Skip to content

fix: add Unwrap() to DescribeConfigError and AlterConfigError#3487

Open
ShinThirty wants to merge 1 commit intoIBM:mainfrom
ShinThirty:add-unwrap-config-errors
Open

fix: add Unwrap() to DescribeConfigError and AlterConfigError#3487
ShinThirty wants to merge 1 commit intoIBM:mainfrom
ShinThirty:add-unwrap-config-errors

Conversation

@ShinThirty
Copy link
Copy Markdown

Summary

TopicError and TopicPartitionError implement Unwrap() returning their KError field, enabling errors.Is/errors.As to traverse the error chain. However, DescribeConfigError and AlterConfigError have the same structure (Err KError + ErrMsg) but were missing Unwrap(), making errors.Is/errors.As unable to match the underlying KError.

This adds the missing Unwrap() methods for consistency, allowing callers to use errors.Is(err, sarama.ErrInvalidConfig) instead of type-asserting to extract the error code.

Changes

  • Add Unwrap() error to *DescribeConfigError (describe_configs_response.go)
  • Add Unwrap() error to *AlterConfigError (alter_configs_response.go)
  • Add tests for both, following the existing TestTopicError pattern

Test plan

  • go test -run 'TestDescribeConfigError|TestAlterConfigError|TestTopicError' — all pass
  • go vet ./... — clean

@ShinThirty ShinThirty force-pushed the add-unwrap-config-errors branch from fec5deb to ae6ae04 Compare March 31, 2026 20:30
TopicError and TopicPartitionError implement Unwrap() returning their
KError field, enabling errors.Is/As to traverse the error chain. However,
DescribeConfigError and AlterConfigError have the same structure (Err KError
+ ErrMsg) but were missing Unwrap(), making errors.Is/As unable to match
the underlying KError.

This adds the missing Unwrap() methods for consistency, allowing callers
to use errors.Is(err, sarama.ErrInvalidConfig) instead of type-asserting
to extract the error code.

Signed-off-by: Lingnan Liu <xmxu00@gmail.com>
@ShinThirty ShinThirty changed the title Add Unwrap() to DescribeConfigError and AlterConfigError fix: add Unwrap() to DescribeConfigError and AlterConfigError Mar 31, 2026
@ShinThirty ShinThirty force-pushed the add-unwrap-config-errors branch from ae6ae04 to 5511bbc Compare March 31, 2026 20:33
Copy link
Copy Markdown
Collaborator

@puellanivis puellanivis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♀️ I see nothing wrong with the code. The only concern here is if this is desired behavior.

@ShinThirty
Copy link
Copy Markdown
Author

I don't think we documented the expected behavior of the errors? Also this is a pure addition so it is backward compatible.

@puellanivis
Copy link
Copy Markdown
Collaborator

Correct. My point is more: as a collaborator who does code reviews, nothing is wrong with the code.

My point is that it’s on the maintainers to decide if they’re good with the behavior change, which I agree is an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants