-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[improve][fn] Introduce NewOutputMessageWithError to enable error handling #24122
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
[improve][fn] Introduce NewOutputMessageWithError to enable error handling #24122
Conversation
nodece
left a comment
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.
This PR breaks the public API.
Could you consider that add the NewOutputMessageWithError to the FunctionContext?
6a09b3e to
8111741
Compare
|
Hi @nodece |
Co-authored-by: Zixuan Liu <[email protected]>
593df9e to
8461215
Compare
nodece
left a comment
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.
Please check.
Co-authored-by: Zixuan Liu <[email protected]>
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.
Pull Request Overview
This pull request introduces a new error-handling function, NewOutputMessageWithError, to allow graceful error handling when sending output messages in the Go Pulsar function implementation.
- Add a new function in both instance.go and context.go to return an error instead of panicking.
- Update tests in context_test.go to cover the new function.
- Minor refactoring in util_test.go to improve variable naming.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pulsar-function-go/pf/util_test.go | Corrected a typo in variable naming from actualtMap to actualMap. |
| pulsar-function-go/pf/instance.go | Introduced a new outputMessageWithError function to support error handling. |
| pulsar-function-go/pf/context_test.go | Added test cases for the new NewOutputMessageWithError functionality. |
| pulsar-function-go/pf/context.go | Added a new field and method for NewOutputMessageWithError. |
Comments suppressed due to low confidence (2)
pulsar-function-go/pf/instance.go:83
- [nitpick] Consider adding a space after 'error is:' in the error message for improved readability, for example: "getting producer failed, error is: %v".
log.Errorf("getting producer failed, error is:%v", err)
pulsar-function-go/pf/context_test.go:126
- Comparing errors by value can lead to false negatives since two errors with the same message may not be equal if they are distinct instances. Consider using assert.EqualError(t, err, "test error") or comparing error messages.
assert.Equal(t, testCase.expectedError, err)
lhotari
left a comment
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.
LGTM, good work @beelis
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #24122 +/- ##
============================================
+ Coverage 73.57% 74.24% +0.66%
+ Complexity 32624 32484 -140
============================================
Files 1877 1864 -13
Lines 139502 144453 +4951
Branches 15299 16479 +1180
============================================
+ Hits 102638 107244 +4606
+ Misses 28908 28747 -161
- Partials 7956 8462 +506
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
…dling (#24122) Co-authored-by: Simon Beeli <[email protected]> Co-authored-by: Zixuan Liu <[email protected]> (cherry picked from commit d8e2743)
…dling (apache#24122) Co-authored-by: Simon Beeli <[email protected]> Co-authored-by: Zixuan Liu <[email protected]> (cherry picked from commit d8e2743) (cherry picked from commit d828bc6)
…dling (apache#24122) Co-authored-by: Simon Beeli <[email protected]> Co-authored-by: Zixuan Liu <[email protected]> (cherry picked from commit d8e2743) (cherry picked from commit d828bc6)
…dling (apache#24122) Co-authored-by: Simon Beeli <[email protected]> Co-authored-by: Zixuan Liu <[email protected]> (cherry picked from commit d8e2743) (cherry picked from commit d828bc6)
…dling (apache#24122) Co-authored-by: Simon Beeli <[email protected]> Co-authored-by: Zixuan Liu <[email protected]> (cherry picked from commit d8e2743) (cherry picked from commit d828bc6)
…dling (apache#24122) Co-authored-by: Simon Beeli <[email protected]> Co-authored-by: Zixuan Liu <[email protected]>
Fixes #24121
Motivation
When an error occurs during the sending of a message using
NewOutputMessage, the go function exits with a panic. This behavior prevents the application from handling the error gracefully, as it bypasses any error-handling logic.Errors should be returned by the new introduced func
NewOutputMessageWithErrorso they can be handled by the calling code, rather than causing a panic.Modifications
Return the error on
NewOutputMessageWithErrorVerifying this change
This change is a trivial rework / code cleanup without any test coverage.
Does this pull request potentially affect one of the following parts:
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: https://github.com/beelis/pulsar/tree/enhancements/24121/Return-error-on-NewOutputMessage