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: handle empty display_name #26

Merged
merged 1 commit into from
Mar 8, 2024
Merged

Conversation

rosnovsky
Copy link
Owner

@rosnovsky rosnovsky commented Mar 8, 2024

Sometimes instances return an empty display_name field. This PR introduces a fallback to username in such cases.

Closes #25

Summary by CodeRabbit

  • New Features
    • Added a new demo post to improve the representation of edge cases in the UI.
  • Bug Fixes
    • Enhanced error handling when fetching Mastodon posts.
    • Updated data conversion logic to handle cases with empty display_name, ensuring a fallback to username.

@rosnovsky rosnovsky added the bug Something isn't working label Mar 8, 2024
@rosnovsky rosnovsky self-assigned this Mar 8, 2024
Copy link

coderabbitai bot commented Mar 8, 2024

Walkthrough

The recent updates focus on enhancing error handling and usability within the application. By adding error logging, addressing issues with empty display_name fields, and ensuring the correct functioning of instance domain and postId changes, these changes aim to improve the reliability and user experience of the application.

Changes

Files Change Summary
src/generateMastodonEmbed.ts Added error logging in the catch block for better error handling.
src/utils/convertors.ts Updated to handle empty display_name, using username as a fallback. Added error logging.
src/utils/demoPosts.ts Added a new demo post entry related to handling empty display_name.

Assessment against linked issues

Objective Addressed Explanation
Identify and resolve errors related to accountUrl when changing instance domain and postId (#25)
Investigate malfunction when changing instance domain and postId (#25)
Address "Cannot read properties of null (reading 'accountUrl')" error (#25)
Ensure toot insertion works correctly after modifying instance domain and postId (#25)
Verify changing instance domain and postId doesn't disrupt expected behavior (#25)

🐇🌟
In the code's garden, changes bloom,
Bugs scatter, as updates loom.
With each line, a fix we weave,
Ensuring no error can deceive.
🥕 Cheers to progress, swift and bright,
Guiding our application towards the light.
🌱🐰

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

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>.
    • Generate unit-tests 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8104b8b and 30a6d52.
Files selected for processing (3)
  • src/generateMastodonEmbed.ts (1 hunks)
  • src/utils/convertors.ts (2 hunks)
  • src/utils/demoPosts.ts (1 hunks)
Additional comments: 4
src/utils/demoPosts.ts (1)
src/generateMastodonEmbed.ts (1)
  • 36-36: The addition of an error logging statement within the catch block is a good practice for improving error handling and debugging. It's important to ensure that these logs are monitored and analyzed for continuous improvement. Additionally, consider implementing more user-friendly error handling mechanisms to enhance the user experience in case of failures.
src/utils/convertors.ts (2)
  • 21-21: Logging an error message when the Mastodon response is invalid is a good practice for improving error diagnostics. This change enhances the application's robustness by providing clearer insights into the nature of encountered errors.
  • 37-43: Implementing a fallback to username when display_name is empty is a sensible approach to address the issue of missing display names. This ensures that the application can still display relevant user information, maintaining a consistent user experience. Verify that this fallback mechanism does not have unintended side effects on other parts of the application where display_name is used.

Comment on lines 15 to 24
!response.account ||
!response.account.url ||
!response.account.username ||
!response.account.display_name ||
!response.account.avatar ||
!response.created_at
) {
console.error("Invalid Mastodon response", response);
return null;
}

Copy link

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [124-124]

The use of dynamically generated regular expressions based on user input in the convertCustomEmojisToImages function could potentially lead to a Regular Expression Denial-of-Service (ReDoS) vulnerability. Consider using a regex checking/sanitization library such as recheck or performing input validation to ensure that the regex does not appear vulnerable to ReDoS. This precaution will help maintain the application's performance and security.

@rosnovsky rosnovsky merged commit 03e96a5 into main Mar 8, 2024
6 checks passed
@rosnovsky rosnovsky deleted the fix/handle-empty-display-name branch March 8, 2024 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Instance domain and postId are errors after changing
1 participant