Skip to content

Conversation

@adityaanurag0219
Copy link

@adityaanurag0219 adityaanurag0219 commented Oct 15, 2025

Summary

This PR addresses issue #6670, where AxiosError.from() overwrote the original error’s stack trace. As a result, only the AxiosError internal stack appears in error logs (e.g. in Sentry), which obscures the root cause (DNS errors, timeouts, etc.)

Changes

  • Captures the error.stack before calling AxiosError.call(...)
  • After constructing the new AxiosError, appends the original stack (if present) as a Caused by: section
  • Updated logic to use only syntax supported by current ESLint (no optional chaining)
  • Added a unit test in test/specs/core/AxiosError.spec.js that asserts the new stack trace contains the original error message
  • Verified that all existing Node tests pass (219/219)
  • Browser tests are environment-dependent — local failures are acceptable if CI passes them

Example Before & After

Before :
AxiosError: Network Error
at AxiosError.from (AxiosError.js:…)

After :
AxiosError: Network Error
at AxiosError.from (AxiosError.js:…)
Caused by: Error: getaddrinfo ENOTFOUND example.com
at GetAddrInfoReqWrap.onlookupall (node:dns:…)

Impact & Backward Compatibility

No public API changes. This only enhances error diagnostics, so existing code consuming AxiosError continues to work.
This change helps debugging and observability (e.g. in error-tracking services) without altering behavior.

Testing & CI

  • Node tests ran locally and passed
  • ESLint fine after style fix
  • Browser tests may require environment setup, but should be green in CI
  • I welcome feedback or improvements if maintainers suggest adjustments

Thanks for reviewing this change and improving diagnostics for the community!

fixes #6670

@github-actions github-actions bot added the pr::fix PR that fixes a bug label Oct 15, 2025
@adityaanurag0219
Copy link
Author

adityaanurag0219 commented Oct 15, 2025

Hi maintainers 👋

This PR is ready for review — it fixes issue #6670 by preserving the original stack trace in AxiosError.from().
All Node tests passed locally, ESLint is clean, and a unit test for stack preservation was added.

Please approve workflow runs when convenient.
Thank you for your time and for maintaining Axios!

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

Labels

pr::fix PR that fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Axios stack trace useless, old issue cropping up?

2 participants