Skip to content
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 handling NaN #46

Merged
merged 1 commit into from
Dec 2, 2024
Merged

fix handling NaN #46

merged 1 commit into from
Dec 2, 2024

Conversation

shogo82148
Copy link
Owner

@shogo82148 shogo82148 commented Dec 2, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced error handling for decimal values, including checks for NaN and infinite inputs.
    • Updated range validations for decimal values to ensure they fall within specified bounds.
  • Bug Fixes

    • Added a test case to ensure NaN values are correctly flagged as invalid during encoding.

Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Walkthrough

The changes in this pull request involve modifications to the encodeDecimal method within the encode.go file to improve error handling for decimal values. The method now checks for NaN (Not a Number) and infinite values, returning an error if such inputs are encountered. Additionally, range checks have been updated to include MaxDecimal and MinDecimal. Corresponding updates in the encode_test.go file introduce a new test case to validate the handling of NaN values, ensuring that the encoding logic appropriately flags these as invalid inputs.

Changes

File Change Summary
encode.go Modified encodeDecimal method to add checks for NaN and infinite values; updated range checks for MaxDecimal and MinDecimal.
encode_test.go Added a test case in TestEncode_invalidTypes to check for error handling of NaN values in EncodeItem function.

Poem

In the land of code where decimals play,
A rabbit hops in, brightening the day.
With checks for NaN, oh what a delight!
Errors caught swiftly, all wrongs made right.
Hopping through tests, we dance with glee,
Encoding with care, as happy as can be! 🐇✨


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
encode_test.go (1)

445-451: Consider enhancing the NaN test case.

While the test correctly verifies that NaN values are rejected, it could be more specific in checking the error message.

Consider updating the test to verify the specific error message:

 	_, err = EncodeItem(Item{
 		Value: math.NaN(),
 	})
-	if err == nil {
-		t.Error("want error, not not")
+	if err == nil || !strings.Contains(err.Error(), "not a finite number") {
+		t.Errorf("want 'not a finite number' error, got %v", err)
 	}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e4ef2fd and 89a9297.

📒 Files selected for processing (2)
  • encode.go (1 hunks)
  • encode_test.go (1 hunks)
🔇 Additional comments (1)
encode.go (1)

66-69: LGTM! Comprehensive validation for decimal values.

The changes properly handle all edge cases for decimal values:

  1. NaN check using math.IsNaN
  2. Infinite value check using math.IsInf
  3. Range validation against MaxDecimal/MinDecimal

@shogo82148 shogo82148 merged commit bff74a5 into main Dec 2, 2024
51 checks passed
@shogo82148 shogo82148 deleted the fix-handling-nan branch December 2, 2024 14:03
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.

1 participant