Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serrors isn't treating by value or by reference errors consistently #4486

Open
jiceatscion opened this issue Mar 18, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@jiceatscion
Copy link
Contributor

serrors.New returns a pointer. all the wrapper constructors return values.
Is() expects a value. It will fail to recognize a pointer as a basicError. However, if given a value, it will panic for any error that happens to be a wrapper around basicErrors, as it will try to compare these objects which are not comparable.

WithCtx() expects only a value and will fail to downcast a basicError ptr, resulting in always wrapping instead of merging ctx.
A number of test cases have been crafted to expect that un-planned behaviour. For example private/mgmtapi/cppki/api/api_test.go expect a wrapped error while serror() was designed to produce the same error in merged form. (i.e. fixing serrors) will break those tests.

Either we fix serrors and the tests or, may be simpler, we remove that accidentally unused merging mechanism from serrors.

In either case we should decide if we want serrrors to handle values, or references, or both and implement whatever we chose consistently. I suspect we really want references since that's what we always use (otherwise Is() would be panicking).

@jiceatscion jiceatscion added the bug Something isn't working label Mar 18, 2024
@oncilla
Copy link
Contributor

oncilla commented Mar 18, 2024

However, if given a value, it will panic for any error that happens to be a wrapper around basicErrors, as it will try to compare these objects which are not comparable.

Do you have a minimal reproducer? I think that would be easier to understand.

WithCtx() expects only a value and will fail to downcast a basicError ptr, resulting in always wrapping instead of merging ctx.
A number of test cases have been crafted to expect that un-planned behaviour. For example private/mgmtapi/cppki/api/api_test.go expect a wrapped error while serror() was designed to produce the same error in merged form. (i.e. fixing serrors) will break those tests.

IMO, WithCtx is anyway not all that useful. It could be dropped and replaced with regular error wrapping.

For example private/mgmtapi/cppki/api/api_test.go expect a wrapped error while serror() was designed to produce the same error in merged form. (i.e. fixing serrors) will break those tests.

Link to the offending line would be useful here.

@jiceatscion
Copy link
Contributor Author

jiceatscion commented Mar 18, 2024

One simple way to see what's happening: modify serrors.New() to return a value. Then run make test.

One other sample of what's broken. This code (from pkg/slayers/path/scion/raw_test.go)

expected := serrors.New("NumHops too large", "NumHops", 65, "Maximum", scion.MaxHops)
err := s.DecodeFromBytes(b)
assert.Equal(t, expected.Error(), err.Error())

Does what's expected, but replacing the last line with:
assert.ErrorIs(t, expected, err)

Doesn't. The errors are deemed different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants