Skip to content

Generalize snackWithFallback for remaining error handlers#3890

Open
flomillot wants to merge 3 commits intomainfrom
feat/generalize-snack-with-fallback
Open

Generalize snackWithFallback for remaining error handlers#3890
flomillot wants to merge 3 commits intomainfrom
feat/generalize-snack-with-fallback

Conversation

@flomillot
Copy link
Copy Markdown
Contributor

@flomillot flomillot commented Apr 17, 2026

Summary

  • Replace remaining snackError({messageTxt: error.message, ...}) patterns with snackWithFallback(snackError, error, {...}) to support structured error display (ProblemDetailError, business errors)
  • Follows up on feat(error-handling): generalize snack error with fallback #3452 which generalized this pattern across most of the codebase
  • Files updated: study-container.jsx, single-line-diagram-content.tsx, gs-map-equipments.ts, pcc-min-export-button.tsx, use-get-pcc-min-parameters.ts

Note: globalFiltersMiddleware.ts was not converted because Redux middlewares cannot access React hooks (useSnackMessage). An architectural bridge would be needed to expose snackError to middleware.

Replace direct snackError({messageTxt: error.message, ...}) calls with
snackWithFallback(snackError, error, {...}) to support structured error
display (ProblemDetailError, business errors) consistently across the
codebase.

Signed-off-by: Florent MILLOT <millotflo@gmail.com>
Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

📝 Walkthrough

Walkthrough

The PR replaces direct error notification calls with a fallback-based error handling mechanism across multiple components. All instances of snackError({ messageTxt: error.message, headerId: ... }) are replaced with snackWithFallback(snackError, error, { headerId: ... }), delegating error-to-message conversion to a centralized utility while maintaining the same error identifiers.

Changes

Cohort / File(s) Summary
Analysis & Parameter Error Handling
src/components/dialogs/parameters/use-get-pcc-min-parameters.ts, src/components/grid-layout/cards/diagrams/singleLineDiagram/single-line-diagram-content.tsx, src/components/study-container.jsx
Updated error notification calls to use snackWithFallback wrapper for parameter retrieval failures, short-circuit analysis errors, and node building failures. Error headerId values preserved while delegating message extraction to fallback mechanism.
Equipment & Export Error Handling
src/components/network/gs-map-equipments.ts, src/components/results/pccmin/pcc-min-export-button.tsx
Replaced direct snackError invocations with snackWithFallback in equipment data loading and CSV export error paths. Multiple catch blocks in gs-map-equipments.ts updated to use consistent fallback error handling pattern.

Suggested Reviewers

  • Meklo
  • sBouzols
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: replacing error handler patterns across multiple files to support structured error display.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose, affected files, and explicitly noting why one file was excluded.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
src/components/network/gs-map-equipments.ts (1)

60-98: LGTM – consider extracting the duplicated .catch handler.

All eight .catch handlers in initEquipments and reloadImpactedSubstationsEquipments now follow the same 4-line pattern (console.error + conditional snackWithFallback with the same headerId). Behavior is correct and consistent with the PR objective. As an optional follow-up, extracting a private handleLoadError = (error) => { ... } method would remove the duplication.

♻️ Optional refactor
+    private handleLoadError = (error: unknown) => {
+        console.error((error as Error)?.message);
+        if (this.errHandler) {
+            snackWithFallback(this.errHandler, error, { headerId: 'MapEquipmentsLoadError' });
+        }
+    };

Then each .catch((error) => { ... }) becomes .catch(this.handleLoadError).

Also applies to: 166-189

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/network/gs-map-equipments.ts` around lines 60 - 98, Extract
the duplicated four-line .catch handler into a single private method (e.g.,
handleLoadError = (error) => { ... }) and replace each .catch((error) => { ...
}) in initEquipments and reloadImpactedSubstationsEquipments with
.catch(this.handleLoadError); the method should call
console.error(error.message) and, if this.errHandler exists, call
snackWithFallback(this.errHandler, error, { headerId: 'MapEquipmentsLoadError'
}) to preserve current behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/components/network/gs-map-equipments.ts`:
- Around line 60-98: Extract the duplicated four-line .catch handler into a
single private method (e.g., handleLoadError = (error) => { ... }) and replace
each .catch((error) => { ... }) in initEquipments and
reloadImpactedSubstationsEquipments with .catch(this.handleLoadError); the
method should call console.error(error.message) and, if this.errHandler exists,
call snackWithFallback(this.errHandler, error, { headerId:
'MapEquipmentsLoadError' }) to preserve current behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: da995a2e-b34d-49f4-aa86-3dbfc85a9b50

📥 Commits

Reviewing files that changed from the base of the PR and between 55ef1f2 and 73b4025.

📒 Files selected for processing (5)
  • src/components/dialogs/parameters/use-get-pcc-min-parameters.ts
  • src/components/grid-layout/cards/diagrams/singleLineDiagram/single-line-diagram-content.tsx
  • src/components/network/gs-map-equipments.ts
  • src/components/results/pccmin/pcc-min-export-button.tsx
  • src/components/study-container.jsx

@sonarqubecloud
Copy link
Copy Markdown

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