Skip to content

structerr: Convert `New()` to return `Unknown` error codes

Patrick Steinhardt requested to merge pks-structerr-unknown-by-default into master

The structerr.New() constructor returns errors with an Internal code. This makes for a somewhat weird interface though: New() shall be used in cases where the actual error condition is not quite clear, but by already setting an Internal error code we'll ultimately propagate that code even if an ancestor in the callchain would know better.

Adjust the function to instead return Unknown errors. Together with the change to always override Unknown errors with more specific ones, this makes for a new calling convention of how to construct errors: always use New(), unless you know the actual root cause. Like this, the first caller that knows more about the root cause will override the Unknown error.

Document this calling convention.

Merge request reports