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

TT-13533 int64 #3

Merged
merged 1 commit into from
Jan 17, 2025
Merged

TT-13533 int64 #3

merged 1 commit into from
Jan 17, 2025

Conversation

tbuchaillot
Copy link
Collaborator

@tbuchaillot tbuchaillot commented Jan 17, 2025

PR Type

Bug fix, Enhancement


Description

  • Fix parsing of large integer values from string

  • Add support for parsing floating point numbers and converting to int64

  • Improve error handling and panic with informative message on parsing failure


Changes walkthrough 📝

Relevant files
Enhancement
meta.go
Add float parsing and improve error handling in ToInt       

utils/meta.go

  • Add support for parsing floating point numbers in ToInt function
  • Convert parsed float to int64 before returning
  • Improve error handling to panic with informative message on parsing
    failure
  • +2/-0     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Potential precision loss

    Converting from float64 to int64 may lead to loss of precision for large floating point numbers. This should be validated to ensure it matches the expected behavior and doesn't introduce bugs for certain input values.

    } else if f, err := strconv.ParseFloat(result, 64); err == nil {
    	return int64(f)

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Handle the error returned by strconv.ParseFloat in the ToInt function

    The ToInt function should handle the error returned by strconv.ParseFloat instead of
    ignoring it. If the float parsing fails, the function will incorrectly panic with a
    message about failing to parse an int, even though the failure was in parsing a
    float.

    utils/meta.go [76-77]

     } else if f, err := strconv.ParseFloat(result, 64); err == nil {
         return int64(f)
    +} else {
    +    panic("failed to parse float: " + result)
    Suggestion importance[1-10]: 8

    Why: The suggestion correctly identifies a bug where the error from parsing a float is ignored, leading to a misleading panic message. Fixing this is important for proper error handling and debugging.

    8
    General
    Add a comment explaining the fallback to parsing as a float

    Consider adding a comment to explain why parsing as a float is attempted if parsing
    as an int fails. This fallback behavior may not be obvious to future maintainers.

    utils/meta.go [74-77]

     } else if i, err := strconv.ParseInt(result, 10, 64); err == nil {
         return i
     } else if f, err := strconv.ParseFloat(result, 64); err == nil {
    -    return int64(f)
    +    // Fallback to parsing as float if parsing as int fails
    +    return int64(f) 
     } else {
         panic("failed to parse int: " + result)
    Suggestion importance[1-10]: 3

    Why: While adding a clarifying comment has some value for maintainability, it's a minor documentation improvement compared to the error handling fix in the first suggestion.

    3

    @tbuchaillot tbuchaillot changed the title Update meta.go TT-13533 int64 Jan 17, 2025
    @edsonmichaque edsonmichaque self-requested a review January 17, 2025 19:17
    Copy link
    Collaborator

    @edsonmichaque edsonmichaque left a comment

    Choose a reason for hiding this comment

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

    LGTM

    @edsonmichaque edsonmichaque merged commit 5dbd8d9 into master Jan 17, 2025
    3 checks passed
    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