Title: SyntaxError stack trace not generated · Issue #81 · stacktracejs/error-stack-parser · GitHub
Open Graph Title: SyntaxError stack trace not generated · Issue #81 · stacktracejs/error-stack-parser
X Title: SyntaxError stack trace not generated · Issue #81 · stacktracejs/error-stack-parser
Description: Current Behavior We have detected a problem when generating stack trace from a SyntaxError. This takes place when the error cause is due to a malformed javascript code, the output of the library is not consistent: On chromium browsers it...
Open Graph Description: Current Behavior We have detected a problem when generating stack trace from a SyntaxError. This takes place when the error cause is due to a malformed javascript code, the output of the library is...
X Description: Current Behavior We have detected a problem when generating stack trace from a SyntaxError. This takes place when the error cause is due to a malformed javascript code, the output of the library is...
Opengraph URL: https://github.com/stacktracejs/error-stack-parser/issues/81
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SyntaxError stack trace not generated","articleBody":"## Current Behavior\r\n\r\nWe have detected a problem when generating stack trace from a SyntaxError. This takes place when the error cause is due to a **malformed javascript code**, the output of the library is not consistent:\r\n\r\n- On chromium browsers it returns a malformed single stack trace element not containing the lineNumber property\r\n\r\n\u003cimg width=\"639\" alt=\"Screenshot 2022-06-15 at 14 46 00\" src=\"https://user-images.githubusercontent.com/15065076/173830214-cdcb3ed3-d6fd-4841-9793-53916d632896.png\"\u003e\r\n\r\n- On non-chromium browsers it throws an exception.\r\n\r\n\u003cimg width=\"388\" alt=\"Screenshot 2022-06-15 at 14 49 36\" src=\"https://user-images.githubusercontent.com/15065076/173830896-de799971-df1e-46d3-8c3e-f147f4bacf4f.png\"\u003e\r\n\r\n## Expected Behavior\r\nWe would expect one the following two behaviours, being **number 2** the preferred:\r\n\r\n1. Consistency across all browsers. In this case, we would expect the exception on all of them.\r\n2. Handle this case and return a well formed single stack trace element, for example:\r\n\r\n\u003cimg width=\"516\" alt=\"Screenshot 2022-06-15 at 15 31 58\" src=\"https://user-images.githubusercontent.com/15065076/173839759-e15f1f93-2914-43c7-9a0c-8738c16bc614.png\"\u003e\r\n\r\n## Steps to Reproduce (for bugs)\r\n\r\nThe code below reproduces the issue:\r\n\r\n```\r\n\u003chtml\u003e\r\n \u003chead\u003e\r\n \u003ctitle\u003eInline errors page test\u003c/title\u003e\r\n \u003c/head\u003e\r\n \u003cbody\u003e\r\n \u003ch1\u003eInline errors page test\u003c/h1\u003e\r\n \u003cscript type=\"text/javascript\" src=\"error-stack-parser.js\"\u003e\u003c/script\u003e\r\n \u003cscript\u003e\r\n window.addEventListener(\"error\", (errorEvent) =\u003e {\r\n const stack = ErrorStackParser.parse(errorEvent.error)\r\n console.log(\"stack\", stack);\r\n })\r\n \u003c/script\u003e\r\n \u003cscript\u003e\r\n var a: // the malformed javascript here\r\n \u003c/script\u003e\r\n \u003c/body\u003e\r\n\u003c/html\u003e\r\n```\r\n**Important**: A SyntaxError generated from a bad usage of a API like JSON.parse does not reproduce the issue\r\n```\r\n\u003chtml\u003e\r\n \u003chead\u003e\r\n \u003ctitle\u003eInline errors page test\u003c/title\u003e\r\n \u003c/head\u003e\r\n \u003cbody\u003e\r\n \u003ch1\u003eInline errors page test\u003c/h1\u003e\r\n \u003cscript type=\"text/javascript\" src=\"error-stack-parser.js\"\u003e\u003c/script\u003e\r\n \u003cscript\u003e\r\n window.addEventListener(\"error\", (errorEvent) =\u003e {\r\n const stack = ErrorStackParser.parse(errorEvent.error);\r\n console.log(\"stack\", stack);\r\n })\r\n \u003c/script\u003e\r\n \u003cscript\u003e\r\n JSON.parse('\u003cI am not a json\u003e') --\u003e wrong input\r\n \u003c/script\u003e\r\n \u003c/body\u003e\r\n\u003c/html\u003e\r\n```\r\n\r\n## Context\r\n\u003c!--- How has this issue affected you? What are you trying to accomplish? --\u003e\r\n\u003c!--- Providing context helps us come up with a solution that is most useful in the real world --\u003e\r\n\r\n## Your Environment\r\nThis happens on all versions of the library (including the latest one). \r\nTested on different OS, such as MacOS, Fedora Linux, and Windows 10\r\n\r\n## Possible Solution\r\nIt seems that the [parse](https://github.com/stacktracejs/error-stack-parser/blob/master/error-stack-parser.js#L28,L35) function it might be the good place to start with the fix. Presumably, there is new condition to be added or a change on the regex that needs to be done, or both. \r\nOn Chromium browsers the line [return this.parseFFOrSafari(error);](https://github.com/stacktracejs/error-stack-parser/blob/master/error-stack-parser.js#L33) is the one being executed, which is wrong.\r\n\r\nOn our product we have followed a defensive approach to overcome the issue:\r\n\r\nWe leverage the information available in [ErrorEvent](https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent). So, if the library throws an exception or generates a malformed stack trace what we do is to extract **lineno**, **colno**, and **filename** from such event.","author":{"url":"https://github.com/devcorpio","@type":"Person","name":"devcorpio"},"datePublished":"2022-06-15T14:13:46.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/81/error-stack-parser/issues/81"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b15ab17a-7a83-b8bd-7295-e5e4e0f08009 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCCC:1F4A08:8E51EE:C6B542:696F3C79 |
| html-safe-nonce | 95ab0760fe8a268985e46a7545c6c3209b7dfcd08502e7e73d31028d44cb5a14 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0NDOjFGNEEwODo4RTUxRUU6QzZCNTQyOjY5NkYzQzc5IiwidmlzaXRvcl9pZCI6IjM2NDE2MjU4NzQ5NTI4MzAwNzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | dc6e79e9c2d6194c15524d71a48e905664dbbf8961cf9751e335e839ed6de303 |
| hovercard-subject-tag | issue:1272302696 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/stacktracejs/error-stack-parser/81/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1c46f2b49c329ef0fd7e85676d7f3ac4d566a32463aea457355053d233ea3223/stacktracejs/error-stack-parser/issues/81 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1c46f2b49c329ef0fd7e85676d7f3ac4d566a32463aea457355053d233ea3223/stacktracejs/error-stack-parser/issues/81 |
| og:image:alt | Current Behavior We have detected a problem when generating stack trace from a SyntaxError. This takes place when the error cause is due to a malformed javascript code, the output of the library is... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | devcorpio |
| hostname | github.com |
| expected-hostname | github.com |
| None | b278ad162d35332b6de714dfb005de04386c4d92df6475522bef910f491a35ee |
| turbo-cache-control | no-preview |
| go-import | github.com/stacktracejs/error-stack-parser git https://github.com/stacktracejs/error-stack-parser.git |
| octolytics-dimension-user_id | 6131251 |
| octolytics-dimension-user_login | stacktracejs |
| octolytics-dimension-repository_id | 15014773 |
| octolytics-dimension-repository_nwo | stacktracejs/error-stack-parser |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 15014773 |
| octolytics-dimension-repository_network_root_nwo | stacktracejs/error-stack-parser |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 39aed5006635ab6f45e6b77d23e73b08a00272a3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width