@visulima/error 1.0.2 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +80 -1
- package/dist/chunk-26F4MLO2.js +6 -0
- package/dist/chunk-26F4MLO2.js.map +1 -0
- package/dist/chunk-7Q3PPTBP.js +5 -0
- package/dist/chunk-7Q3PPTBP.js.map +1 -0
- package/dist/chunk-F52HEHA7.js +13 -0
- package/dist/chunk-F52HEHA7.js.map +1 -0
- package/dist/chunk-X3TE67TZ.js +7 -0
- package/dist/chunk-X3TE67TZ.js.map +1 -0
- package/dist/error.d.ts +17 -0
- package/dist/error.js +4 -0
- package/dist/error.js.map +1 -0
- package/dist/index.d.ts +7 -50
- package/dist/index.js +12 -8
- package/dist/index.js.map +1 -1
- package/dist/sourcemap.d.ts +6 -0
- package/dist/sourcemap.js +4 -0
- package/dist/sourcemap.js.map +1 -0
- package/dist/stacktrace.d.ts +7 -0
- package/dist/stacktrace.js +4 -0
- package/dist/stacktrace.js.map +1 -0
- package/dist/types-e15294e6.d.ts +48 -0
- package/package.json +40 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## @visulima/error [1.1.1](https://github.com/visulima/visulima/compare/@visulima/error@1.1.0...@visulima/error@1.1.1) (2023-11-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Dependencies
|
|
6
|
+
|
|
7
|
+
* **@visulima/nextra-theme-docs:** upgraded to 4.0.10
|
|
8
|
+
|
|
9
|
+
## @visulima/error [1.1.0](https://github.com/visulima/visulima/compare/@visulima/error@1.0.2...@visulima/error@1.1.0) (2023-11-30)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* added a stacktrace parser and a sourcemap loader ([#250](https://github.com/visulima/visulima/issues/250)) ([4543e44](https://github.com/visulima/visulima/commit/4543e44becc85a54cdbe7701e2c3e6601b282985))
|
|
15
|
+
|
|
1
16
|
## @visulima/error [1.0.2](https://github.com/visulima/visulima/compare/@visulima/error@1.0.1...@visulima/error@1.0.2) (2023-11-30)
|
|
2
17
|
|
|
3
18
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<h3>Visulima error</h3>
|
|
3
3
|
<p>
|
|
4
|
-
Error with more than just a message.
|
|
4
|
+
Error with more than just a message, stacktrace parsing and sourcemap loading.
|
|
5
5
|
</p>
|
|
6
6
|
</div>
|
|
7
7
|
|
|
@@ -82,6 +82,65 @@ console.log(frame);
|
|
|
82
82
|
// | ^
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
+
## Stacktrace
|
|
86
|
+
|
|
87
|
+
> Browser older than 6 years are not supported.
|
|
88
|
+
|
|
89
|
+
Currently supported browsers/platforms:
|
|
90
|
+
|
|
91
|
+
- Firefox
|
|
92
|
+
- Chrome
|
|
93
|
+
- Webkit / Safari
|
|
94
|
+
- Edge
|
|
95
|
+
- Node / Node V8
|
|
96
|
+
- Opera (Chromium based)
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { parseStack } from "@visulima/error";
|
|
100
|
+
|
|
101
|
+
const error = new Error("My error message");
|
|
102
|
+
|
|
103
|
+
const stack = parseStack(error);
|
|
104
|
+
|
|
105
|
+
console.log(stack);
|
|
106
|
+
|
|
107
|
+
// [
|
|
108
|
+
// {
|
|
109
|
+
// column: 16,
|
|
110
|
+
// file: "file:///Users/danielbannert/Projects/visulima/packages/error/src/index.ts",
|
|
111
|
+
// line: 2,
|
|
112
|
+
// methodName: "Object.<anonymous>",
|
|
113
|
+
// raw: " at Object.<anonymous> (/visulima/packages/error/src/index.ts:2:16)",
|
|
114
|
+
// type: undefined, // optional property, can be undefined, "eval", "native", or "internal"
|
|
115
|
+
// evalOrigin: undefined, // optional property only available if the stacktrace contains eval
|
|
116
|
+
// },
|
|
117
|
+
// ...and so on
|
|
118
|
+
// ];
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Source Map
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { loadSourceMap, originalPositionFor, sourceContentFor } from "@visulima/error";
|
|
125
|
+
|
|
126
|
+
const sourceMap = loadSourceMap("your_path/src/index.js"); // returns a TraceMap
|
|
127
|
+
|
|
128
|
+
const traced = originalPositionFor(sourceMap, { column: 13, line: 30 });
|
|
129
|
+
|
|
130
|
+
console.log(traced);
|
|
131
|
+
|
|
132
|
+
// {
|
|
133
|
+
// column: 9,
|
|
134
|
+
// line: 15,
|
|
135
|
+
// name: "setState",
|
|
136
|
+
// source: "your_path/src/index.js"
|
|
137
|
+
// }
|
|
138
|
+
|
|
139
|
+
console.log(sourceContentFor(sourceMap, traced.source)); // 'content for your_path/src/index.js'
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
For more information about the TraceMap see [@jridgewell/trace-mapping](https://github.com/jridgewell/trace-mapping)
|
|
143
|
+
|
|
85
144
|
## Supported Node.js Versions
|
|
86
145
|
|
|
87
146
|
Libraries in this ecosystem make the best effort to track [Node.js’ release schedule](https://github.com/nodejs/release#release-schedule).
|
|
@@ -98,6 +157,26 @@ If you would like to help take a look at the [list of issues](https://github.com
|
|
|
98
157
|
- [Daniel Bannert](https://github.com/prisis)
|
|
99
158
|
- [All Contributors](https://github.com/visulima/visulima/graphs/contributors)
|
|
100
159
|
|
|
160
|
+
## About
|
|
161
|
+
|
|
162
|
+
### Related Projects
|
|
163
|
+
|
|
164
|
+
- [baseerr](https://github.com/tjmehta/baseerr): merge another error with additional properties.
|
|
165
|
+
- [callsite-record](https://github.com/inikulin/callsite-record): create a fancy log entries for errors and function call sites.
|
|
166
|
+
- [callsites](https://github.com/sindresorhus/callsites): get callsites from the V8 stack trace API.
|
|
167
|
+
- [explain-error](https://github.com/dominictarr/explain-error): wrap an error with additional explanation.
|
|
168
|
+
- [error-wrapper](https://github.com/spudly/error-wrapper): merges the stack of another error to its own.
|
|
169
|
+
- [errwischt/stacktrace-parser](https://github.com/errwischt/stacktrace-parser)
|
|
170
|
+
- [trace](https://github.com/AndreasMadsen/trace): create super long stack traces.
|
|
171
|
+
- [clarify](https://github.com/AndreasMadsen/clarify): remove node related stack trace noise.
|
|
172
|
+
- [piotr-szewczyk/stacktrace-parser-node](https://github.com/piotr-szewczyk/stacktrace-parser-node)
|
|
173
|
+
- [pretty-error](https://github.com/AriaMinaei/pretty-error): make the call stacks clear.
|
|
174
|
+
- [ono](https://github.com/bigstickcarpet/ono): allow different types of error to be thrown.
|
|
175
|
+
- [ololog](https://github.com/xpl/ololog): another logger with a similar motivation but only support console.log as its sole transport.
|
|
176
|
+
- [stacktracejs/error-stack-parser](https://github.com/stacktracejs/error-stack-parser)
|
|
177
|
+
- [marvinhagemeister/errorstacks](https://github.com/marvinhagemeister/errorstacks) Tiny library to parse error stack traces
|
|
178
|
+
- [getsentry/sentry-javascript](https://github.com/getsentry/sentry-javascript)
|
|
179
|
+
|
|
101
180
|
## License
|
|
102
181
|
|
|
103
182
|
The visulima error is open-sourced software licensed under the [MIT][license-url]
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
var o=(s,...e)=>{process.env.DEBUG&&String(process.env.DEBUG)==="true"&&console.debug(`error:parse-stacktrace: ${s}`,...e);},f="<unknown>",y=/^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,v=/\((\S+)\),\s(<[^>]+>)?:(\d+)?:(\d+)?\)?/,T=/(.*?):(\d+):(\d+)(\s<-\s(.+):(\d+):(\d+))?/,$=/^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/,N=/in\s(.*)\s\(at\s(.+)\)\sat/,x=/^(?:.*@)?(.*):(\d+):(\d+)$/,b=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. \/=]+)(?::(\d+))?(?::(\d+))?\s*$/i,O=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,R=/(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/,l=/\(error: (.*)\)/,p=(s,e)=>{let n=s.includes("safari-extension"),t=s.includes("safari-web-extension");return n||t?[s.includes("@")?s.split("@")[0]:f,n?`safari-extension:${e}`:`safari-web-extension:${e}`]:[s,e]},m=(s,e)=>{let n=T.exec(e);n&&(s.file=n[1],s.line=+n[2],s.column=+n[3]);},S=s=>{let e=N.exec(s);if(e){o(`parse nested node error stack line: "${s}"`,`found: ${JSON.stringify(e)}`);let t=e[2].split(":");return {column:t[2]?+t[2]:void 0,file:t[0],line:t[1]?+t[1]:void 0,methodName:e[1]||f,raw:s,type:void 0}}let n=$.exec(s);if(n){o(`parse node error stack line: "${s}"`,`found: ${JSON.stringify(n)}`);let t={column:n[4]?+n[4]:void 0,file:n[2]?n[2].replace(/at\s/,""):void 0,line:n[3]?+n[3]:void 0,methodName:n[1]||f,raw:s,type:s.startsWith("internal")?"internal":void 0};return m(t,`${n[2]}:${n[3]}:${n[4]}`),t}},_=s=>{let e=y.exec(s);if(e){o(`parse chrome error stack line: "${s}"`,`found: ${JSON.stringify(e)}`);let n=e[2]&&e[2].startsWith("native"),t=e[2]&&e[2].startsWith("eval")||e[1]&&e[1].startsWith("eval"),r;if(t){let i=v.exec(s);if(i){let c=/(\S+):(\d+):(\d+)|(\S+):(\d+)$/.exec(i[1]);c?(e[2]=c[4]??c[1],e[3]=c[5]??c[2],e[4]=c[3]):i[2]&&(e[2]=i[1]),i[2]&&(r={column:i[4]?+i[4]:void 0,file:i[2],line:i[3]?+i[3]:void 0,methodName:"eval",raw:s,type:"eval"});}}let[a,u]=p(e[1]?e[1].replace(/^Anonymous function$/,"<anonymous>"):f,e[2]),d={column:e[4]?+e[4]:void 0,evalOrigin:r,file:u,line:e[3]?+e[3]:void 0,methodName:a,raw:s,type:t?"eval":n?"native":void 0};return m(d,`${u}:${e[3]}:${e[4]}`),d}},h=(s,e)=>{let n=b.exec(s);if(n){o(`parse gecko error stack line: "${s}"`,`found: ${JSON.stringify(n)}`);let t=n[3]?.includes(" > eval"),r=t&&n[3]&&O.exec(n[3]),a;t&&r&&(n[3]=r[1],a={column:n[5]?+n[5]:void 0,file:n[3],line:n[4]?+n[4]:void 0,methodName:"eval",raw:s,type:"eval"},n[4]=r[2]);let[u,d]=p(n[1]?n[1].replace(/^Anonymous function$/,"<anonymous>"):f,n[3]),i;(e?.type==="safari"||!t&&e?.type==="firefox")&&e.column?i=e.column:!t&&n[5]&&(i=+n[5]);let c;return (e?.type==="safari"||!t&&e?.type==="firefox")&&e.line?c=e.line:n[4]&&(c=+n[4]),{column:i,evalOrigin:a,file:d,line:c,methodName:u,raw:s,type:t?"eval":d.includes("[native code]")?"native":void 0}}},G=(s,e)=>{let n=R.exec(s);if(!(n?n[2].includes(" > eval"):!1)&&n)return o(`parse firefox error stack line: "${s}"`,`found: ${JSON.stringify(n)}`),{column:n[4]?+n[4]:e?.column??void 0,file:n[2],line:n[3]?+n[3]:e?.line??void 0,methodName:n[1]||f,raw:s,type:void 0}},w=s=>{let e=x.exec(s);if(e)return o(`parse react android native error stack line: "${s}"`,`found: ${JSON.stringify(e)}`),{column:e[3]?+e[3]:void 0,file:e[1],line:e[2]?+e[2]:void 0,methodName:f,raw:s,type:void 0}},k=(s,e={})=>{let{frameLimit:n=50}=e,t=(s.stacktrace??s.stack??"").split(`
|
|
2
|
+
`).map(r=>(l.test(r)?r.replace(l,"$1"):r).replace(/^\s+|\s+$/g,"")).filter(r=>!/\S*Error: /.test(r)&&r!=="eval code");return t.length>n&&(t=t.slice(0,n)),t.reduce((r,a,u)=>{if(!a||a.length>1024)return r;let d;if(/^\s*in\s.*/.test(a))d=S(a);else if(/^.*?\s*at\s.*/.test(a))d=_(a);else if(/^.*?\s*@.*|\[native code\]/.test(a)){let i;u===0&&(s.columnNumber||s.lineNumber?i={column:s.columnNumber,line:s.lineNumber,type:"firefox"}:(s.line||s.column)&&(i={column:s.column,line:s.line,type:"safari"})),d=G(a,i)||h(a,i);}else d=w(a);return d?r.push(d):o(`parse error stack line: "${a}"`,"not parser found"),r},[])},A=k;
|
|
3
|
+
|
|
4
|
+
export { A as a };
|
|
5
|
+
//# sourceMappingURL=out.js.map
|
|
6
|
+
//# sourceMappingURL=chunk-26F4MLO2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/parse-stacktrace.ts"],"names":["debugLog","message","arguments_","UNKNOWN_FUNCTION","CHROMIUM_REGEX","CHROMIUM_EVAL_REGEX","CHROMIUM_MAPPED","NODE_REGEX","NODE_NESTED_REGEX","REACT_ANDROID_NATIVE_REGEX","GECKO_REGEX","GECKO_EVAL_REGEX","FIREFOX_REGEX","WEBPACK_ERROR_REGEXP","extractSafariExtensionDetails","methodName","url","isSafariExtension","isSafariWebExtension","parseMapped","trace","maybeMapped","match","parseNode","line","nestedNode","split","node","parseChromium","parts","isNative","isEval","evalOrigin","subMatch","file","parseGecko","topFrameMeta","column","lineNumber","parseFirefox","parseReactAndroidNative","parse","error","options","frameLimit","lines","stack","currentIndex","parseResult","parse_stacktrace_default"],"mappings":"AAQA,IAAMA,EAAW,CAACC,KAAoBC,IAAgC,CAC9D,QAAQ,IAAI,OAAY,OAAO,QAAQ,IAAI,KAAQ,IAAM,QAEzD,QAAQ,MAAM,2BAA2BD,CAAO,GAAI,GAAGC,CAAU,CAEzE,EAEMC,EAAmB,YAsBnBC,EAEF,yJAEEC,EAAsB,0CAItBC,EAAkB,6CAIlBC,EAAa,qFACbC,EAAoB,6BAGpBC,EAA6B,6BAM7BC,EAAc,wIAEdC,EAAmB,gDAMnBC,EAAgB,yCAGhBC,EAAuB,kBAsBvBC,EAAgC,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AAQ,CAACC,EAAcC,EAA2C,CAAC,IAAe,CACpF,GAAM,CAAE,WAAAC,EAAa,EAAG,EAAID,EAGxBE,GAASH,EAAM,YAAcA,EAAM,OAAS,IAC3C,MAAM;AAAA,CAAI,EACV,IAAKlB,IAGkBX,EAAqB,KAAKW,CAAI,EAAIA,EAAK,QAAQX,EAAsB,IAAI,EAAIW,GAG9E,QAAQ,aAAc,EAAE,CAC9C,EAIA,OAAQA,GAA0B,CAAC,aAAa,KAAKA,CAAI,GAAKA,IAAS,WAAW,EAEvF,OAAIqB,EAAM,OAASD,IACfC,EAAQA,EAAM,MAAM,EAAGD,CAAU,GAI9BC,EAAM,OAAO,CAACC,EAAgBtB,EAAcuB,IAAkC,CASjF,GARI,CAACvB,GAQDA,EAAK,OAAS,KACd,OAAOsB,EAGX,IAAIE,EAEJ,GAAI,aAAa,KAAKxB,CAAI,EACtBwB,EAAczB,EAAUC,CAAI,UAErB,gBAAgB,KAAKA,CAAI,EAChCwB,EAAcpB,EAAcJ,CAAI,UAEzB,6BAA6B,KAAKA,CAAI,EAAG,CAChD,IAAIY,EAEAW,IAAiB,IAEbL,EAAM,cAAgBA,EAAM,WAC5BN,EAAe,CAEX,OAAQM,EAAM,aAEd,KAAMA,EAAM,WACZ,KAAM,SACV,GAEOA,EAAM,MAAQA,EAAM,UAC3BN,EAAe,CAEX,OAAQM,EAAM,OAEd,KAAMA,EAAM,KACZ,KAAM,QACV,IAIRM,EAEIT,EAAaf,EAAMY,CAAY,GAAKD,EAAWX,EAAMY,CAAY,CACzE,MACIY,EAAcR,EAAwBhB,CAAI,EAG9C,OAAIwB,EACAF,EAAM,KAAKE,CAAW,EAEtBhD,EAAS,4BAA4BwB,CAAI,IAAK,kBAAkB,EAG7DsB,CACX,EAAG,CAAC,CAAC,CACT,EAEOG,EAAQR","sourcesContent":["import type { Trace, TraceType } from \"./types\";\n\ntype TopFrameMeta = {\n column?: number;\n line?: number;\n type: \"firefox\" | \"safari\";\n};\n\nconst debugLog = (message: string, ...arguments_: unknown[]): void => {\n if (process.env[\"DEBUG\"] && String(process.env[\"DEBUG\"]) === \"true\") {\n // eslint-disable-next-line no-console\n console.debug(`error:parse-stacktrace: ${message}`, ...arguments_);\n }\n};\n\nconst UNKNOWN_FUNCTION = \"<unknown>\";\n\n// at <SomeFramework>\n// at <SomeFramework>:123:39\n// -----------------\n// at about:blank:1:7\n// at index.js:23\n// >= Chrome 99\n// at /projects/foo.test.js:689:1 <- /projects/foo.test.js:10:1\n// -----------------\n// at bar (<anonymous>:1:19 <- <anonymous>:2:3)\n// -----------------\n// at foo.bar(bob) (foo.bar.js:123:39)\n// at foo.bar(bob) (foo.bar.js:123:39 <- original.js:123:34)\n// -----------------\n// >= Chrome 88\n// spy() at Component.Foo [as constructor] (original.js:123:34)\n// spy() at Component.Foo [as constructor] (foo.bar.js:123:39 <- original.js:123:34)\n// -----------------\n// at Module.load (internal/modules/cjs/loader.js:641:32)\n// -----------------\n// Chromium based browsers: Chrome, Brave, new Opera, new Edge\nconst CHROMIUM_REGEX =\n // eslint-disable-next-line security/detect-unsafe-regex,regexp/no-super-linear-backtracking\n /^.*?\\s*at\\s(?:(.+?\\)(?:\\s\\[.+\\])?|\\(?.*?)\\s?\\((?:address\\sat\\s)?)?(?:async\\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\\/)?.*?)(?::(\\d+))?(?::(\\d+))?\\)?\\s*$/i;\n// eslint-disable-next-line security/detect-unsafe-regex\nconst CHROMIUM_EVAL_REGEX = /\\((\\S+)\\),\\s(<[^>]+>)?:(\\d+)?:(\\d+)?\\)?/;\n// foo.bar.js:123:39\n// foo.bar.js:123:39 <- original.js:123:34\n// eslint-disable-next-line security/detect-unsafe-regex,regexp/no-unused-capturing-group\nconst CHROMIUM_MAPPED = /(.*?):(\\d+):(\\d+)(\\s<-\\s(.+):(\\d+):(\\d+))?/;\n\n// in AppProviders (at App.tsx:28)\n// eslint-disable-next-line security/detect-unsafe-regex\nconst NODE_REGEX = /^\\s*in\\s(?:([^\\\\/]+(?:\\s\\[as\\s\\S+\\])?)\\s\\(?)?\\(at?\\s?(.*?):(\\d+)(?::(\\d+))?\\)?\\s*$/;\nconst NODE_NESTED_REGEX = /in\\s(.*)\\s\\(at\\s(.+)\\)\\sat/;\n\n// eslint-disable-next-line security/detect-unsafe-regex,regexp/no-super-linear-backtracking\nconst REACT_ANDROID_NATIVE_REGEX = /^(?:.*@)?(.*):(\\d+):(\\d+)$/;\n\n// gecko regex: `(?:bundle|\\d+\\.js)`: `bundle` is for react native, `\\d+\\.js` also but specifically for ram bundles because it\n// generates filenames without a prefix like `file://` the filenames in the stacktrace are just 42.js\n// We need this specific case for now because we want no other regex to match.\n// eslint-disable-next-line regexp/no-super-linear-backtracking,security/detect-unsafe-regex,regexp/no-optional-assertion,regexp/no-trivially-nested-quantifier,regexp/no-useless-escape,no-useless-escape,regexp/optimal-quantifier-concatenation\nconst GECKO_REGEX = /^\\s*(.*?)(?:\\((.*?)\\))?(?:^|@)?((?:[-a-z]+)?:\\/.*?|\\[native code\\]|[^@]*(?:bundle|\\d+\\.js)|\\/[\\w\\-. \\/=]+)(?::(\\d+))?(?::(\\d+))?\\s*$/i;\n// eslint-disable-next-line security/detect-unsafe-regex\nconst GECKO_EVAL_REGEX = /(\\S+) line (\\d+)(?: > eval line \\d+)* > eval/i;\n\n// @http://localhost:8080/file.js:33:9\n// foo@debugger eval code:1:27\n// obj[\"@fn\"]@Scratchpad/1:10:29\n// eslint-disable-next-line regexp/no-super-linear-backtracking\nconst FIREFOX_REGEX = /(\\S[^\\s[]*\\[.*\\]|.*?)@(.*):(\\d+):(\\d+)/;\n\n// Used to sanitize webpack (error: *) wrapped stack errors\nconst WEBPACK_ERROR_REGEXP = /\\(error: (.*)\\)/;\n\n/**\n * Safari web extensions, starting version unknown, can produce \"frames-only\" stacktraces.\n * What it means, is that instead of format like:\n *\n * Error: wat\n * at function@url:row:col\n * at function@url:row:col\n * at function@url:row:col\n *\n * it produces something like:\n *\n * function@url:row:col\n * function@url:row:col\n * function@url:row:col\n *\n * Because of that, it won't be captured by `chrome` RegExp and will fall into `Gecko` branch.\n * This function is extracted so that we can use it in both places without duplicating the logic.\n * Unfortunately \"just\" changing RegExp is too complicated now and making it pass all tests\n * and fix this case seems like an impossible, or at least way too time-consuming task.\n */\nconst extractSafariExtensionDetails = (methodName: string, url: string): [string, string] => {\n const isSafariExtension = methodName.includes(\"safari-extension\");\n const isSafariWebExtension = methodName.includes(\"safari-web-extension\");\n\n return isSafariExtension || isSafariWebExtension\n ? [\n methodName.includes(\"@\") ? (methodName.split(\"@\")[0] as string) : UNKNOWN_FUNCTION,\n isSafariExtension ? `safari-extension:${url}` : `safari-web-extension:${url}`,\n ]\n : [methodName, url];\n};\n\nconst parseMapped = (trace: Trace, maybeMapped: string) => {\n const match = CHROMIUM_MAPPED.exec(maybeMapped);\n\n if (match) {\n // eslint-disable-next-line no-param-reassign,prefer-destructuring\n trace.file = match[1];\n // eslint-disable-next-line no-param-reassign\n trace.line = +(<string>match[2]);\n // eslint-disable-next-line no-param-reassign\n trace.column = +(<string>match[3]);\n }\n};\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst parseNode = (line: string): Trace | undefined => {\n const nestedNode = NODE_NESTED_REGEX.exec(line);\n\n if (nestedNode) {\n debugLog(`parse nested node error stack line: \"${line}\"`, `found: ${JSON.stringify(nestedNode)}`);\n\n const split = (nestedNode[2] as string).split(\":\");\n\n return {\n column: split[2] ? +split[2] : undefined,\n file: split[0],\n line: split[1] ? +split[1] : undefined,\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n methodName: nestedNode[1] || UNKNOWN_FUNCTION,\n raw: line,\n type: undefined,\n };\n }\n\n const node = NODE_REGEX.exec(line);\n\n if (node) {\n debugLog(`parse node error stack line: \"${line}\"`, `found: ${JSON.stringify(node)}`);\n\n const trace = {\n column: node[4] ? +node[4] : undefined,\n file: node[2] ? node[2].replace(/at\\s/, \"\") : undefined,\n line: node[3] ? +node[3] : undefined,\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n methodName: node[1] || UNKNOWN_FUNCTION,\n raw: line,\n type: line.startsWith(\"internal\") ? (\"internal\" as TraceType) : undefined,\n };\n\n parseMapped(trace, `${node[2]}:${node[3]}:${node[4]}`);\n\n return trace;\n }\n\n return undefined;\n};\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst parseChromium = (line: string): Trace | undefined => {\n const parts = CHROMIUM_REGEX.exec(line) as (string | undefined)[] | null;\n\n if (parts) {\n debugLog(`parse chrome error stack line: \"${line}\"`, `found: ${JSON.stringify(parts)}`);\n\n const isNative = parts[2] && parts[2].startsWith(\"native\"); // start of line\n const isEval = (parts[2] && parts[2].startsWith(\"eval\")) || (parts[1] && parts[1].startsWith(\"eval\")); // start of line\n\n let evalOrigin: Trace | undefined;\n\n if (isEval) {\n const subMatch = CHROMIUM_EVAL_REGEX.exec(line);\n\n if (subMatch) {\n // can be index.js:123:39 or index.js:123 or index.js\n const split = /(\\S+):(\\d+):(\\d+)|(\\S+):(\\d+)$/.exec(subMatch[1] as string);\n\n if (split) {\n // throw out eval line/column and use top-most line/column number\n parts[2] = split[4] ?? split[1]; // url\n parts[3] = split[5] ?? split[2]; // line\n // eslint-disable-next-line prefer-destructuring\n parts[4] = split[3]; // column\n } else if (subMatch[2]) {\n // eslint-disable-next-line prefer-destructuring\n parts[2] = subMatch[1];\n }\n\n if (subMatch[2]) {\n evalOrigin = {\n column: subMatch[4] ? +subMatch[4] : undefined,\n file: subMatch[2],\n line: subMatch[3] ? +subMatch[3] : undefined,\n methodName: \"eval\",\n raw: line,\n type: \"eval\" as TraceType,\n };\n }\n }\n }\n\n const [methodName, file] = extractSafariExtensionDetails(\n // Normalize IE's 'Anonymous function'\n parts[1] ? parts[1].replace(/^Anonymous function$/, \"<anonymous>\") : UNKNOWN_FUNCTION,\n parts[2] as string,\n );\n\n const trace = {\n column: parts[4] ? +parts[4] : undefined,\n evalOrigin,\n file,\n line: parts[3] ? +parts[3] : undefined,\n // Normalize IE's 'Anonymous function'\n methodName,\n raw: line,\n type: (isEval ? \"eval\" : isNative ? \"native\" : undefined) as TraceType,\n };\n\n parseMapped(trace, `${file}:${parts[3]}:${parts[4]}`);\n\n return trace;\n }\n\n return undefined;\n};\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst parseGecko = (line: string, topFrameMeta?: TopFrameMeta): Trace | undefined => {\n const parts = GECKO_REGEX.exec(line);\n\n if (parts) {\n debugLog(`parse gecko error stack line: \"${line}\"`, `found: ${JSON.stringify(parts)}`);\n\n const isEval = parts[3]?.includes(\" > eval\");\n const subMatch = isEval && parts[3] && GECKO_EVAL_REGEX.exec(parts[3]);\n\n let evalOrigin: Trace | undefined;\n\n if (isEval && subMatch) {\n // overwrite file\n parts[3] = <string>subMatch[1];\n\n evalOrigin = {\n column: parts[5] ? +parts[5] : undefined,\n file: parts[3],\n line: parts[4] ? +parts[4] : undefined,\n methodName: \"eval\",\n raw: line,\n type: \"eval\" as TraceType,\n };\n\n // overwrite line\n parts[4] = <string>subMatch[2];\n }\n\n const [methodName, file] = extractSafariExtensionDetails(\n // Normalize IE's 'Anonymous function'\n parts[1] ? parts[1].replace(/^Anonymous function$/, \"<anonymous>\") : UNKNOWN_FUNCTION,\n parts[3] as string,\n );\n\n let column: number | undefined; // no column when eval\n\n if ((topFrameMeta?.type === \"safari\" || (!isEval && topFrameMeta?.type === \"firefox\")) && topFrameMeta.column) {\n column = topFrameMeta.column;\n } else if (!isEval && parts[5]) {\n column = +parts[5];\n }\n\n let lineNumber: number | undefined; // no line when eval\n\n if ((topFrameMeta?.type === \"safari\" || (!isEval && topFrameMeta?.type === \"firefox\")) && topFrameMeta.line) {\n lineNumber = topFrameMeta.line;\n } else if (parts[4]) {\n lineNumber = +parts[4];\n }\n\n return {\n column,\n evalOrigin,\n file,\n line: lineNumber,\n methodName,\n raw: line,\n type: isEval ? \"eval\" : file.includes(\"[native code]\") ? \"native\" : undefined,\n };\n }\n\n return undefined;\n};\n\nconst parseFirefox = (line: string, topFrameMeta?: TopFrameMeta): Trace | undefined => {\n const parts = FIREFOX_REGEX.exec(line);\n\n const isEval = parts ? (parts[2] as string).includes(\" > eval\") : false;\n\n if (!isEval && parts) {\n debugLog(`parse firefox error stack line: \"${line}\"`, `found: ${JSON.stringify(parts)}`);\n\n return {\n column: parts[4] ? +parts[4] : topFrameMeta?.column ?? undefined,\n file: parts[2],\n line: parts[3] ? +parts[3] : topFrameMeta?.line ?? undefined,\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n methodName: parts[1] || UNKNOWN_FUNCTION,\n raw: line,\n type: undefined,\n };\n }\n\n return undefined;\n};\n\nconst parseReactAndroidNative = (line: string): Trace | undefined => {\n const parts = REACT_ANDROID_NATIVE_REGEX.exec(line);\n\n if (parts) {\n debugLog(`parse react android native error stack line: \"${line}\"`, `found: ${JSON.stringify(parts)}`);\n\n return {\n column: parts[3] ? +parts[3] : undefined,\n file: parts[1],\n line: parts[2] ? +parts[2] : undefined,\n methodName: UNKNOWN_FUNCTION,\n raw: line,\n type: undefined,\n };\n }\n\n return undefined;\n};\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nconst parse = (error: Error, options: Partial<{ frameLimit: number }> = {}): Trace[] => {\n const { frameLimit = 50 } = options;\n\n // @ts-expect-error missing stacktrace property\n let lines = (error.stacktrace ?? error.stack ?? \"\")\n .split(\"\\n\")\n .map((line: string): string => {\n // https://github.com/getsentry/sentry-javascript/issues/5459\n // Remove webpack (error: *) wrappers\n const cleanedLine = WEBPACK_ERROR_REGEXP.test(line) ? line.replace(WEBPACK_ERROR_REGEXP, \"$1\") : line;\n\n // eslint-disable-next-line unicorn/prefer-string-replace-all\n return cleanedLine.replace(/^\\s+|\\s+$/g, \"\");\n })\n // https://github.com/getsentry/sentry-javascript/issues/7813\n // Skip Error: lines\n // Skip eval code without more context\n .filter((line: string): boolean => !/\\S*Error: /.test(line) && line !== \"eval code\");\n\n if (lines.length > frameLimit) {\n lines = lines.slice(0, frameLimit);\n }\n\n // eslint-disable-next-line unicorn/no-array-reduce,@typescript-eslint/no-unsafe-return\n return lines.reduce((stack: Trace[], line: string, currentIndex: number): Trace[] => {\n if (!line) {\n return stack;\n }\n\n // Ignore lines over 1kb as they are unlikely to be stack frames.\n // Many of the regular expressions use backtracking which results in run time that increases exponentially with\n // input size. Huge strings can result in hangs/Denial of Service:\n // https://github.com/getsentry/sentry-javascript/issues/2286\n if (line.length > 1024) {\n return stack;\n }\n\n let parseResult: Trace | undefined;\n\n if (/^\\s*in\\s.*/.test(line)) {\n parseResult = parseNode(line);\n // eslint-disable-next-line regexp/no-super-linear-backtracking\n } else if (/^.*?\\s*at\\s.*/.test(line)) {\n parseResult = parseChromium(line);\n // eslint-disable-next-line regexp/no-super-linear-backtracking\n } else if (/^.*?\\s*@.*|\\[native code\\]/.test(line)) {\n let topFrameMeta: TopFrameMeta | undefined;\n\n if (currentIndex === 0) {\n // @ts-expect-error columnNumber and lineNumber property only exists on Firefox\n if (error.columnNumber || error.lineNumber) {\n topFrameMeta = {\n // @ts-expect-error columnNumber and columnNumber property only exists on Firefox\n column: error.columnNumber,\n // @ts-expect-error columnNumber and lineNumber property only exists on Firefox\n line: error.lineNumber,\n type: \"firefox\",\n };\n // @ts-expect-error line and column property only exists on safari\n } else if (error.line || error.column) {\n topFrameMeta = {\n // @ts-expect-error column property only exists on safari\n column: error.column,\n // @ts-expect-error line property only exists on safari\n line: error.line,\n type: \"safari\",\n };\n }\n }\n\n parseResult =\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n parseFirefox(line, topFrameMeta) || parseGecko(line, topFrameMeta);\n } else {\n parseResult = parseReactAndroidNative(line);\n }\n\n if (parseResult) {\n stack.push(parseResult);\n } else {\n debugLog(`parse error stack line: \"${line}\"`, \"not parser found\");\n }\n\n return stack;\n }, []);\n};\n\nexport default parse;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { dirname, resolve } from 'path';
|
|
3
|
+
import { AnyMap } from '@jridgewell/trace-mapping';
|
|
4
|
+
export { generatedPositionFor as b, originalPositionFor as c, sourceContentFor as d, traceSegment as e } from '@jridgewell/trace-mapping';
|
|
5
|
+
|
|
6
|
+
var l=/^data:application\/json[^,]+base64,/,u=/\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+)[ \t]*$|\/\*[@#][ \t]+sourceMappingURL=([^*]+?)[ \t]*\*\/[ \t]*$/,a=e=>l.test(e),f=(e,o)=>{let t=e.split(/\r?\n/),n=null;for(let r=t.length-1;r>=0&&!n;r--)n=u.exec(t[r]);if(n)return a(n[1])?n[1]:resolve(o,n[1])},m=e=>{let o=e.slice(e.indexOf(",")+1);return Buffer.from(o,"base64").toString()},M=e=>{let o;try{o=readFileSync(e,{encoding:"utf8"});}catch(r){throw r.message=`Error reading sourcemap for file "${e}":
|
|
7
|
+
${r.message}`,r}let t=f(o,dirname(e));if(!t)return;let n;if(a(t))n=m(t);else try{n=readFileSync(t,{encoding:"utf8"});}catch(r){throw r.message=`Error reading sourcemap for file "${e}":
|
|
8
|
+
${r.message}`,r}try{return new AnyMap(n,t)}catch(r){throw r.message=`Error parsing sourcemap for file "${e}":
|
|
9
|
+
${r.message}`,r}},y=M;
|
|
10
|
+
|
|
11
|
+
export { y as a };
|
|
12
|
+
//# sourceMappingURL=out.js.map
|
|
13
|
+
//# sourceMappingURL=chunk-F52HEHA7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/load-source-map.ts","../src/sourcemap.ts"],"names":["readFileSync","dirname","resolve","AnyMap","INLINE_SOURCEMAP_REGEX","SOURCEMAP_REGEX","isInlineMap","url","resolveSourceMapUrl","sourceFile","sourcePath","lines","sourceMapUrl","index","decodeInlineMap","data","rawData","loadSourceMap","filename","sourceMapContent","error","traceMapContent","load_source_map_default","generatedPositionFor","originalPositionFor","sourceContentFor","traceSegment"],"mappings":"AAAA,OAAS,gBAAAA,MAAoB,KAC7B,OAAS,WAAAC,EAAS,WAAAC,MAAe,OAGjC,OAAS,UAAAC,MAAc,4BAEvB,IAAMC,EAAyB,sCAEzBC,EAAkB,4GAElBC,EAAeC,GAAyBH,EAAuB,KAAKG,CAAG,EAEvEC,EAAsB,CAACC,EAAoBC,IAA2C,CACxF,IAAMC,EAAQF,EAAW,MAAM,OAAO,EAElCG,EAAe,KAGnB,QAASC,EAAQF,EAAM,OAAS,EAAGE,GAAS,GAAK,CAACD,EAAcC,IAE5DD,EAAeP,EAAgB,KAAKM,EAAME,CAAK,CAAW,EAG9D,GAAKD,EAIL,OAAON,EAAYM,EAAa,CAAC,CAAW,EAAKA,EAAa,CAAC,EAAgBV,EAAQQ,EAAYE,EAAa,CAAC,CAAW,CAChI,EAEME,EAAmBC,GAAiB,CACtC,IAAMC,EAAUD,EAAK,MAAMA,EAAK,QAAQ,GAAG,EAAI,CAAC,EAEhD,OAAO,OAAO,KAAKC,EAAS,QAAQ,EAAE,SAAS,CACnD,EAEMC,EAAiBC,GAA2C,CAC9D,IAAIC,EAEJ,GAAI,CAEAA,EAAmBnB,EAAakB,EAAU,CAAE,SAAU,MAAO,CAAC,CAElE,OAASE,EAAY,CACjB,MAAAA,EAAM,QAAU,qCAAqCF,CAAQ;AAAA,EAAOE,EAAM,OAAO,GAE3EA,CACV,CAEA,IAAMR,EAAeJ,EAAoBW,EAAkBlB,EAAQiB,CAAQ,CAAC,EAE5E,GAAI,CAACN,EACD,OAGJ,IAAIS,EAGJ,GAAIf,EAAYM,CAAY,EACxBS,EAAkBP,EAAgBF,CAAY,MAE9C,IAAI,CAGAS,EAAkBrB,EAAaY,EAAc,CAAE,SAAU,MAAO,CAAC,CAErE,OAASQ,EAAY,CACjB,MAAAA,EAAM,QAAU,qCAAqCF,CAAQ;AAAA,EAAOE,EAAM,OAAO,GAE3EA,CACV,CAGJ,GAAI,CACA,OAAO,IAAIjB,EAAOkB,EAAiBT,CAAY,CAEnD,OAASQ,EAAY,CACjB,MAAAA,EAAM,QAAU,qCAAqCF,CAAQ;AAAA,EAAOE,EAAM,OAAO,GAE3EA,CACV,CACJ,EAEOE,EAAQL,ECjFf,OAAS,wBAAAM,EAAsB,uBAAAC,EAAqB,oBAAAC,EAAkB,gBAAAC,MAAoB","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\n\nimport type { TraceMap } from \"@jridgewell/trace-mapping\";\nimport { AnyMap } from \"@jridgewell/trace-mapping\";\n\nconst INLINE_SOURCEMAP_REGEX = /^data:application\\/json[^,]+base64,/;\n// eslint-disable-next-line regexp/no-unused-capturing-group,regexp/no-super-linear-backtracking\nconst SOURCEMAP_REGEX = /\\/\\/[@#][ \\t]+sourceMappingURL=([^\\s'\"]+)[ \\t]*$|\\/\\*[@#][ \\t]+sourceMappingURL=([^*]+?)[ \\t]*\\*\\/[ \\t]*$/;\n\nconst isInlineMap = (url: string): boolean => INLINE_SOURCEMAP_REGEX.test(url);\n\nconst resolveSourceMapUrl = (sourceFile: string, sourcePath: string): string | undefined => {\n const lines = sourceFile.split(/\\r?\\n/);\n\n let sourceMapUrl = null;\n\n // eslint-disable-next-line no-loops/no-loops,no-plusplus\n for (let index = lines.length - 1; index >= 0 && !sourceMapUrl; index--) {\n // eslint-disable-next-line security/detect-object-injection\n sourceMapUrl = SOURCEMAP_REGEX.exec(lines[index] as string);\n }\n\n if (!sourceMapUrl) {\n return undefined;\n }\n\n return isInlineMap(sourceMapUrl[1] as string) ? (sourceMapUrl[1] as string) : (resolve(sourcePath, sourceMapUrl[1] as string) as string);\n};\n\nconst decodeInlineMap = (data: string) => {\n const rawData = data.slice(data.indexOf(\",\") + 1);\n\n return Buffer.from(rawData, \"base64\").toString();\n};\n\nconst loadSourceMap = (filename: string): TraceMap | undefined => {\n let sourceMapContent: string | undefined;\n\n try {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n sourceMapContent = readFileSync(filename, { encoding: \"utf8\" });\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n error.message = `Error reading sourcemap for file \"${filename}\":\\n${error.message}`;\n\n throw error;\n }\n\n const sourceMapUrl = resolveSourceMapUrl(sourceMapContent, dirname(filename));\n\n if (!sourceMapUrl) {\n return undefined;\n }\n\n let traceMapContent: string | undefined;\n\n // If it's an inline map, decode it and pass it through the same consumer factory\n if (isInlineMap(sourceMapUrl)) {\n traceMapContent = decodeInlineMap(sourceMapUrl);\n } else {\n try {\n // Load actual source map from given path\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n traceMapContent = readFileSync(sourceMapUrl, { encoding: \"utf8\" });\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n error.message = `Error reading sourcemap for file \"${filename}\":\\n${error.message}`;\n\n throw error;\n }\n }\n\n try {\n return new AnyMap(traceMapContent, sourceMapUrl);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n error.message = `Error parsing sourcemap for file \"${filename}\":\\n${error.message}`;\n\n throw error;\n }\n};\n\nexport default loadSourceMap;\n","export { default as loadSourceMap } from \"./load-source-map\";\nexport type { TraceMap } from \"@jridgewell/trace-mapping\";\nexport { generatedPositionFor, originalPositionFor, sourceContentFor, traceSegment } from \"@jridgewell/trace-mapping\";\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { a } from './chunk-7Q3PPTBP.js';
|
|
2
|
+
|
|
3
|
+
var m=t=>t instanceof Error&&t.type==="VisulimaError",s=class extends Error{constructor(r,...e){super(...e);a(this,"loc");a(this,"title");a(this,"hint");a(this,"type","VisulimaError");let{hint:n,location:a$1,message:o,name:c,stack:p,title:l}=r;this.title=l,this.name=c,o&&(this.message=o),this.stack=p??this.stack,this.loc=a$1,this.hint=n,Error.captureStackTrace(this,this.constructor);}setLocation(r){this.loc=r;}setName(r){this.name=r;}setMessage(r){this.message=r;}setHint(r){this.hint=r;}};
|
|
4
|
+
|
|
5
|
+
export { m as a, s as b };
|
|
6
|
+
//# sourceMappingURL=out.js.map
|
|
7
|
+
//# sourceMappingURL=chunk-X3TE67TZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/visulima-error.ts"],"names":["isVisulimaError","error","VisulimaError","properties","parameters","__publicField","hint","location","message","name","stack","title"],"mappings":"wCAEO,IAAMA,EAAmBC,GAA2CA,aAAiB,OAAUA,EAAwB,OAAS,gBAE1HC,EAAN,cAA4B,KAAM,CAa9B,YAAYC,KAAgCC,EAAiB,CAEhE,MAAM,GAAGA,CAAU,EAdvBC,EAAA,KAAO,OAEPA,EAAA,KAAO,SAKPA,EAAA,KAAO,QAEPA,EAAA,KAAO,OAAO,iBAOV,GAAM,CAAE,KAAAC,EAAM,SAAAC,EAAU,QAAAC,EAAS,KAAAC,EAAM,MAAAC,EAAO,MAAAC,CAAM,EAAIR,EACxD,KAAK,MAAQQ,EACb,KAAK,KAAOF,EAERD,IACA,KAAK,QAAUA,GAInB,KAAK,MAAQE,GAAU,KAAK,MAC5B,KAAK,IAAMH,EACX,KAAK,KAAOD,EAEZ,MAAM,kBAAkB,KAAM,KAAK,WAAW,CAClD,CAEO,YAAYC,EAA+B,CAC9C,KAAK,IAAMA,CACf,CAEO,QAAQE,EAAoB,CAC/B,KAAK,KAAOA,CAChB,CAEO,WAAWD,EAAuB,CACrC,KAAK,QAAUA,CACnB,CAEO,QAAQF,EAA+B,CAC1C,KAAK,KAAOA,CAChB,CACJ","sourcesContent":["import type { ErrorLocation, ErrorProperties } from \"./types\";\n\nexport const isVisulimaError = (error: unknown): error is VisulimaError => error instanceof Error && (error as VisulimaError).type === \"VisulimaError\";\n\nexport class VisulimaError extends Error {\n public loc: ErrorLocation | undefined;\n\n public title: string | undefined;\n\n /**\n * A message that explains to the user how they can fix the error.\n */\n public hint: string[] | string | undefined;\n\n public type = \"VisulimaError\";\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types,@typescript-eslint/no-explicit-any\n public constructor(properties: ErrorProperties, ...parameters: any) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n super(...parameters);\n\n const { hint, location, message, name, stack, title } = properties;\n this.title = title;\n this.name = name;\n\n if (message) {\n this.message = message;\n }\n\n // Only set this if we actually have a stack passed, otherwise uses Error's\n this.stack = stack ?? (this.stack as string);\n this.loc = location;\n this.hint = hint;\n\n Error.captureStackTrace(this, this.constructor);\n }\n\n public setLocation(location: ErrorLocation): void {\n this.loc = location;\n }\n\n public setName(name: string): void {\n this.name = name;\n }\n\n public setMessage(message: string): void {\n this.message = message;\n }\n\n public setHint(hint: string[] | string): void {\n this.hint = hint;\n }\n}\n"]}
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { E as ErrorLocation, a as ErrorProperties } from './types-e15294e6.js';
|
|
2
|
+
export { C as CodeFrameOptions, b as ErrorWithMetadata, T as Trace } from './types-e15294e6.js';
|
|
3
|
+
|
|
4
|
+
declare const isVisulimaError: (error: unknown) => error is VisulimaError;
|
|
5
|
+
declare class VisulimaError extends Error {
|
|
6
|
+
loc: ErrorLocation | undefined;
|
|
7
|
+
title: string | undefined;
|
|
8
|
+
hint: string[] | string | undefined;
|
|
9
|
+
type: string;
|
|
10
|
+
constructor(properties: ErrorProperties, ...parameters: any);
|
|
11
|
+
setLocation(location: ErrorLocation): void;
|
|
12
|
+
setName(name: string): void;
|
|
13
|
+
setMessage(message: string): void;
|
|
14
|
+
setHint(hint: string[] | string): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { ErrorLocation, ErrorProperties, VisulimaError, isVisulimaError };
|
package/dist/error.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,58 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
title?: string;
|
|
8
|
-
}
|
|
9
|
-
interface ErrorLocation {
|
|
10
|
-
column?: number;
|
|
11
|
-
file?: string;
|
|
12
|
-
line?: number;
|
|
13
|
-
}
|
|
14
|
-
interface ErrorWithMetadata<Type = NonNullable<unknown> & string> {
|
|
15
|
-
[name: string]: any;
|
|
16
|
-
cause?: any;
|
|
17
|
-
frame?: string;
|
|
18
|
-
fullCode?: string;
|
|
19
|
-
hint?: string;
|
|
20
|
-
id?: string;
|
|
21
|
-
loc?: {
|
|
22
|
-
column?: number;
|
|
23
|
-
file?: string;
|
|
24
|
-
line?: number;
|
|
25
|
-
};
|
|
26
|
-
message: string;
|
|
27
|
-
name: string;
|
|
28
|
-
stack: string;
|
|
29
|
-
title?: string;
|
|
30
|
-
type?: Type | "VisulimaError";
|
|
31
|
-
}
|
|
32
|
-
type CodeFrameOptions = {
|
|
33
|
-
focusLineColor?: (value: string) => string;
|
|
34
|
-
linesAbove?: number;
|
|
35
|
-
linesBelow?: number;
|
|
36
|
-
};
|
|
1
|
+
import { E as ErrorLocation, C as CodeFrameOptions } from './types-e15294e6.js';
|
|
2
|
+
export { a as ErrorProperties, b as ErrorWithMetadata, T as Trace } from './types-e15294e6.js';
|
|
3
|
+
export { VisulimaError, isVisulimaError } from './error.js';
|
|
4
|
+
export { loadSourceMap } from './sourcemap.js';
|
|
5
|
+
export { TraceMap, generatedPositionFor, originalPositionFor, sourceContentFor, traceSegment } from '@jridgewell/trace-mapping';
|
|
6
|
+
export { parseStacktrace } from './stacktrace.js';
|
|
37
7
|
|
|
38
8
|
declare const codeFrame: (source: string, loc: ErrorLocation, options?: CodeFrameOptions) => string;
|
|
39
9
|
|
|
40
|
-
declare const isVisulimaError: (error: unknown) => error is VisulimaError;
|
|
41
|
-
declare class VisulimaError extends Error {
|
|
42
|
-
loc: ErrorLocation | undefined;
|
|
43
|
-
title: string | undefined;
|
|
44
|
-
hint: string[] | string | undefined;
|
|
45
|
-
type: string;
|
|
46
|
-
constructor(properties: ErrorProperties, ...parameters: any);
|
|
47
|
-
setLocation(location: ErrorLocation): void;
|
|
48
|
-
setName(name: string): void;
|
|
49
|
-
setMessage(message: string): void;
|
|
50
|
-
setHint(hint: string[] | string): void;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
10
|
declare const positionAt: (offset: number, text: string) => {
|
|
54
11
|
column: number;
|
|
55
12
|
line: number;
|
|
56
13
|
};
|
|
57
14
|
|
|
58
|
-
export { CodeFrameOptions, ErrorLocation,
|
|
15
|
+
export { CodeFrameOptions, ErrorLocation, codeFrame, positionAt };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
export { b as VisulimaError, a as isVisulimaError } from './chunk-X3TE67TZ.js';
|
|
2
|
+
export { a as parseStacktrace } from './chunk-26F4MLO2.js';
|
|
3
|
+
export { b as generatedPositionFor, a as loadSourceMap, c as originalPositionFor, d as sourceContentFor, e as traceSegment } from './chunk-F52HEHA7.js';
|
|
4
|
+
import './chunk-7Q3PPTBP.js';
|
|
1
5
|
import { platform, env } from 'process';
|
|
2
6
|
|
|
3
|
-
var
|
|
4
|
-
`,
|
|
5
|
-
`&&
|
|
6
|
-
`),
|
|
7
|
-
`).map(
|
|
8
|
-
`,
|
|
9
|
-
`:l;}),
|
|
7
|
+
var O=r=>{let o=[],i=!0;for(let e=0;e<r.length;e++){i&&(o.push(e),i=!1);let t=r.charAt(e);i=t==="\r"||t===`
|
|
8
|
+
`,t==="\r"&&e+1<r.length&&r.charAt(e+1)===`
|
|
9
|
+
`&&e++;}return i&&r.length>0&&o.push(r.length),o},f=r=>r.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
|
|
10
|
+
`),S=(r,o)=>{let i=O(o);r=Math.max(0,Math.min(o.length,r));let e=0,t=i.length;if(t===0)return {column:r,line:0};for(;e<=t;){let s=Math.floor((e+t)/2),m=i[s];if(m===r)return {column:0,line:s};r>m?e=s+1:t=s-1;}let a=e-1;return {column:r-i[a],line:a}};var h=platform==="win32"&&!env.WT_SESSION?">":"\u276F",y=(r,o,i)=>{if(o.line===void 0||o.column===void 0)return "";let e={focusLineColor:n=>n,linesAbove:2,linesBelow:3,...i},t=f(r).split(`
|
|
11
|
+
`).map(n=>n.replaceAll(" "," ")),a=[];for(let n=-(e.linesAbove+1);n<=e.linesBelow;n++)t[o.line+n]&&a.push(o.line+n);let s=0;a.forEach(n=>{let l=`${h} ${n}${n<9?" ":""}`;l.length>s&&(s=l.length);});let m="";return a.forEach(n=>{let l="",c=n===o.line-1;l+=c?`${h} `:" ",l+=`${n<9?" ":""}${n+1} | ${t[n]}
|
|
12
|
+
`,c&&(l+=`${Array.from({length:s}).join(" ")} | ${Array.from({length:o.column}).join(" ")}^`),m+=c?`${e.focusLineColor(l)}
|
|
13
|
+
`:l;}),m},C=y;
|
|
10
14
|
|
|
11
|
-
export {
|
|
15
|
+
export { C as codeFrame, S as positionAt };
|
|
12
16
|
//# sourceMappingURL=out.js.map
|
|
13
17
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/code-frame.ts","../src/utils.ts"
|
|
1
|
+
{"version":3,"sources":["../src/code-frame.ts","../src/utils.ts"],"names":["env","platform","getLineOffsets","text","lineOffsets","isLineStart","index","ch","normalizeLF","code","positionAt","offset","low","high","mid","lineOffset","line","POINTER","codeFrame","source","loc","options","config","value","lines","ln","visibleLines","gutterWidth","lineNo","w","output","isFocusedLine","code_frame_default"],"mappings":"uLAAA,OAAS,OAAAA,EAAK,YAAAC,MAAgB,UCA9B,IAAMC,EAAkBC,GAA2B,CAC/C,IAAMC,EAAc,CAAC,EACjBC,EAAc,GAGlB,QAASC,EAAQ,EAAGA,EAAQH,EAAK,OAAQG,IAAS,CAC1CD,IACAD,EAAY,KAAKE,CAAK,EACtBD,EAAc,IAGlB,IAAME,EAAKJ,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AI,EAAEJ,EAAO,WAAa,GAAI,GAAKA,EAAO,WAAY,IACvDE,EAAMJ,EAAI,KAAO,CAAC,GAClBM,EAAa,KAAKN,EAAI,KAAO,CAAC,EAKtC,IAAIO,EAAc,EAElBD,EAAa,QAASE,GAAW,CAC7B,IAAMC,EAAI,GAAGZ,CAAO,IAAIW,CAAM,GAAGA,EAAS,EAAI,IAAM,EAAE,GAElDC,EAAE,OAASF,IACXA,EAAcE,EAAE,OAExB,CAAC,EAGD,IAAIC,EAAS,GAEb,OAAAJ,EAAa,QAASE,GAAW,CAC7B,IAAInB,EAAO,GACLsB,EAAgBH,IAAYR,EAAI,KAAkB,EAExDX,GAAQsB,EAAgB,GAAGd,CAAO,IAAM,KAExCR,GAAQ,GAAGmB,EAAS,EAAI,IAAM,EAAE,GAAGA,EAAS,CAAC,MAAMJ,EAAMI,CAAM,CAAC;AAAA,EAE5DG,IACAtB,GAAQ,GAAG,MAAM,KAAK,CAAE,OAAQkB,CAAY,CAAC,EAAE,KAAK,GAAG,CAAC,OAAO,MAAM,KAAK,CACtE,OAAQP,EAAI,MAChB,CAAC,EAAE,KAAK,GAAG,CAAC,KAGhBU,GAAUC,EAAgB,GAAGT,EAAO,eAAeb,CAAI,CAAC;AAAA,EAAOA,CACnE,CAAC,EAEMqB,CACX,EAEOE,EAAQd","sourcesContent":["import { env, platform } from \"node:process\";\n\nimport type { CodeFrameOptions, ErrorLocation } from \"./types\";\nimport { normalizeLF } from \"./utils\";\n\nconst POINTER = platform === \"win32\" && !env[\"WT_SESSION\"] ? \">\" : \"❯\";\n\n/** Generate a code frame from string and an error location */\nconst codeFrame = (\n source: string,\n loc: ErrorLocation,\n options?: CodeFrameOptions,\n // eslint-disable-next-line sonarjs/cognitive-complexity\n): string => {\n if (loc.line === undefined || loc.column === undefined) {\n return \"\";\n }\n\n // grab 2 lines before, and 3 lines after focused line\n const config = {\n focusLineColor: (value: string) => value,\n linesAbove: 2,\n linesBelow: 3,\n ...options,\n };\n\n const lines = normalizeLF(source)\n .split(\"\\n\")\n .map((ln) => ln.replaceAll(\"\\t\", \" \"));\n\n const visibleLines = [];\n\n // eslint-disable-next-line no-loops/no-loops,no-plusplus\n for (let n = -(config.linesAbove + 1); n <= config.linesBelow; n++) {\n if (lines[loc.line + n]) {\n visibleLines.push(loc.line + n);\n }\n }\n\n // figure out gutter width\n let gutterWidth = 0;\n\n visibleLines.forEach((lineNo) => {\n const w = `${POINTER} ${lineNo}${lineNo < 9 ? \" \" : \"\"}`;\n\n if (w.length > gutterWidth) {\n gutterWidth = w.length;\n }\n });\n\n // print lines\n let output = \"\";\n\n visibleLines.forEach((lineNo) => {\n let code = \"\";\n const isFocusedLine = lineNo === (loc.line as number) - 1;\n\n code += isFocusedLine ? `${POINTER} ` : \" \";\n // eslint-disable-next-line security/detect-object-injection\n code += `${lineNo < 9 ? \" \" : \"\"}${lineNo + 1} | ${lines[lineNo]}\\n`;\n\n if (isFocusedLine) {\n code += `${Array.from({ length: gutterWidth }).join(\" \")} | ${Array.from({\n length: loc.column as number,\n }).join(\" \")}^`;\n }\n\n output += isFocusedLine ? `${config.focusLineColor(code)}\\n` : code;\n });\n\n return output;\n};\n\nexport default codeFrame;\n","const getLineOffsets = (text: string): number[] => {\n const lineOffsets = [];\n let isLineStart = true;\n\n // eslint-disable-next-line no-plusplus,no-loops/no-loops\n for (let index = 0; index < text.length; index++) {\n if (isLineStart) {\n lineOffsets.push(index);\n isLineStart = false;\n }\n\n const ch = text.charAt(index);\n\n isLineStart = ch === \"\\r\" || ch === \"\\n\";\n\n if (ch === \"\\r\" && index + 1 < text.length && text.charAt(index + 1) === \"\\n\") {\n // eslint-disable-next-line no-plusplus\n index++;\n }\n }\n\n if (isLineStart && text.length > 0) {\n lineOffsets.push(text.length);\n }\n\n return lineOffsets;\n};\n\nexport const normalizeLF = (code: string): string => code.replaceAll(/\\r\\n|\\r(?!\\n)|\\n/gu, \"\\n\");\n\n/**\n * Get the line and character based on the offset\n * @param offset The index of the position\n * @param text The text for which the position should be retrieved\n */\nexport const positionAt = (\n offset: number,\n text: string,\n): {\n column: number;\n line: number;\n} => {\n const lineOffsets = getLineOffsets(text);\n\n // eslint-disable-next-line no-param-reassign\n offset = Math.max(0, Math.min(text.length, offset));\n\n let low = 0;\n let high = lineOffsets.length;\n\n if (high === 0) {\n return {\n column: offset,\n line: 0,\n };\n }\n\n // eslint-disable-next-line no-loops/no-loops\n while (low <= high) {\n const mid = Math.floor((low + high) / 2);\n // eslint-disable-next-line security/detect-object-injection\n const lineOffset = lineOffsets[mid] as number;\n\n if (lineOffset === offset) {\n return {\n column: 0,\n line: mid,\n };\n }\n\n if (offset > lineOffset) {\n low = mid + 1;\n } else {\n high = mid - 1;\n }\n }\n\n // low is the least x for which the line offset is larger than the current offset\n // or array.length if no line offset is larger than the current offset\n const line = low - 1;\n\n // eslint-disable-next-line security/detect-object-injection\n return { column: offset - (lineOffsets[line] as number), line };\n};\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TraceMap } from '@jridgewell/trace-mapping';
|
|
2
|
+
export { TraceMap, generatedPositionFor, originalPositionFor, sourceContentFor, traceSegment } from '@jridgewell/trace-mapping';
|
|
3
|
+
|
|
4
|
+
declare const loadSourceMap: (filename: string) => TraceMap | undefined;
|
|
5
|
+
|
|
6
|
+
export { loadSourceMap };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
interface ErrorProperties {
|
|
2
|
+
hint?: string;
|
|
3
|
+
location?: ErrorLocation;
|
|
4
|
+
message?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
stack?: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
}
|
|
9
|
+
interface ErrorLocation {
|
|
10
|
+
column?: number;
|
|
11
|
+
file?: string;
|
|
12
|
+
line?: number;
|
|
13
|
+
}
|
|
14
|
+
interface ErrorWithMetadata<Type = NonNullable<unknown> & string> {
|
|
15
|
+
[name: string]: any;
|
|
16
|
+
cause?: any;
|
|
17
|
+
frame?: string;
|
|
18
|
+
fullCode?: string;
|
|
19
|
+
hint?: string;
|
|
20
|
+
id?: string;
|
|
21
|
+
loc?: {
|
|
22
|
+
column?: number;
|
|
23
|
+
file?: string;
|
|
24
|
+
line?: number;
|
|
25
|
+
};
|
|
26
|
+
message: string;
|
|
27
|
+
name: string;
|
|
28
|
+
stack: string;
|
|
29
|
+
title?: string;
|
|
30
|
+
type?: Type | "VisulimaError";
|
|
31
|
+
}
|
|
32
|
+
type CodeFrameOptions = {
|
|
33
|
+
focusLineColor?: (value: string) => string;
|
|
34
|
+
linesAbove?: number;
|
|
35
|
+
linesBelow?: number;
|
|
36
|
+
};
|
|
37
|
+
type TraceType = "eval" | "internal" | "native" | undefined;
|
|
38
|
+
interface Trace {
|
|
39
|
+
column: number | undefined;
|
|
40
|
+
evalOrigin?: Trace | undefined;
|
|
41
|
+
file: string | undefined;
|
|
42
|
+
line: number | undefined;
|
|
43
|
+
methodName: string | undefined;
|
|
44
|
+
raw: string;
|
|
45
|
+
type?: TraceType | undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { CodeFrameOptions as C, ErrorLocation as E, Trace as T, ErrorProperties as a, ErrorWithMetadata as b };
|
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/error",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Error with more than just a message.",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Error with more than just a message, stacktrace parsing and sourcemap loading.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"visulima",
|
|
7
7
|
"anolilab",
|
|
8
8
|
"error",
|
|
9
9
|
"exception",
|
|
10
10
|
"code-frame",
|
|
11
|
-
"codeframe"
|
|
11
|
+
"codeframe",
|
|
12
|
+
"stack",
|
|
13
|
+
"stacktrace",
|
|
14
|
+
"stack-trace",
|
|
15
|
+
"trace",
|
|
16
|
+
"source-map",
|
|
17
|
+
"parser",
|
|
18
|
+
"v8"
|
|
12
19
|
],
|
|
13
20
|
"homepage": "https://www.visulima.com/docs/package/error",
|
|
14
21
|
"repository": {
|
|
@@ -40,9 +47,26 @@
|
|
|
40
47
|
"default": "./dist/index.js"
|
|
41
48
|
}
|
|
42
49
|
},
|
|
50
|
+
"./error": {
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./dist/error.d.ts",
|
|
53
|
+
"default": "./dist/error.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"./sourcemap": {
|
|
57
|
+
"import": {
|
|
58
|
+
"types": "./dist/sourcemap.d.ts",
|
|
59
|
+
"default": "./dist/sourcemap.js"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"./stacktrace": {
|
|
63
|
+
"import": {
|
|
64
|
+
"types": "./dist/stacktrace.d.ts",
|
|
65
|
+
"default": "./dist/stacktrace.js"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
43
68
|
"./package.json": "./package.json"
|
|
44
69
|
},
|
|
45
|
-
"source": "src/index.ts",
|
|
46
70
|
"types": "dist/index.d.ts",
|
|
47
71
|
"files": [
|
|
48
72
|
"dist",
|
|
@@ -65,11 +89,14 @@
|
|
|
65
89
|
"test": "vitest run",
|
|
66
90
|
"test:watch": "vitest"
|
|
67
91
|
},
|
|
92
|
+
"dependencies": {
|
|
93
|
+
"@jridgewell/trace-mapping": "^0.3.20"
|
|
94
|
+
},
|
|
68
95
|
"devDependencies": {
|
|
69
96
|
"@anolilab/eslint-config": "^15.0.2",
|
|
70
97
|
"@anolilab/prettier-config": "^5.0.13",
|
|
71
98
|
"@anolilab/semantic-release-preset": "^8.0.2",
|
|
72
|
-
"@babel/core": "^7.23.
|
|
99
|
+
"@babel/core": "^7.23.5",
|
|
73
100
|
"@eslint-types/deprecation": "^2.0.0",
|
|
74
101
|
"@eslint-types/import": "^2.29.0",
|
|
75
102
|
"@eslint-types/jsdoc": "^46.9.0",
|
|
@@ -79,7 +106,7 @@
|
|
|
79
106
|
"@total-typescript/ts-reset": "^0.5.1",
|
|
80
107
|
"@types/command-line-args": "^5.2.3",
|
|
81
108
|
"@types/node": "18.18.5",
|
|
82
|
-
"@visulima/nextra-theme-docs": "4.0.
|
|
109
|
+
"@visulima/nextra-theme-docs": "4.0.10",
|
|
83
110
|
"@vitest/coverage-v8": "^0.34.6",
|
|
84
111
|
"chalk": "^5.3.0",
|
|
85
112
|
"cross-env": "^7.0.3",
|
|
@@ -116,5 +143,11 @@
|
|
|
116
143
|
"info_on_disabling_jsonc_sort_keys_rule": false,
|
|
117
144
|
"info_on_disabling_etc_no_deprecated": false
|
|
118
145
|
}
|
|
119
|
-
}
|
|
146
|
+
},
|
|
147
|
+
"sources": [
|
|
148
|
+
"src/index.ts",
|
|
149
|
+
"src/error.ts",
|
|
150
|
+
"src/stacktrace.ts",
|
|
151
|
+
"src/sourcemap.ts"
|
|
152
|
+
]
|
|
120
153
|
}
|