Skip to content

fix(powerbi): recover from transient FailedToLoadModel errors#851

Merged
rusko124 merged 4 commits into
masterfrom
fix/powerbi-model-load-recovery
Jun 22, 2026
Merged

fix(powerbi): recover from transient FailedToLoadModel errors#851
rusko124 merged 4 commits into
masterfrom
fix/powerbi-model-load-recovery

Conversation

@rusko124

@rusko124 rusko124 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

PR Type

Bug fix, Tests


Description

  • Recover transient Power BI model-load failures

  • Cap automatic report reload attempts

  • Improve embed error reporting context

  • Add coverage for reload behavior


Diagram Walkthrough

flowchart LR
  A["Power BI embed error"] -- "inspect detail" --> B["Error helpers"]
  B -- "FailedToLoadModel and retries remain" --> C["Reload report"]
  B -- "other errors or retry limit" --> D["Report and show error"]
  C -- "rendered successfully" --> E["Reset retry counter"]
Loading

File Walkthrough

Relevant files
Bug fix
services.lib.ts
Add Power BI model-load error helpers                                       

edge-apps/powerbi/src/services.lib.ts

  • Adds FailedToLoadModel detection helper
  • Defines MAX_MODEL_RELOADS retry limit
  • Converts Power BI errors into reportable Errors
  • Adds structured Sentry context generation
+27/-0   
services.ts
Retry transient Power BI model-load failures                         

edge-apps/powerbi/src/services.ts

  • Stops embedded error events bubbling globally
  • Tracks model-load reload attempts per report
  • Reloads transient FailedToLoadModel errors
  • Shows errors after retry exhaustion
+36/-17 
Tests
services.test.ts
Test model-load reload recovery paths                                       

edge-apps/powerbi/src/services.test.ts

  • Adds mocked report.reload support
  • Verifies rendered handler signals readiness
  • Tests non-model errors still render failures
  • Tests model-load reload and retry limit
+50/-8   
Enhancement
services.types.ts
Extend Power BI error typing                                                         

edge-apps/powerbi/src/services.types.ts

  • Adds optional message to PowerBiError
  • Supports model-load error detection by message
+1/-0     

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Unhandled Rejection

report.reload() is fired without handling rejection, and the handler returns before showError. If Power BI cannot reload due to an invalid state, network failure, or expired session, this can produce an unhandled promise rejection and leave the user without an error screen. Consider catching the rejection and reporting/rendering an error fallback.

if (isModelLoadError(detail) && modelReloadAttempts < MAX_MODEL_RELOADS) {
  modelReloadAttempts += 1
  void report.reload()
  return

@github-actions

Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Handle reload promise failures

Handle a rejected report.reload() promise; otherwise a reload failure can become an
unhandled rejection and leave the embed area blank with no rendered error. Report
the reload failure and fall back to showError(detail) so the user gets a visible
failure state.

edge-apps/powerbi/src/services.ts [137-141]

 if (isModelLoadError(detail) && modelReloadAttempts < MAX_MODEL_RELOADS) {
   modelReloadAttempts += 1
-  void report.reload()
+  void report.reload().catch((reloadError: unknown) => {
+    reportError(reloadError, { source: 'powerbi-reload' })
+    showError(detail)
+  })
   return
 }
Suggestion importance[1-10]: 7

__

Why: This correctly identifies that void report.reload() can produce an unhandled rejected promise, leaving the UI without a fallback error state. The proposed catch reports the reload failure and calls showError(detail), which is a meaningful reliability improvement but limited to an error-handling edge case.

Medium
General
Broaden transient error detection

Check detailedMessage as well as message when detecting FailedToLoadModel. If Power
BI provides the code only in detailedMessage, the new recovery path will be skipped
and users will still see the error screen.

edge-apps/powerbi/src/services.lib.ts [11-13]

 export function isModelLoadError(error: PowerBiError): boolean {
-  return (error.message ?? '').includes(MODEL_LOAD_ERROR)
+  return [error.message, error.detailedMessage].some((message) =>
+    (message ?? '').includes(MODEL_LOAD_ERROR),
+  )
 }
Suggestion importance[1-10]: 6

__

Why: The suggestion is accurate because PowerBiError includes both message and detailedMessage, while isModelLoadError currently only checks message. This improves robustness if Power BI emits FailedToLoadModel in detailedMessage, though the impact depends on the actual shape of Power BI errors.

Low

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds resilience to the Power BI embed flow by retrying transient FailedToLoadModel failures and improving how embed errors are reported to Sentry.

Changes:

  • Detect FailedToLoadModel and reload the report up to MAX_MODEL_RELOADS times before showing an error.
  • Improve Sentry reporting by converting Power BI error payloads into a real Error plus structured context.
  • Extend tests to cover model-load retry behavior and the new reporting shape.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
edge-apps/powerbi/src/services.types.ts Extends the Power BI error shape to include a top-level message.
edge-apps/powerbi/src/services.ts Adds model-load retry logic, adjusts event handlers, and reports errors with richer Sentry context.
edge-apps/powerbi/src/services.test.ts Updates mocks and adds tests for retry vs. render-error behavior.
edge-apps/powerbi/src/services.lib.ts Introduces model-load detection and helper functions for Sentry reporting/context.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread edge-apps/powerbi/src/services.ts
Comment thread edge-apps/powerbi/src/services.ts Outdated
Comment thread edge-apps/powerbi/src/services.lib.ts Outdated
rusko124 added 2 commits June 22, 2026 16:31
- Updated error reporting to include detailed messages in Sentry.
- Improved the display of error messages in the UI when reloads fail.
- Added tests to verify the correct rendering of error messages.
- Introduced a delay mechanism for retrying failed model loads to improve recovery from transient errors.
- Updated error handling to ensure that reload attempts are properly counted and managed.
- Enhanced tests to validate the new retry behavior and ensure correct error reporting.
nicomiguelino
nicomiguelino previously approved these changes Jun 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Comment thread edge-apps/powerbi/src/services.lib.ts
Comment thread edge-apps/powerbi/src/services.lib.ts
Comment thread edge-apps/powerbi/src/services.lib.ts Outdated
Comment thread edge-apps/powerbi/src/services.ts Outdated
…failures

- Added a default error message for better user feedback when loading reports fails.
- Refactored the reload logic to prevent duplicate reload attempts and ensure proper error handling.
- Enhanced tests to validate the new behavior of error handling and reload scheduling.
@rusko124 rusko124 merged commit bfa3b17 into master Jun 22, 2026
4 checks passed
@nicomiguelino nicomiguelino deleted the fix/powerbi-model-load-recovery branch June 22, 2026 13:21
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