-
Notifications
You must be signed in to change notification settings - Fork 16
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
fix: Don't fatal error when we can return an error #36
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I agree with returning errors instead of crashing the process 😬
@@ -625,8 +625,7 @@ func ConfigureOpenTelemetry(opts ...Option) (func(), error) { | |||
for _, setup := range []setupFunc{setupTracing, setupMetrics} { | |||
shutdown, err := setup(c) | |||
if err != nil { | |||
c.Logger.Fatalf("setup error: %v", err) | |||
continue | |||
return otelConfig.Shutdown, fmt.Errorf("setup error: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be worth capturing all the errors from the for loop, combing them and returning a single error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see it as worthwhile, since upstream would have to be told to expect some form of multierror. I saw this loop as simple convenience and considered even unrolling it. But I can do that if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think returning early is fine. Thanks for putting together 👍🏻
@MikeGoldsmith for releasing purposes, is this a patch/bugfix you think? |
Which problem is this PR solving?
Calling this code:
Crashes with a fatal error, even though the function returns an error.
It would be nice to be able to catch this error and handle it in my app appropriately.
Short description of the changes
Return a wrapped error instead of crashing. Note that this also affects other setup-type errors that are currently fatally crashing, and required reworking some tests.
How to verify that this has the expected result
Run the tests, or the code above;
err
should come back as non-nil and it shouldn't crash.