fix: make GraphError body/cause non-enumerable#552
Merged
Conversation
body and cause dumped the full Graph API response + raw axios error (including config with auth headers) on every console.log/throw. Now hidden from inspect output but still accessible programmatically. Co-Authored-By: Claude <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR updates GraphError so sensitive/verbose fields (body, cause) are non-enumerable to keep logs and thrown error output concise and reduce accidental exposure of Graph API responses and HTTP client details.
Changes:
- Stop passing
causeviaErrorconstructor options and instead attachcauseas a non-enumerable property. - Attach
bodyas a non-enumerable property viaObject.defineProperty. - Make
body/causenon-writable to prevent mutation after construction.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…d tests
- Use super(message, { cause }) to preserve native Error.cause behavior,
then redefine enumerability after
- Use writable: true, configurable: true to match native Error semantics
- Add test asserting body/cause are hidden from Object.keys and JSON.stringify
Co-Authored-By: Claude <[email protected]>
Node's util.inspect special-cases [cause] and always prints it regardless of enumerability. Renamed to `source` to avoid this. No data lost — err.source holds the original axios error. Co-Authored-By: Claude <[email protected]>
Jesperholmbergmsft
approved these changes
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bodyandsource(previouslycause) onGraphErroruseObject.definePropertywithenumerable: falsecauserenamed tosourcebecause Node'sutil.inspecthard-codes[cause]display regardless of enumerabilityerr.body,err.sourcestill work for programmatic accessBefore
After
Test plan
npx jestinpackages/graph— all 64 tests passGraphErrorand confirm console output is cleanerr.bodyanderr.sourcestill return correct values