-
-
Notifications
You must be signed in to change notification settings - Fork 445
Add original path to error messages #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
b25a26b
to
3f25805
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Can we move forward and make a release for this? this really helps a lot with migrating from Express 4 to Express 5 |
I think it is time to land it with new realease |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #363 +/- ##
===========================================
- Coverage 100.00% 99.21% -0.79%
===========================================
Files 1 1
Lines 668 381 -287
Branches 151 132 -19
===========================================
- Hits 668 378 -290
- Misses 0 3 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Refactored and added a test to reduce stack size for pillarjs/router#158. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, for posterity, why did you stop using generators?
Easiest way reduce the error stack size, otherwise it has 2-3 lines per generator. |
function* lexer(str: string): Generator<LexToken, LexToken> { | ||
function errorMessage(text: string, originalPath: string | undefined) { | ||
let message = text; | ||
if (originalPath !== undefined) message += `: ${originalPath}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have actually been meaning to ask if we could get the individual things on the error instance as properties, so this PR feel like a great time to mention that. It would help for o11y to have them that way as well as in the message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the path or something else too? I can add it in a new PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to skip for now. I forgot why I didn't do this originally but turning this into the error object instead of the message adds an extra line to the error stack which is additional obfuscation of the source (one complaint in the issue I'm trying to resolve).
Adding it to every error in the source code increases the package size by 1%. I don't think it's currently worth it since no one has asked for it, but if you feel strongly I can open the change still.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened a PR here #398.
Found a way to minimize the size increase a bit more by using an error sub-class. Since the package is ES2015+ that should work everywhere I support. Using the custom class does not add to the stack size in node at least.
 <h3>Snyk has created this PR to upgrade path-to-regexp from 8.2.0 to 8.3.0.</h3> :information_source: Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project. <hr/> - The recommended version is **1 version** ahead of your current version. - The recommended version was released **25 days ago**. <details> <summary><b>Release notes</b></summary> <br/> <details> <summary>Package name: <b>path-to-regexp</b></summary> <ul> <li> <b>8.3.0</b> - <a href="https://redirect.github.com/pillarjs/path-to-regexp/releases/tag/v8.3.0">2025-09-02</a></br><p><strong>Changed</strong></p> <ul> <li>Add custom error class (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="3332530309" data-permission-text="Title is private" data-url="pillarjs/path-to-regexp#398" data-hovercard-type="pull_request" data-hovercard-url="/pillarjs/path-to-regexp/pull/398/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/pull/398">#398</a>) <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pillarjs/path-to-regexp/commit/2a7f2a4e9ba42eee41aa9d7a1a69eddb43b79a61/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/commit/2a7f2a4e9ba42eee41aa9d7a1a69eddb43b79a61"><tt>2a7f2a4</tt></a></li> <li>Allow plain objects for <code>TokenData</code> (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="3281561483" data-permission-text="Title is private" data-url="pillarjs/path-to-regexp#391" data-hovercard-type="pull_request" data-hovercard-url="/pillarjs/path-to-regexp/pull/391/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/pull/391">#391</a>) <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pillarjs/path-to-regexp/commit/687a9bbc735245b2688c17db7e9fe86013ea0c77/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/commit/687a9bbc735245b2688c17db7e9fe86013ea0c77"><tt>687a9bb</tt></a></li> <li>Escape text should escape backslash (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="3281489414" data-permission-text="Title is private" data-url="pillarjs/path-to-regexp#390" data-hovercard-type="pull_request" data-hovercard-url="/pillarjs/path-to-regexp/pull/390/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/pull/390">#390</a>) <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pillarjs/path-to-regexp/commit/a4a8552c9fb4449c470fb9ead458df1c89cadb72/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/commit/a4a8552c9fb4449c470fb9ead458df1c89cadb72"><tt>a4a8552</tt></a></li> <li>Improved error messages and stack size (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="3054423448" data-permission-text="Title is private" data-url="pillarjs/path-to-regexp#363" data-hovercard-type="pull_request" data-hovercard-url="/pillarjs/path-to-regexp/pull/363/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/pull/363">#363</a>) <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pillarjs/path-to-regexp/commit/a6bdf4045f369474e4e580bc6fcadb6bd806e62e/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/commit/a6bdf4045f369474e4e580bc6fcadb6bd806e62e"><tt>a6bdf40</tt></a></li> </ul> <p><strong>Other</strong></p> <ul> <li>Minifying the parser <ul> <li>PR (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="3352988435" data-permission-text="Title is private" data-url="pillarjs/path-to-regexp#401" data-hovercard-type="pull_request" data-hovercard-url="/pillarjs/path-to-regexp/pull/401/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/pull/401">#401</a>) <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pillarjs/path-to-regexp/commit/9df2448fdfca9d2957cf47a1777b5deda9be18cf/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/commit/9df2448fdfca9d2957cf47a1777b5deda9be18cf"><tt>9df2448</tt></a></li> <li>PR (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="3301895649" data-permission-text="Title is private" data-url="pillarjs/path-to-regexp#395" data-hovercard-type="pull_request" data-hovercard-url="/pillarjs/path-to-regexp/pull/395/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/pull/395">#395</a>) <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pillarjs/path-to-regexp/commit/4a915059a843dfdd122a0c4936837c7fdda2d4ee/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/commit/4a915059a843dfdd122a0c4936837c7fdda2d4ee"><tt>4a91505</tt></a></li> <li>Shaving some bytes <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pillarjs/path-to-regexp/commit/d63f44bc54f2c6fe7d35dc77f8515622006bf7cb/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/commit/d63f44bc54f2c6fe7d35dc77f8515622006bf7cb"><tt>d63f44b</tt></a></li> <li>Remove optional operator <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pillarjs/path-to-regexp/commit/973d15c262f113c4cb88762971920053fdbd31ff/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/commit/973d15c262f113c4cb88762971920053fdbd31ff"><tt>973d15c</tt></a></li> </ul> </li> </ul> <p><a class="commit-link" href="https://redirect.github.com/pillarjs/path-to-regexp/compare/v8.2.0...v8.3.0"><tt>v8.2.0...v8.3.0</tt></a></p> </li> <li> <b>8.2.0</b> - <a href="https://redirect.github.com/pillarjs/path-to-regexp/releases/tag/v8.2.0">2024-09-26</a></br><p><strong>Fixed</strong></p> <ul> <li>Allowing <code>path-to-regexp</code> to run on older browsers by targeting ES2015 <ul> <li>Target ES2015 <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pillarjs/path-to-regexp/commit/59690338f2a089f45505718c94b86dcb2d32f29d/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/commit/59690338f2a089f45505718c94b86dcb2d32f29d"><tt>5969033</tt></a> <ul> <li>Also saved <em>0.22kb</em> (10%!) by removing the private class field down level</li> </ul> </li> <li>Remove <code>s</code> flag from regexp <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/pillarjs/path-to-regexp/commit/51dbd45e00043f082e3cf1857861e856c40a32f0/hovercard" href="https://redirect.github.com/pillarjs/path-to-regexp/commit/51dbd45e00043f082e3cf1857861e856c40a32f0"><tt>51dbd45</tt></a></li> </ul> </li> </ul> <p><a class="commit-link" href="https://redirect.github.com/pillarjs/path-to-regexp/compare/v8.1.0...v8.2.0"><tt>v8.1.0...v8.2.0</tt></a></p> </li> </ul> from <a href="https://redirect.github.com/pillarjs/path-to-regexp/releases">path-to-regexp GitHub release notes</a> </details> </details> --- > [!IMPORTANT] > > - Check the changes in this PR to ensure they won't cause issues with your project. > - This PR was automatically created by Snyk using the credentials of a real user. --- **Note:** _You are seeing this because you or someone else with access to this repository has authorized Snyk to open upgrade PRs._ **For more information:** <img src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6InJyWmxZcEdHY2RyTHZsb0lYd0dUcVg4WkFRTnNCOUEwIiwiYW5vbnltb3VzSWQiOiI2ZjIyMWFhNS01NDQ4LTQwMDgtODEzNy05NjljNmM0MmJiY2IiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6IjZmMjIxYWE1LTU0NDgtNDAwOC04MTM3LTk2OWM2YzQyYmJjYiJ9fQ==" width="0" height="0"/> > - 🧐 [View latest project report](https://app.snyk.io/org/szotkowski/project/36f26f5b-e4bf-4cb8-ae5b-087fbc45bf4d?utm_source=github&utm_medium=referral&page=upgrade-pr) > - 📜 [Customise PR templates](https://docs.snyk.io/scan-using-snyk/pull-requests/snyk-fix-pull-or-merge-requests/customize-pr-templates?utm_source=&utm_content=fix-pr-template) > - 🛠 [Adjust upgrade PR settings](https://app.snyk.io/org/szotkowski/project/36f26f5b-e4bf-4cb8-ae5b-087fbc45bf4d/settings/integration?utm_source=github&utm_medium=referral&page=upgrade-pr) > - 🔕 [Ignore this dependency or unsubscribe from future upgrade PRs](https://app.snyk.io/org/szotkowski/project/36f26f5b-e4bf-4cb8-ae5b-087fbc45bf4d/settings/integration?pkg=path-to-regexp&utm_source=github&utm_medium=referral&page=upgrade-pr#auto-dep-upgrades) [//]: # 'snyk:metadata:{"breakingChangeRiskLevel":null,"FF_showPullRequestBreakingChanges":null,"FF_showPullRequestBreakingChangesWebSearch":null,"customTemplate":{"variablesUsed":[],"fieldsUsed":[]},"dependencies":[{"name":"path-to-regexp","from":"8.2.0","to":"8.3.0"}],"env":"prod","hasFixes":false,"isBreakingChange":false,"isMajorUpgrade":false,"issuesToFix":[],"prId":"6f221aa5-5448-4008-8137-969c6c42bbcb","prPublicId":"6f221aa5-5448-4008-8137-969c6c42bbcb","packageManager":"npm","priorityScoreList":[],"projectPublicId":"36f26f5b-e4bf-4cb8-ae5b-087fbc45bf4d","projectUrl":"https://app.snyk.io/org/szotkowski/project/36f26f5b-e4bf-4cb8-ae5b-087fbc45bf4d?utm_source=github&utm_medium=referral&page=upgrade-pr","prType":"upgrade","templateFieldSources":{"branchName":"default","commitMessage":"default","description":"default","title":"default"},"templateVariants":[],"type":"auto","upgrade":[],"upgradeInfo":{"versionsDiff":1,"publishedDate":"2025-09-02T21:13:13.739Z"},"vulns":[]}' Co-authored-by: snyk-bot <[email protected]>
Closes #336, #358, #356, and #354.
Adds
originalPath
toTokenData
, which will be used (when available) for the error messages. It's already added to any methods that input a string.