Skip to content

Conversation

@fm3
Copy link
Member

@fm3 fm3 commented Sep 24, 2025

Before:
image
After:
image

Since I’m stitching together this error string, I’m not using messages.tsx for it. Not sure what the policy is for that, hope it’s ok?

Steps to test:

  • Create an annotation
  • Delete its dataset
  • Try to re-open the annotation
  • Try to re-open the dataset

Issues:


  • Added changelog entry (create a $PR_NUMBER.md file in unreleased_changes or use ./tools/create-changelog-entry.py)
  • Considered common edge cases

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 24, 2025

📝 Walkthrough

Walkthrough

Removes a translation key from frontend translations, adds an internal helper to validate dataset usability and centralize improved error messages (including dataset id/name/status and TRACE annotation prefix) during viewer initialization, and adds a changelog entry documenting the error-message improvements.

Changes

Cohort / File(s) Summary
Translation cleanup
frontend/javascripts/messages.tsx
Removed the public translation key dataset.not_imported from the default export translation map.
Dataset usability validation refactor
frontend/javascripts/viewer/model_initialization.ts
Added internal helper assertUsableDataset(dataset, initialCommandType) to validate dataset presence/data and build contextual error messages; replaced inline validation with this helper; initialization function signature unchanged.
Changelog update
unreleased_changes/8956.md
Added entry describing improved error messages when loading unusable datasets or annotations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

bug, usability

Suggested reviewers

  • philippotto
  • hotzenklotz

Poem

A rabbit hops where code once tripped,
I patch the paths where errors slipped.
IDs now sing, and traces show,
No sudden crash—just steady flow.
I twitch my nose and dance a hop—🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly captures the primary change of providing a better error message in model initialization when a dataset is unusable. It references the relevant component and the nature of the change without extraneous detail. This allows a reviewer scanning PR history to quickly understand the core enhancement. It does not include noise like file names or emojis. Thus, it meets the criteria for a concise and clear PR title.
Linked Issues Check ✅ Passed The PR addresses the primary objective of issue #8948 by replacing the crash with a detailed error message through the new assertUsableDataset helper. The updated logic validates dataset availability and constructs contextual error messages that include dataset identifiers and status, which directly satisfies the requirement. The test steps in the PR description mirror the reproduction steps of the linked issue, ensuring thorough coverage. No additional coding requirements from the issue are left unaddressed. Thus, the PR complies with the linked issue’s objectives.
Out of Scope Changes Check ✅ Passed All modifications in this PR are confined to improving dataset initialization error handling and corresponding translation and changelog updates. There are no unrelated refactorings, feature additions, or changes to public interfaces beyond the error messaging context. The removal of the translation entry directly supports the custom error string construction. Therefore, no out-of-scope changes are present.
Description Check ✅ Passed The pull request description includes before and after screenshots, a testing procedure, and reference to the fixed issue, all of which are directly related to the changes in error handling. It describes how the error string was constructed and notes policy consideration about using translations. This content clearly supports the code changes and is not off-topic or generic. It is specific to the PR’s purpose of improving error messages. Therefore it passes the lenient description check.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch initializaton-error-toast

📜 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 a814e1b and 6e4fbec.

📒 Files selected for processing (1)
  • unreleased_changes/8956.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • unreleased_changes/8956.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: backend-tests
  • GitHub Check: build-smoketest-push
  • GitHub Check: frontend-tests

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@fm3 fm3 marked this pull request as ready for review September 24, 2025 07:59
@fm3 fm3 self-assigned this Sep 24, 2025
@fm3 fm3 requested a review from philippotto September 24, 2025 08:00
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 (2)
frontend/javascripts/viewer/model_initialization.ts (2)

216-218: Pass datasetId and accept nullable dataset to improve missing-dataset error

Include the datasetId in the error when the dataset is missing and avoid the unsafe cast by allowing a nullable APIDataset.

-  assertUsableDataset(apiDataset as StoreDataset, initialCommandType);
+  assertUsableDataset(apiDataset, initialCommandType, datasetId);

472-493: Harden assertUsableDataset — accept nullable APIDataset, add datasetId, and null‑safe access

Verified: function is at frontend/javascripts/viewer/model_initialization.ts (~472–493) and is called at line 216 with a cast (assertUsableDataset(apiDataset as StoreDataset, initialCommandType)); messages["dataset.does_not_exist"] exists (frontend/javascripts/messages.tsx:359); messages["dataset.not_imported"] is unused.

-function assertUsableDataset(dataset: StoreDataset, initialCommandType: TraceOrViewCommand) {
+function assertUsableDataset(
+  dataset: APIDataset | null | undefined,
+  initialCommandType: TraceOrViewCommand,
+  datasetId?: string,
+) {
   let error;
-  let annotationNote = "";
+  let annotationNote = "";
   if (initialCommandType.type === ControlModeEnum.TRACE) {
     annotationNote = `Failed to load annotation ${initialCommandType.annotationId}: `;
   }
 
-  if (!dataset) {
-    error = `${annotationNote}${messages["dataset.does_not_exist"]}`;
-  } else if (!dataset.dataSource.dataLayers) {
-    let statusNote = ".";
-    if (dataset.dataSource.status) {
-      statusNote = `: ${dataset.dataSource.status}`;
-    }
-    error = `${annotationNote}Dataset ‘${dataset.name}’ (${dataset.id}) is not available${statusNote}`;
+  if (dataset == null) {
+    const idNote = datasetId ? ` (id: ${datasetId})` : "";
+    error = `${annotationNote}${messages["dataset.does_not_exist"]}${idNote}`;
+  } else if (!dataset.dataSource?.dataLayers) {
+    const statusNote = dataset.dataSource?.status ? `: ${dataset.dataSource.status}` : ".";
+    error = `${annotationNote}Dataset ‘${dataset.name}’ (${dataset.id}) is not available${statusNote}`;
   }
 
   if (error) {
     Toast.error(error);
     throw HANDLED_ERROR;
   }
 }

Update the call site at model_initialization.ts:216 to drop the cast and pass datasetId (available nearby): assertUsableDataset(apiDataset, initialCommandType, datasetId);

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8115ea8 and a814e1b.

📒 Files selected for processing (3)
  • frontend/javascripts/messages.tsx (0 hunks)
  • frontend/javascripts/viewer/model_initialization.ts (2 hunks)
  • unreleased_changes/8956.md (1 hunks)
💤 Files with no reviewable changes (1)
  • frontend/javascripts/messages.tsx
🧰 Additional context used
🧬 Code graph analysis (1)
frontend/javascripts/viewer/model_initialization.ts (1)
frontend/javascripts/viewer/store.ts (2)
  • StoreDataset (566-573)
  • TraceOrViewCommand (229-242)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-smoketest-push
  • GitHub Check: backend-tests
🔇 Additional comments (3)
frontend/javascripts/viewer/model_initialization.ts (2)

495-511: LGTM: dataset initialization flow unchanged

Type and assertions look consistent with preprocess + Store usage.


472-487: Confirm policy on exposing raw dataset IDs in user‑facing errors

The new message includes the dataset’s internal id. Please confirm this is acceptable per UX/privacy guidelines (especially with shared links).

unreleased_changes/8956.md (1)

1-2: Changelog LGTM

Accurately describes the improvement without implying functional changes.

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.

sorry for the late review! I already read the code but wanted to test it too (which then slipped through somehow).

code looks good 👍 during testing I got this when deleting a DS on the dev instance:

[Server Time 2025-09-29T06:34:14.541Z] Failed RPC 97: DELETE https://initializatonerrortoast.webknossos.xyz/data/datasets/68d3a936010000b50097f657/deleteOnDisk. Response: 400 '{"messages":[{"error":"Could not delete the dataset on disk."},{"chain":"[Server Time 2025-09-29T06:34:14.540Z] Failed to remake symlinks <~ Could not update datasource-properties.json <~ Could not back up old contents: java.io.FileNotFoundException: /webknossos/binaryData/sample_organization/data_types/datasource-properties-backups.log (Permission denied)"}]}' 400

might be dev instance specific, though?

@fm3
Copy link
Member Author

fm3 commented Sep 29, 2025

Thanks!

Yes, the dev deployments don’t have full write access on their data directory. Testing locally might be better suited for this PR.

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.

works great 👍

@fm3 fm3 merged commit 0b55ea3 into master Sep 29, 2025
5 checks passed
@fm3 fm3 deleted the initializaton-error-toast branch September 29, 2025 12:23
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.

Opening annotations of deleted datasets crashes WK

3 participants