Solution Architect (ex Lead Go Developer) at Exness 💹
Look my way at Linkedin 👨💻
Author and teacher of «GOLANG NINJA» online courses:
The Golang linter that checks that there is no simultaneous return of `nil` error and an invalid value.
License: MIT License
Solution Architect (ex Lead Go Developer) at Exness 💹
Look my way at Linkedin 👨💻
Author and teacher of «GOLANG NINJA» online courses:
return entity, errors.New("something went wrong")
// should be
return nil, errors.New("something went wrong")
To reproduce, add this to the examples:
import "examples/other"
func iface2() (other.Iface, error) {
return nil, nil // want "return both the `nil` error and invalid value: use a sentinel error instead"
}
And add this to a new package under "examples":
package other
type Iface interface {
Do()
}
Reading the code of the linter, the package of the type is not considered in the analysis and *ast.SelectorExpr
is not traversed in isDangerNilType
, so only types form the same package are analyzed.
One way to "fix" this might be to create a config that bypasses this type based analysis entirely by saying "all types should be checked". That still wouldn't work if a custom config is given and typed based analysis is still desired, but I think it would work for most users.
It's possible for you to downgrade the version inside your go.mod to go1.20?
the new way to handle the module and go version is strict.
https://github.com/golangci/golangci-lint/actions/runs/5893637045/job/15985603630?pr=4023
go version: go version go1.22.1 darwin/arm64
nilnil version: v0.1.7
command: nilnil ./...
error message:
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1004baac4]
goroutine 3 [running]:
go/types.(*Checker).handleBailout(0x14000356400, 0x1400158bb98)
/opt/homebrew/opt/go/libexec/src/go/types/check.go:367 +0x9c
panic({0x100693d80?, 0x100897ca0?})
/opt/homebrew/opt/go/libexec/src/runtime/panic.go:770 +0x124
go/types.(*StdSizes).Sizeof(0x0, {0x1006ea5e8, 0x10089b8a0})
/opt/homebrew/opt/go/libexec/src/go/types/sizes.go:228 +0x314
go/types.(*Config).sizeof(...)
/opt/homebrew/opt/go/libexec/src/go/types/sizes.go:333
go/types.representableConst.func1({0x1006ea5e8?, 0x10089b8a0?})
/opt/homebrew/opt/go/libexec/src/go/types/const.go:76 +0x9c
go/types.representableConst({0x1006eb928, 0x1008906f0}, 0x14000356400, 0x10089b8a0, 0x1400158b2e8)
/opt/homebrew/opt/go/libexec/src/go/types/const.go:92 +0x138
go/types.(*Checker).representation(0x14000356400, 0x140015a7c00, 0x10089b8a0)
/opt/homebrew/opt/go/libexec/src/go/types/const.go:256 +0x68
go/types.(*Checker).implicitTypeAndValue(0x14000356400, 0x140015a7c00, {0x1006ea5e8, 0x10089b8a0})
/opt/homebrew/opt/go/libexec/src/go/types/expr.go:375 +0x304
go/types.(*Checker).assignment(0x14000356400, 0x140015a7c00, {0x1006ea5e8, 0x10089b8a0}, {0x1005e6e4c, 0x14})
/opt/homebrew/opt/go/libexec/src/go/types/assignments.go:52 +0x23c
go/types.(*Checker).initConst(0x14000356400, 0x14000e6aae0, 0x140015a7c00)
/opt/homebrew/opt/go/libexec/src/go/types/assignments.go:126 +0x274
go/types.(*Checker).constDecl(0x14000356400, 0x14000e6aae0, {0x1006eab88, 0x1400051e220}, {0x1006eaeb8, 0x140013260f0}, 0x0)
/opt/homebrew/opt/go/libexec/src/go/types/decl.go:490 +0x250
go/types.(*Checker).objDecl(0x14000356400, {0x1006ee138, 0x14000e6aae0}, 0x0)
/opt/homebrew/opt/go/libexec/src/go/types/decl.go:191 +0x84c
go/types.(*Checker).packageObjects(0x14000356400)
/opt/homebrew/opt/go/libexec/src/go/types/resolver.go:693 +0x468
go/types.(*Checker).checkFiles(0x14000356400, {0x140009f9500, 0xb, 0xb})
/opt/homebrew/opt/go/libexec/src/go/types/check.go:408 +0x164
go/types.(*Checker).Files(...)
/opt/homebrew/opt/go/libexec/src/go/types/check.go:372
golang.org/x/tools/go/packages.(*loader).loadPackage(0x1400010e000, 0x140002278f0)
/Users/jinwu.li/go/pkg/mod/golang.org/x/[email protected]/go/packages/packages.go:1058 +0x8cc
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
/Users/jinwu.li/go/pkg/mod/golang.org/x/[email protected]/go/packages/packages.go:854 +0x178
sync.(*Once).doSlow(0x0?, 0x0?)
/opt/homebrew/opt/go/libexec/src/sync/once.go:74 +0x100
sync.(*Once).Do(...)
/opt/homebrew/opt/go/libexec/src/sync/once.go:65
golang.org/x/tools/go/packages.(*loader).loadRecursive(0x0?, 0x0?)
/Users/jinwu.li/go/pkg/mod/golang.org/x/[email protected]/go/packages/packages.go:842 +0x50
golang.org/x/tools/go/packages.(*loader).refine.func2(0x0?)
/Users/jinwu.li/go/pkg/mod/golang.org/x/[email protected]/go/packages/packages.go:777 +0x30
created by golang.org/x/tools/go/packages.(*loader).refine in goroutine 1
/Users/jinwu.li/go/pkg/mod/golang.org/x/[email protected]/go/packages/packages.go:776 +0xaa4
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.