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: correctly display error message when metadata migration fails #551

Merged
merged 3 commits into from
Aug 29, 2024

Conversation

Tchoupinax
Copy link
Contributor

@Tchoupinax Tchoupinax commented Aug 26, 2024

User description

Before submitting this PR:

Checklist

  • No breaking changes
  • Tests pass
  • New features have new tests
  • Documentation is updated

PR Type

Bug fix


Description

  • Fixed the error message display when metadata migration fails by using template literals for improved readability.
  • Ensured that the error message includes the specific error details.

Changes walkthrough 📝

Relevant files
Bug fix
metadata.ts
Correct error message formatting in metadata migration     

src/metadata.ts

  • Corrected the format of the error message when metadata migration
    fails.
  • Replaced concatenation with template literals for better readability.
  • +1/-1     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    qodo-merge-pro bot commented Aug 26, 2024

    PR Reviewer Guide 🔍

    (Review updated until commit 6e76f97)

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ No key issues to review

    Copy link

    qodo-merge-pro bot commented Aug 26, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Best practice
    ✅ Use template literals for string interpolation in error logging

    Use template literals for string interpolation instead of string concatenation. This
    will correctly display the error message when metadata migration fails.

    src/metadata.ts [448]

    -logger.warn('Impossible to apply metadata: ${message}');
    +logger.warn(`Impossible to apply metadata: ${message}`);
     

    [Suggestion has been applied]

    Suggestion importance[1-10]: 9

    Why: The suggestion correctly identifies the misuse of string concatenation and recommends using template literals, which is a best practice for string interpolation in TypeScript.

    9
    Enhancement
    Use a more specific error type instead of 'any'

    Consider adding a more specific error type instead of using 'any' to improve type
    safety and code maintainability.

    src/metadata.ts [445-446]

    -// eslint-disable-next-line @typescript-eslint/no-explicit-any
    -const error = e as any;
    +const error = e as Error & { response?: { data: string } };
     
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion improves type safety and maintainability by recommending a more specific error type, which is beneficial for understanding and handling errors more effectively.

    8
    Error handling
    Rethrow the error after logging for proper error propagation

    Consider rethrowing the error after logging it, to allow proper error handling at a
    higher level.

    src/metadata.ts [444-449]

     } catch (e) {
       // eslint-disable-next-line @typescript-eslint/no-explicit-any
       const error = e as any;
       const message = error.response?.data || error.message;
    -  logger.warn('Impossible to apply metadata: ${message}');
    +  logger.warn(`Impossible to apply metadata: ${message}`);
    +  throw error;
     }
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion to rethrow the error after logging is valid as it allows for better error handling at higher levels, though it may not be crucial depending on the application's error handling strategy.

    7

    @Tchoupinax
    Copy link
    Contributor Author

    Hello,
    Following the issue raised here, I edited how to low the error message. It's the only way that shows a result

    @dbarrosop dbarrosop force-pushed the main branch 3 times, most recently from cbf212b to 36837b1 Compare August 29, 2024 07:36
    @onehassan onehassan self-requested a review August 29, 2024 11:24
    src/metadata.ts Outdated Show resolved Hide resolved
    Copy link
    Contributor

    @onehassan onehassan left a comment

    Choose a reason for hiding this comment

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

    Can you please review the suggestion

    @dbarrosop
    Copy link
    Member

    Thanks!

    @dbarrosop dbarrosop merged commit 1e6c29f into nhost:main Aug 29, 2024
    6 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants