You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please fill in the fields below to submit an issue or feature request. The
more information that is provided, the better.
Description of issue or feature request:
With Go 13, Go got better error handling with functions like errors.Is() or errors.As(). We might want to adapt our code, so developers can use this functions with our library.
Current behavior:
Right now we are excessively using fmt.Errorf("..") for error messages. Instead we should declare global Error types like in the Symlink implementation and return error types:
// ErrSymCycle signals a detected symlink cycle in our RecordArtifacts() function.
var ErrSymCycle = errors.New("symlink cycle detected")
This way we have error documentation and can use errors.Is(err, ErrSymCycle) for error checking. This is a huge benefit over string checking with if err.Error() == "..." { .. }, because with the latter we can run into a nil pointer dereference if Error() returns nil.
Expected behavior:
Use documented error types like:
// ErrSymCycle signals a detected symlink cycle in our RecordArtifacts() function.
var ErrSymCycle = errors.New("symlink cycle detected")
@SantiagoTorres Yes, I just pushed 3 new error types in my latest in-toto-run commit. The error handling gets so much better with this.
We get basically from something like this:
expectedError:="Could not find a public key PEM block"err=key.LoadRSAPublicKey("demo.layout.template")
iferr==nil||!strings.Contains(err.Error(), expectedError) {
t.Errorf("LoadRSAPublicKey returned (%s), expected '%s' error", err,
expectedError)
}
Please fill in the fields below to submit an issue or feature request. The
more information that is provided, the better.
Description of issue or feature request:
With Go 13, Go got better error handling with functions like
errors.Is()
orerrors.As()
. We might want to adapt our code, so developers can use this functions with our library.Current behavior:
Right now we are excessively using
fmt.Errorf("..")
for error messages. Instead we should declare global Error types like in the Symlink implementation and return error types:This way we have error documentation and can use
errors.Is(err, ErrSymCycle)
for error checking. This is a huge benefit over string checking withif err.Error() == "..." { .. }
, because with the latter we can run into a nil pointer dereference if Error() returns nil.Expected behavior:
Use documented error types like:
More about new Go 1.13 error handling can be found here: https://blog.golang.org/go1.13-errors
Feedback @SantiagoTorres @lukpueh ?
The text was updated successfully, but these errors were encountered: