Skip to content

fix: prevent edge function crashes with null checks and type validation#174

Merged
JakeSCahill merged 2 commits into
mainfrom
fix/edge-function-exceptions
May 18, 2026
Merged

fix: prevent edge function crashes with null checks and type validation#174
JakeSCahill merged 2 commits into
mainfrom
fix/edge-function-exceptions

Conversation

@JakeSCahill
Copy link
Copy Markdown
Contributor

@JakeSCahill JakeSCahill commented May 18, 2026

Summary

Fixes uncaught exceptions in Netlify edge functions that were causing crashes in production.

Changes

proxy-api-docs.js

  • Add null check before head.appendChild(): Prevents crash when the HTML document doesn't have a proper head element (line 174-178)
  • Add fallback for document.documentElement: Uses originalHtml if documentElement is null (line 181)
  • Add type check for error in fetchWithRetry: Safely handles non-Error exceptions when logging (line 217-218)

feedback-api.ts

  • Add type validation for path and feedback: Ensures both are strings before accessing .length property, preventing crashes when invalid data types are submitted (line 35-43)

Root Cause

The primary crash was caused by line 176 in proxy-api-docs.js attempting to call head.appendChild(style) without checking if head was null. When widget files failed to load (as shown in logs), the code continued processing but hit this unchecked operation and threw an uncaught exception.

Testing

All changes maintain existing functionality while adding safety checks for edge cases:

  • Widgets failing to load no longer causes crashes
  • Invalid API payloads are rejected with proper error messages
  • All operations gracefully handle null/undefined values

🤖 Generated with Claude Code

Fixes uncaught exceptions in edge functions:

proxy-api-docs.js:
- Add null check before head.appendChild() to prevent crash when head element is missing
- Add fallback for document.documentElement to use originalHtml if null
- Add type check for error.message in fetchWithRetry to handle non-Error exceptions

feedback-api.ts:
- Add type validation to ensure path and feedback are strings before accessing .length
- Prevents crashes when invalid data types are submitted

All changes maintain existing functionality while preventing edge cases that could cause crashes.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@JakeSCahill JakeSCahill requested a review from a team as a code owner May 18, 2026 14:17
@netlify
Copy link
Copy Markdown

netlify Bot commented May 18, 2026

Deploy Preview for redpanda-documentation ready!

Name Link
🔨 Latest commit 7879626
🔍 Latest deploy log https://app.netlify.com/projects/redpanda-documentation/deploys/6a0b205bf19ba2000870f66f
😎 Deploy Preview https://deploy-preview-174--redpanda-documentation.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 94 (🟢 up 12 from production)
Accessibility: 96 (no change from production)
Best Practices: 100 (no change from production)
SEO: 83 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@JakeSCahill JakeSCahill merged commit 2b953df into main May 18, 2026
1 check failed
@JakeSCahill JakeSCahill deleted the fix/edge-function-exceptions branch May 18, 2026 14:21
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