Skip to content

Conversation

@nicomiguelino
Copy link
Contributor

@nicomiguelino nicomiguelino commented Jan 14, 2026

User description

Add error handling utilities to the edge-apps-library


PR Type

Enhancement, Tests


Description

  • Introduce error handling utilities with panic-overlay

  • Expose setupErrorHandling in utils index

  • Integrate error handling in Menu Board and QR Code

  • Add and configure display_errors setting for apps

  • Cover utility with unit tests


File Walkthrough

Relevant files
Tests
3 files
setup.ts
Add global.Node to test environment                                           
+1/-0     
error-handling.test.ts
Add tests for setupErrorHandling behavior                               
+45/-0   
main.test.ts
Reorder test imports for consistency                                         
+1/-1     
Error handling
1 files
error-handling.ts
Introduce setupErrorHandling with panic-overlay                   
+17/-0   
Enhancement
3 files
index.ts
Export error-handling utilities                                                   
+1/-0     
main.ts
Integrate setupErrorHandling on load                                         
+2/-0     
main.ts
Integrate setupErrorHandling on window load                           
+4/-0     
Dependencies
1 files
package.json
Add panic-overlay dependency                                                         
+1/-0     
Configuration changes
4 files
screenly.yml
Add `display_errors` setting to config                                     
+11/-0   
screenly_qc.yml
Add `display_errors` setting to QC config                               
+11/-0   
screenly.yml
Add `display_errors` setting to config                                     
+11/-0   
screenly_qc.yml
Add `display_errors` setting to QC config                               
+11/-0   

- Add error-handling.ts with error utility functions
- Update exports in utils/index.ts
- Update package dependencies
@github-actions
Copy link

github-actions bot commented Jan 14, 2026

PR Reviewer Guide 🔍

(Review updated until commit a46c174)

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

Setting Type Mismatch

The display_errors setting is declared with type: string but its help_text schema specifies type: boolean. Confirm if this mismatch is intended and ensure consistent parsing of boolean values.

display_errors:
  type: string
  default_value: 'false'
  title: Display Errors
  optional: true
  help_text:
    properties:
      advanced: true
      help_text: For debugging purposes to display errors on the screen.
      type: boolean
    schema_version: 1
Global Namespace Pollution

Assigning to global.Node may override or conflict with existing Node globals. Verify this assignment is necessary and won't introduce side effects.

global.Node = dom.window.Node
Event Listener Leak

Calling setupErrorHandling multiple times will add event listeners on each invocation. Consider removing existing listeners or ensuring it's only called once to avoid memory leaks.

if (displayErrors) {
  window.addEventListener('error', signalReady)
  window.addEventListener('unhandledrejection', signalReady)
}

@github-actions
Copy link

github-actions bot commented Jan 14, 2026

PR Code Suggestions ✨

Latest suggestions up to a46c174
Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Coerce display_errors to boolean

Explicitly coerce the display_errors setting to a boolean so that string values like
'false' don’t get treated as truthy. Fetch it as a string and compare to 'true'
before configuring panic-overlay and registering listeners.

edge-apps/edge-apps-library/src/utils/error-handling.ts [9-16]

-const displayErrors = getSettingWithDefault<boolean>('display_errors', false)
+const rawDisplayErrors = getSettingWithDefault<string>('display_errors', 'false')
+const displayErrors = rawDisplayErrors === 'true'
 panic.configure({
   handleErrors: displayErrors,
 })
 if (displayErrors) {
   window.addEventListener('error', signalReady)
   window.addEventListener('unhandledrejection', signalReady)
 }
Suggestion importance[1-10]: 8

__

Why: The suggestion prevents string values like "false" from being truthy by explicitly casting, which fixes a key bug in error display configuration.

Medium
General
Initialize error handling earlier

Invoke setupErrorHandling() at module initialization instead of inside the load
callback so that panic-overlay is configured and global error listeners are in place
before any load-time errors occur.

edge-apps/menu-board/src/main.ts [166-169]

+setupErrorHandling()
 window.addEventListener('load', () => {
-  setupErrorHandling()
   initializeMenuBoard()
 })
Suggestion importance[1-10]: 6

__

Why: Calling setupErrorHandling() before the load event ensures panic-overlay is ready to catch any early errors without altering page initialization logic.

Low
Call error handler before onload

Move setupErrorHandling() outside of the window.onload handler so that panic-overlay
and its global listeners are installed immediately, catching errors during startup
rather than after load.

edge-apps/qr-code/src/main.ts [36-46]

+// Setup error handling with panic-overlay
+setupErrorHandling()
 window.onload = function () {
-  // Setup error handling with panic-overlay
-  setupErrorHandling()
-
   // Setup branding colors using the library
   setupTheme()
 ...
Suggestion importance[1-10]: 5

__

Why: Moving setupErrorHandling() outside the window.onload handler catches startup errors sooner but offers a minor improvement in practice.

Low

Previous suggestions

Suggestions up to commit 67641be
CategorySuggestion                                                                                                                                    Impact
Possible issue
Guard browser environment usage

Guard access to window to avoid runtime errors in non-browser or SSR environments.
Wrap the conditional and listener registrations in a typeof window !== 'undefined'
check.

edge-apps/edge-apps-library/src/utils/error-handling.ts [13-16]

-if (displayErrors) {
+if (typeof window !== 'undefined' && displayErrors) {
   window.addEventListener('error', signalReady)
   window.addEventListener('unhandledrejection', signalReady)
 }
Suggestion importance[1-10]: 7

__

Why: Wrapping the listener registration in a typeof window !== 'undefined' guard prevents runtime errors in non-browser or SSR environments.

Medium
General
Prevent event argument pollution

Use a wrapper function for signalReady to prevent accidentally passing the event
object as an argument. This ensures signalReady is invoked without unexpected
parameters.

edge-apps/edge-apps-library/src/utils/error-handling.ts [14-15]

-window.addEventListener('error', signalReady)
-window.addEventListener('unhandledrejection', signalReady)
+window.addEventListener('error', () => signalReady())
+window.addEventListener('unhandledrejection', () => signalReady())
Suggestion importance[1-10]: 4

__

Why: Using a wrapper ensures signalReady is called without unintended event arguments, though it has minimal impact since extra parameters would be ignored.

Low

- Add tests for setupErrorHandling function
- Test display_errors setting behavior and event listener registration
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds error handling utilities to the edge-apps-library using the panic-overlay package. The implementation allows developers to optionally display errors on screen during development via a display_errors setting.

Changes:

  • Adds setupErrorHandling() function that configures panic-overlay based on the display_errors setting
  • Exports the new error-handling utility through the utils index
  • Adds panic-overlay dependency (version 1.0.51) and its transitive dependencies

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/utils/error-handling.ts Implements the main error handling setup function
src/utils/error-handling.test.ts Provides test coverage for the error handling utility
src/utils/index.ts Exports the error-handling module for public API access
src/test/setup.ts Adds Node global to test environment for JSDOM compatibility
package.json Adds panic-overlay as a runtime dependency
bun.lock Updates lock file with panic-overlay and transitive dependencies

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

- Add display_errors setting to screenly.yml and screenly_qc.yml
- Enable error display for debugging purposes
- Add display_errors setting to screenly.yml and screenly_qc.yml
- Import and call setupErrorHandling in main.ts
@nicomiguelino nicomiguelino marked this pull request as ready for review January 16, 2026 02:55
@github-actions
Copy link

Persistent review updated to latest commit a46c174

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.

1 participant