Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stylecheck: advise against non-conforming Unwrap, Is, and As methods on error types #799

Open
ainar-g opened this issue Jul 24, 2020 · 0 comments
Labels
needs-decision We have to decide if this check is feasible and desirable new-check

Comments

@ainar-g
Copy link
Contributor

ainar-g commented Jul 24, 2020

(Inspired by golang/go#40356, so probably won't be as necessary if that proposal is accepted.)

What I did:

Filtered shell output
$ staticcheck --debug.version
staticcheck (devel, v0.0.1-2020.1.0.20200615045319-925e3c1d1b98)

Compiled with Go version: go1.14.6
Main module:
	honnef.co/go/[email protected] (sum: h1:8DVSlQMnJDu5uoPrBMZQcr2cz1aK/HdVSSIvhPzYx0c=)
Dependencies:
	github.com/BurntSushi/[email protected] (sum: h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=)
	golang.org/x/[email protected] (sum: h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=)
	golang.org/x/[email protected] (sum: h1:59syOWj4+Fl+op4LL8fX1kO7HmbdEWfxlw4tcGvH+y0=)
	golang.org/x/[email protected] (sum: h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=)
$ nl -b a ./go/tmp.go 
     1	// +build ignore
     2	
     3	package main
     4	
     5	type myError struct{}
     6	
     7	func (myError) Error() (msg string)  { return "" }
     8	func (myError) Unwrap() (msg string) { return "" }
     9	
    10	func main() {
    11		var err error = myError{}
    12		_ = err
    13	}
$ staticcheck --checks=all -f stylish ./go/tmp.go
 ✖ 0 problems (0 errors, 0 warnings, 0 ignored)

What I expected: A warning about my error implementing the Unwrap interface incorrectly.

(This is stylecheck and not staticcheck, because this Unwrap could simply implement another interface for another library.)

@ainar-g ainar-g added the needs-triage Newly filed issue that needs triage label Jul 24, 2020
@dominikh dominikh added needs-decision We have to decide if this check is feasible and desirable new-check and removed needs-triage Newly filed issue that needs triage labels Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision We have to decide if this check is feasible and desirable new-check
Projects
None yet
Development

No branches or pull requests

2 participants