Skip to content

fix: adding a np check for error.stack#314

Merged
vdua merged 1 commit intomainfrom
fix/error-stack
Nov 4, 2025
Merged

fix: adding a np check for error.stack#314
vdua merged 1 commit intomainfrom
fix/error-stack

Conversation

@vdua
Copy link
Collaborator

@vdua vdua commented Oct 26, 2025

  • error.stack is not a standard api

Please ensure your pull request adheres to the following guidelines:

  • make sure to link the related issues in this description
  • when merging / squashing, make sure the fixed issue references are visible in the commits, for easy compilation of release notes

Related Issues

Thanks for contributing!

Test URL

https://fix-error-stack--helix-rum-js--adobe.aem.live/test/static.html

- error.stack is not a standard api
@aem-code-sync
Copy link

aem-code-sync bot commented Oct 26, 2025

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
In case there are problems, just click a checkbox below to rerun the respective action.

  • Re-run PSI checks
  • Re-sync branch
Commits
@adobe-bot
Copy link
Collaborator

adobe-bot commented Oct 26, 2025

Claude finished @vdua's task —— View job


Code Review Complete ✅

I've analyzed the pull request that adds a null pointer check for error.stack. Here's my comprehensive review:

Todo List:

  • Read repository guidelines (CLAUDE.md)
  • Analyze the code changes in src/index.js
  • Provide comprehensive review feedback

Review Feedback

Positive Aspects

  1. Important Bug Fix: The addition of the if (error.stack) check on line 35 is a crucial defensive programming practice. You're absolutely right that error.stack is not part of the standard Error API and can be undefined in some environments.

  2. Minimal Impact: The change is surgical and doesn't alter the overall logic flow - if error.stack is falsy, the code simply skips the stack processing and keeps the default source: 'undefined error'.

  3. Proper Exception Handling: The change is already wrapped in a try-catch block, providing additional safety.

🔍 Code Quality Assessment

  • Good: The null check follows JavaScript best practices
  • Good: Maintains existing code style and indentation
  • Good: No performance impact - simple conditional check

🛡️ Security Considerations

  • Safe: No security concerns introduced
  • Good: Prevents potential runtime errors that could crash error reporting

Performance Considerations

  • Minimal Impact: Single boolean check has negligible performance cost
  • Positive: May actually improve performance by avoiding unnecessary string operations when error.stack is undefined

🧪 Test Coverage Assessment

I reviewed the existing error handling tests in the /test/errors/ directory. The current tests appear to focus on scenarios with valid Error objects that have stack traces.

Recommendation: Consider adding a test case specifically for an error object without a stack property to ensure this code path is covered:

// Test case suggestion for error without stack it('handles error without stack property', async () => { await test(() => { const errorWithoutStack = new Error('No stack'); delete errorWithoutStack.stack; // Remove stack property throw errorWithoutStack; }, (source) => { assert.strictEqual(source, 'undefined error'); }, (target) => { assert.strictEqual(target, 'Error: No stack'); }, config.queue); });

📝 Minor Observations

  1. The PR removes a newline at the end of the file (line 110) - this is cosmetic and doesn't affect functionality
  2. The indentation change on line 36-40 is purely for readability within the new if block

Overall Assessment

This is a solid defensive programming fix that addresses a real-world compatibility issue. The change is safe, minimal, and follows good coding practices. The modification properly handles the edge case where error.stack might not exist while maintaining all existing functionality.

Recommendation: Approve - This change improves the robustness of error handling without introducing any risks.


@aem-code-sync
Copy link

aem-code-sync bot commented Oct 26, 2025

Page Scores Audits Google
📱 /test/static.html PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI
🖥️ /test/static.html PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI
@codecov
Copy link

codecov bot commented Oct 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@vdua vdua requested review from kptdobe and trieloff October 28, 2025 17:40
@vdua vdua merged commit a33aa40 into main Nov 4, 2025
14 checks passed
@vdua vdua deleted the fix/error-stack branch November 4, 2025 10:02
adobe-bot pushed a commit that referenced this pull request Nov 14, 2025
## [2.13.7](v2.13.6...v2.13.7) (2025-11-14) ### Bug Fixes * adding a np check for error.stack ([#314](#314)) ([a33aa40](a33aa40))
@adobe-bot
Copy link
Collaborator

🎉 This PR is included in version 2.13.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 participants