Skip to content

Conversation

knollengewaechs
Copy link
Contributor

@knollengewaechs knollengewaechs commented Jan 27, 2025

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

Steps to test:

  • I think this is best tested locally.
  • First, reproduce the bug, e.g. with the current master:
    • ( In the issue it says that the schema of the organizations table was altered when the issue occured, so maybe try to do that. This somehow did not trigger the described behaviour for me though.)
    • I found it easiest to introduce a typo to the URL in checkAnyOrganizationExists() because this triggers a 404 response and the described behaviour, redirecting you to the onboarding screen.
  • Now, check out this branch. With still having the typo or sth. similar in place, reload the page. Instead of the onboarding screen, you should now see a white screen with the words "Failed to load WEBKNOSSOS. Please try again or check the console for details." and a corresponding error in the console.
  • This behaviour should of course not be triggered by errors in different modules, so the display of other errors should still be precise.

TODOs:

  • ...

I asked for help in this thread

Issues:


(Please delete unneeded items, merge only when none are left open)

@knollengewaechs knollengewaechs self-assigned this Jan 27, 2025
Copy link
Contributor

coderabbitai bot commented Jan 27, 2025

📝 Walkthrough

Walkthrough

The pull request addresses an issue with the onboarding screen appearing incorrectly when a request to check organization existence fails. The changes modify error handling in the main application initialization process, specifically in the loadHasOrganizations function and the DOMContentLoaded event listener. The modifications aim to improve error reporting and prevent unintended onboarding screen display during request failures.

Changes

File Change Summary
frontend/javascripts/main.tsx - Removed try-catch block from loadHasOrganizations function
- Added error handling in DOMContentLoaded event listener
- Implemented error logging and user-friendly error message rendering
- Renamed loadActiveUser to tryToLoadActiveUser
CHANGELOG.unreleased.md Added an entry under the "Fixed" section describing the onboarding screen issue

Assessment against linked issues

Objective Addressed Explanation
Avoid Onboarding screen when /api/organizationsIsEmpty fails [#8056]
Prevent unintended data loss during onboarding [#8056] The objective regarding data loss prevention during onboarding was not addressed in this PR.

Suggested labels

bug, frontend

Suggested reviewers

  • philippotto

Poem

🐰 In the land of code, where errors play,
The onboarding screen won't lead us astray.
With careful hops and a clever fix,
We keep our users from onboarding tricks!
So let’s celebrate, with joy and cheer,
For smoother paths, the rabbit's here! 🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35485ea and dfd5ed5.

📒 Files selected for processing (1)
  • CHANGELOG.unreleased.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.unreleased.md
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: circleci_build

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>, 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@knollengewaechs knollengewaechs marked this pull request as ready for review January 27, 2025 17:57
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

🧹 Nitpick comments (1)
frontend/javascripts/main.tsx (1)

98-109: LGTM! Good error handling implementation.

The changes effectively prevent the onboarding screen from appearing on API failures and provide good user feedback.

Consider enhancing the error message for better accessibility:

-        <p>Failed to load WEBKNOSSOS. Please try again or check the console for details.</p>,
+        <p role="alert" style={{ margin: '20px' }}>
+          Failed to load WEBKNOSSOS. Please try again or check the console for details.
+        </p>,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13f8c14 and 15c0d02.

📒 Files selected for processing (2)
  • CHANGELOG.unreleased.md (1 hunks)
  • frontend/javascripts/main.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: circleci_build
🔇 Additional comments (2)
frontend/javascripts/main.tsx (1)

76-77: LGTM! Good simplification of error handling.

Removing the try-catch block here allows errors to propagate up to the main error handler, which aligns with the PR objectives of properly handling API failures.

CHANGELOG.unreleased.md (1)

19-19: LGTM! Clear and well-placed changelog entry.

The entry accurately describes the fix and follows the changelog format.

@knollengewaechs
Copy link
Contributor Author

@philippotto So this is my initial suggestion. I am a little insecure whether I tested it enough and all the way, because I made changes in such a meaningful component. I am looking forward to hear what you think!

Comment on lines 99 to 100
await Promise.all([loadFeatureToggles(), loadActiveUser(), loadHasOrganizations()]);
await Promise.all([loadOrganization()]);
Copy link
Member

Choose a reason for hiding this comment

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

there are now 4 function calls in this new try block. for loadHasOrganizations, you already did the testing. but what about the others? I'm not sure what their failure would cause on master (for example, what happens if loadOrganization fails). maybe the new error makes sense, but maybe it's too strict 🤔 could you test these scenarios, too?

Copy link
Contributor Author

@knollengewaechs knollengewaechs Jan 29, 2025

Choose a reason for hiding this comment

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

you are right that I did not test this enough!
If loadOrganizations fails, the same failure screen is rendered as when loadHasOrganizations fails. This is probably too strict.
An obvious solution would be to move all other api calls outside the try and catch block. the disadvantage would be that one more single await is introduced where it is not needed (within the try-catch). But thats probably the trade-off that has to be made, I dont have a simple solution where this is not the case 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that if loadFeatureToggles yields an error, a blank screen is rendered, so I included it in the try-catch.

Copy link
Member

Choose a reason for hiding this comment

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

I noticed that if loadFeatureToggles yields an error, a blank screen is rendered, so I included it in the try-catch.

Isn't the same true for loadOrganization? My understanding of the current master is the following in the error cases:

  • loadFeatureToggles: causes blank screen; therefore, needs try-catch with error screen
  • loadActiveUser: causes logged-out screen (this is alright); has try-catch + ignore error in implementation
  • loadHasOrganizations: causes onboarding screen; had try-catch + ignore but should not have it. instead, needs try-catch with error screen.
  • loadOrganization: causes blank screen; therefore, needs try-catch with error screen

so, in summary, 3 of the functions need a try-catch with error screen. your original commit was good 🙈 sorry for the confusion, I just wanted to know if everything is "as good as or better than before".
my final suggestion would be:

// note: rename loadActiveUser to tryToLoadActiveUser

try {
    await Promise.all([
      loadFeatureToggles(),
      // This function call cannot error as it has a try-catch built-in
      tryToLoadActiveUser(),
      // *Don't* ignore errors in this request. We only want
      // to show an onboarding screen if the back-end replied
      // with hasOrganizations==true.
      loadHasOrganizations(),
    ]);
    await loadOrganization();
  } catch (exc) {
    // ...
  }

what do you think? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think its good that we talk about this in detail! 🙏

loadOrganization: causes blank screen; therefore, needs try-catch with error screen

Oh, I understand that this depends on the test scenario! During login, I got an Action Not Found toast and I thought that was better than the error screen. But if the user is logged in and suddenly the request fails, the blank screen is rendered.

Right, of cause loadActiveUser cant cause an error, so it can be included into the try-catch. 👍
image

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I understand that this depends on the test scenario! During login, I got an Action Not Found toast and I thought that was better than the error screen. But if the user is logged in and suddenly the request fails, the blank screen is rendered.

could it be that you tested the "open wk & log in" scenario and I tested the "open wk while being logged in"? I also simply added throw Error() to the loadOrganization function (not sure whether that makes a difference).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could it be that you tested the "open wk & log in" scenario and I tested the "open wk while being logged in"?

yes, I think thats right 😅

Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

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

great, testing went well 👍 please see my one style suggestion.

@knollengewaechs knollengewaechs merged commit a471709 into master Feb 3, 2025
3 checks passed
@knollengewaechs knollengewaechs deleted the avoid-onboarding-screen-when-organizationisempty-fails branch February 3, 2025 13:01
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.

Avoid Onboarding screen when /api/organizationsIsEmpty fails
2 participants