humaneerror
About 207 wordsLess than 1 minute
2025-01-16
Enforces the use of humane-errors-go for user-facing errors.
Category
Error Handling
What It Checks
This analyzer ensures error messages provide actionable information for users, not just technical details.
Why It Matters
Technical error messages frustrate users:
Error: connection refusedHumane errors help users:
Error: Unable to connect to the database
Hint: Check that the database server is running and accessible
Details: connection refused to localhost:5432Examples
Bad
func GetUser(id string) (*User, error) {
user, err := db.Find(id)
if err != nil {
return nil, err // Raw technical error
}
return user, nil
}Good
import "github.com/sierrasoftworks/humane-errors-go"
func GetUser(id string) (*User, error) {
user, err := db.Find(id)
if err != nil {
return nil, humane.New("Unable to find the user").
WithHint("Check that the user ID is correct").
WithDetails(err.Error())
}
return user, nil
}Configuration
# .golint-sl.yaml
analyzers:
humaneerror: true # enabled by defaultWhen to Disable
- Internal services where users are developers
- CLI tools with technical audiences
- Libraries (let consumers decide error presentation)
analyzers:
humaneerror: falseRelated Analyzers
- errorwrap - Error context wrapping
- sentinelerrors - Sentinel error patterns
