package config
func Load(path string) Config {
data, err := os.ReadFile(path)
if err != nil {
panic(err)
}
return parse(data)
}Deterministic line match: flags `panic(` in non-test `.go` files whose package is not `main`.
A `panic()` call in a non-main Go package. It unwinds the caller's goroutine instead of returning an error the caller could handle.
Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.
package config
func Load(path string) Config {
data, err := os.ReadFile(path)
if err != nil {
panic(err)
}
return parse(data)
}Deterministic line match: flags `panic(` in non-test `.go` files whose package is not `main`.
package config
func Load(path string) (Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return Config{}, fmt.Errorf("read config %s: %w", path, err)
}
return parse(data), nil
}Return an error (`fmt.Errorf("...: %w", err)`) and let the caller decide. Reserve `panic` for genuinely impossible states, and mark those with a comment.
Agents treat `panic` like `throw` from other languages and use it for ordinary failures. In Go, library failures are values the caller decides about.
ai-slop/go-library-panic
ai-slop
Deterministic line match: flags `panic(` in non-test `.go` files whose package is not `main`.
`package main`, `_test.go` files, packages whose name ends in `test`, test-support paths such as `testdata/` and `testutil/`, panics with a comment in the three lines above, and short string panics directly under an `if x == nil` guard are not flagged.
Shipped in aislop v0.8.0 among the Go detectors; the same release exempted nil-check preconditions after validation against open-source projects.