Skip to content

Conversation

@mensfeld
Copy link
Member

No description provided.

Copy link
Contributor

Copilot AI left a 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 PR refactors magic numbers throughout the codebase by replacing them with named constants from the rdkafka library for improved readability and maintainability. The constants include RD_KAFKA_PARTITION_UA (-1 for unassigned partitions), RD_KAFKA_RESP_ERR_NO_ERROR (0 for no error), and related offset constants.

  • Introduced RD_KAFKA_PARTITION_UA and RD_KAFKA_PARTITION_UA_STR constants in bindings.rb
  • Replaced hardcoded -1 values with RD_KAFKA_PARTITION_UA for partition-related operations
  • Replaced hardcoded 0 values with RD_KAFKA_RESP_ERR_NO_ERROR for error code comparisons

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/rdkafka/bindings.rb Added RD_KAFKA_PARTITION_UA constants and updated stats callback to use named constants
lib/rdkafka/producer.rb Replaced magic numbers with constants in partition_count, produce method, and handle initialization; contains bugs with timestamp and response initialization
lib/rdkafka/consumer.rb Updated all error code comparisons and partition references to use named constants; contains bug with timeout parameter
lib/rdkafka/consumer/topic_partition_list.rb Updated partition and error code usage with named constants
lib/rdkafka/consumer/partition.rb Updated default error parameter to use RD_KAFKA_RESP_ERR_NO_ERROR
lib/rdkafka/callbacks.rb Replaced all hardcoded 0 comparisons with RD_KAFKA_RESP_ERR_NO_ERROR constant
lib/rdkafka/admin.rb Updated handle response initialization to use RD_KAFKA_PARTITION_UA
CHANGELOG.md Added entry documenting the refactoring enhancement

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mensfeld mensfeld merged commit adcc8e3 into master Nov 11, 2025
82 checks passed
@mensfeld mensfeld deleted the refactor-magic-numbers branch November 11, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants