Skip to content

statushandler: Retain explicitly set `Unknown` error codes

The statushandler package is responsible for wrapping errors returned by the gRPC handler. For one this is required to return proper error codes when the context has been canceled or hit a deadline. On the other hand it will wrap errors that don't have an error code to have an Internal error code.

There is one edge case here that needs to be explained. When we don't have an error that is ultimately caused by context cancellation, then we previously returned helper.ErrInternal(err). The intent of this is to add an Internal error code in case the error didn't yet have any error code set so that we don't see an Unknown error by default. There is a slight gotcha though, because we now return Internal even if the wrapped error explicitly had Unknown set as an error code. This is arguably the wrong thing to do as we shouldn't override any error code that the RPC handler has explicitly set up.

The structerr package doesn't do this anymore, so it will really only override the gRPC error code in case it wasn't set at all. And this really is the right thing to do.

Merge request reports