Skip to content

feat: add package name prefix to sentinel error strings #2228

Description

@pageton

Summary

Go convention recommends that sentinel error variables include the package name as a prefix so that errors can be identified by origin when they propagate across package boundaries (e.g., "fasthttp: not found").

None of the ~38 exported sentinel errors in the codebase include a package name prefix.

Examples

Variable Current String Suggested
ErrAlreadyServing "Server is already serving connections" "fasthttp: server is already serving connections"
ErrDialTimeout "dialing to the given TCP address timed out" "fasthttp: dialing to the given tcp address timed out"
ErrBodyTooLarge "body size exceeds the given limit" "fasthttp: body size exceeds the given limit"
ErrNoFreeConns "no free connections available to host" "fasthttp: no free connections available to host"
ErrConnectionClosed "the server closed connection..." "fasthttp: the server closed connection..."
ErrMissingLocation "missing Location header..." "fasthttp: missing location header..."
ErrTimeout "timeout" "fasthttp: timeout"

Sub-packages should also use their own prefixes:

  • fasthttputil: "fasthttputil: connection closed" instead of "connection closed"
  • prefork: "prefork: exceeding the value..." instead of "exceeding the value..."

Scope

~35 sentinel errors in fasthttp (root) + 3 in fasthttputil + 2 in prefork + ErrNoArgValue in args.go + ErrorInvalidURI in uri.go.

Note

This is a breaking change for any downstream code comparing error messages with == or strings.Contains. Should be noted in the changelog and ideally done in a major version bump.

Reference

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions