You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "beelis (via GitHub)" <gi...@apache.org> on 2025/03/25 12:04:35 UTC

[PR] [Enhancement][functions go] Return error on NewOutputMessage to enable error handling [pulsar]

beelis opened a new pull request, #24122:
URL: https://github.com/apache/pulsar/pull/24122

   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 `NewOutputMessage` so they can be handled by the calling code, rather than causing a panic.
   
   ### Modifications
   
   Return the error on `NewOutputMessage`
   
   ### Verifying this change
   
   - [x] Make sure that the change passes the CI checks.
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   ### Does this pull request potentially affect one of the following parts:
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] The metrics
   - [ ] Anything that affects deployment
   
   ### Documentation
   
   - [ ] `doc` <!-- Your PR contains doc changes. -->
   - [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
   - [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   - [ ] `doc-complete` <!-- Docs have been already added -->
   
   ### Matching PR in forked repository
   
   PR in forked repository: https://github.com/beelis/pulsar/tree/enhancements/24121/Return-error-on-NewOutputMessage
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improvement][functions go] Introduce NewOutputMessageWithError to enable error handling [pulsar]

Posted by "beelis (via GitHub)" <gi...@apache.org>.
beelis commented on PR #24122:
URL: https://github.com/apache/pulsar/pull/24122#issuecomment-2753880738

   Hi @nodece 
   Thank you for your review and feedback, i introduced the new func NewOutputMessageWithError.
   Cheers, Simon


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improvement][functions go] Introduce NewOutputMessageWithError to enable error handling [pulsar]

Posted by "nodece (via GitHub)" <gi...@apache.org>.
nodece commented on code in PR #24122:
URL: https://github.com/apache/pulsar/pull/24122#discussion_r2018149045


##########
pulsar-function-go/pf/context_test.go:
##########
@@ -82,3 +84,43 @@ func TestFunctionContext_NewOutputMessage(t *testing.T) {
 	actualProducer := fc.NewOutputMessage(publishTopic)
 	assert.IsType(t, &MockPulsarProducer{}, actualProducer)
 }
+
+func TestFunctionContext_NewOutputMessageWithError(t *testing.T) {
+	testCases := []struct {
+		name                 string
+		outputFunc           func(topic string) (pulsar.Producer, error)
+		expectedError        bool
+		expectedProducerType *MockPulsarProducer
+	}{
+		{
+			name:                 "Test producer",
+			outputFunc:           func(topic string) (pulsar.Producer, error) { return &MockPulsarProducer{}, nil },
+			expectedError:        false,
+			expectedProducerType: &MockPulsarProducer{},
+		},
+		{
+			name:                 "Test error",
+			outputFunc:           func(topic string) (pulsar.Producer, error) { return nil, errors.New("test error") },
+			expectedError:        true,
+			expectedProducerType: nil,
+		},
+	}
+
+	for i, testCase := range testCases {
+		t.Run(fmt.Sprintf("testCase[%d] %s", i, testCase.name), func(t *testing.T) {
+
+			fc := NewFuncContext()
+			publishTopic := "publish-topic"
+
+			fc.outputMessageWithError = testCase.outputFunc
+
+			actualProducer, err := fc.NewOutputMessageWithError(publishTopic)
+			if testCase.expectedProducerType == nil {
+				assert.Nil(t, actualProducer)
+			} else {
+				assert.IsType(t, testCase.expectedProducerType, actualProducer)
+			}
+			assert.Equal(t, testCase.expectedError, err != nil)

Review Comment:
   ```suggestion
   			assert.Equal(t, testCase.expectedError, err)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improvement][functions go] Introduce NewOutputMessageWithError to enable error handling [pulsar]

Posted by "nodece (via GitHub)" <gi...@apache.org>.
nodece commented on code in PR #24122:
URL: https://github.com/apache/pulsar/pull/24122#discussion_r2015862180


##########
pulsar-function-go/pf/context_test.go:
##########
@@ -82,3 +84,42 @@ func TestFunctionContext_NewOutputMessage(t *testing.T) {
 	actualProducer := fc.NewOutputMessage(publishTopic)
 	assert.IsType(t, &MockPulsarProducer{}, actualProducer)
 }
+
+func TestFunctionContext_NewOutputMessageWithError(t *testing.T) {
+
+	testCases := []struct {
+		name                 string
+		outputFunc           func(topic string) (pulsar.Producer, error)
+		expectedError        bool
+		expectedProducerType *MockPulsarProducer
+	}{
+		{
+			name:                 "Test producer",
+			outputFunc:           func(topic string) (pulsar.Producer, error) { return &MockPulsarProducer{}, nil },
+			expectedError:        false,
+			expectedProducerType: &MockPulsarProducer{},
+		},
+		{
+			name:                 "Test error",
+			outputFunc:           func(topic string) (pulsar.Producer, error) { return nil, errors.New("test error") },
+			expectedError:        false,
+			expectedProducerType: nil,
+		},
+	}
+
+	for i, testCase := range testCases {
+		t.Run(fmt.Sprintf("testCase[%d] %s", i, testCase.name), func(t *testing.T) {
+
+			fc := NewFuncContext()
+			publishTopic := "publish-topic"
+
+			fc.outputMessageWithError = func(topic string) (pulsar.Producer, error) {
+				return &MockPulsarProducer{}, nil
+			}

Review Comment:
   ```suggestion
   			fc.outputMessageWithError = testCase.outputFunc;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improvement][functions go] Introduce NewOutputMessageWithError to enable error handling [pulsar]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #24122:
URL: https://github.com/apache/pulsar/pull/24122#issuecomment-2760846437

   ## [Codecov](https://app.codecov.io/gh/apache/pulsar/pull/24122?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   All modified and coverable lines are covered by tests :white_check_mark:
   > Project coverage is 74.24%. Comparing base [(`bbc6224`)](https://app.codecov.io/gh/apache/pulsar/commit/bbc62245c5ddba1de4b1e7cee4ab49334bc36277?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`c288ae0`)](https://app.codecov.io/gh/apache/pulsar/commit/c288ae022cfdb06e5fd7ced60e0ac73a995231a6?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 996 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/pulsar/pull/24122/graphs/tree.svg?width=650&height=150&src=pr&token=acYqCpsK9J&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/pulsar/pull/24122?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@             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     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/pulsar/pull/24122/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [inttests](https://app.codecov.io/gh/apache/pulsar/pull/24122/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `26.68% <ø> (+2.10%)` | :arrow_up: |
   | [systests](https://app.codecov.io/gh/apache/pulsar/pull/24122/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `23.19% <ø> (-1.14%)` | :arrow_down: |
   | [unittests](https://app.codecov.io/gh/apache/pulsar/pull/24122/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `73.74% <ø> (+0.89%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   [see 1068 files with indirect coverage changes](https://app.codecov.io/gh/apache/pulsar/pull/24122/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improve][fn] Introduce NewOutputMessageWithError to enable error handling [pulsar]

Posted by "nodece (via GitHub)" <gi...@apache.org>.
nodece merged PR #24122:
URL: https://github.com/apache/pulsar/pull/24122


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improvement][functions go] Introduce NewOutputMessageWithError to enable error handling [pulsar]

Posted by "nodece (via GitHub)" <gi...@apache.org>.
nodece commented on code in PR #24122:
URL: https://github.com/apache/pulsar/pull/24122#discussion_r2018166796


##########
pulsar-function-go/pf/context_test.go:
##########
@@ -82,3 +84,46 @@ func TestFunctionContext_NewOutputMessage(t *testing.T) {
 	actualProducer := fc.NewOutputMessage(publishTopic)
 	assert.IsType(t, &MockPulsarProducer{}, actualProducer)
 }
+
+func TestFunctionContext_NewOutputMessageWithError(t *testing.T) {
+	testErr := errors.New("test error")
+
+	testCases := []struct {
+		name                 string
+		outputFunc           func(topic string) (pulsar.Producer, error)
+		expectedError        error
+		expectedProducerType *MockPulsarProducer
+	}{
+
+		{
+			name:                 "Test producer",
+			outputFunc:           func(topic string) (pulsar.Producer, error) { return &MockPulsarProducer{}, nil },
+			expectedError:        nil,
+			expectedProducerType: &MockPulsarProducer{},
+		},
+		{
+			name:                 "Test error",
+			outputFunc:           func(topic string) (pulsar.Producer, error) { return nil, errors.New("test error") },

Review Comment:
   ```suggestion
   			outputFunc:           func(topic string) (pulsar.Producer, error) { return nil, testErr },
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [improvement][functions go] Introduce NewOutputMessageWithError to enable error handling [pulsar]

Posted by "nodece (via GitHub)" <gi...@apache.org>.
nodece commented on code in PR #24122:
URL: https://github.com/apache/pulsar/pull/24122#discussion_r2018166796


##########
pulsar-function-go/pf/context_test.go:
##########
@@ -82,3 +84,46 @@ func TestFunctionContext_NewOutputMessage(t *testing.T) {
 	actualProducer := fc.NewOutputMessage(publishTopic)
 	assert.IsType(t, &MockPulsarProducer{}, actualProducer)
 }
+
+func TestFunctionContext_NewOutputMessageWithError(t *testing.T) {
+	testErr := errors.New("test error")
+
+	testCases := []struct {
+		name                 string
+		outputFunc           func(topic string) (pulsar.Producer, error)
+		expectedError        error
+		expectedProducerType *MockPulsarProducer
+	}{
+
+		{
+			name:                 "Test producer",
+			outputFunc:           func(topic string) (pulsar.Producer, error) { return &MockPulsarProducer{}, nil },
+			expectedError:        nil,
+			expectedProducerType: &MockPulsarProducer{},
+		},
+		{
+			name:                 "Test error",
+			outputFunc:           func(topic string) (pulsar.Producer, error) { return nil, errors.New("test error") },

Review Comment:
   ```suggestion
   			outputFunc:           func(topic string) (pulsar.Producer, error) { return nil, testErr },
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org