@visulima/error 5.0.3 → 5.0.5

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/code-frame/get-marker-lines.d.ts +19 -0
  3. package/dist/code-frame/index-to-line-column.d.ts +7 -0
  4. package/dist/code-frame/index.d.ts +15 -7
  5. package/dist/code-frame/index.js +125 -6
  6. package/dist/{packem_shared/types-CrVmNoPV.d.ts → code-frame/types.d.ts} +4 -6
  7. package/dist/error/capture-raw-stack-trace.d.ts +2 -0
  8. package/dist/error/get-error-causes.d.ts +6 -0
  9. package/dist/error/index.d.ts +12 -96
  10. package/dist/error/index.js +8 -1
  11. package/dist/error/render/error.d.ts +22 -0
  12. package/dist/error/serialize/deserialize.d.ts +14 -0
  13. package/dist/error/serialize/error-constructors.d.ts +25 -0
  14. package/dist/error/serialize/error-proto.d.ts +10 -0
  15. package/dist/error/serialize/non-error.d.ts +7 -0
  16. package/dist/error/serialize/serialize.d.ts +14 -0
  17. package/dist/error/types.d.ts +33 -0
  18. package/dist/error/visulima-error.d.ts +16 -0
  19. package/dist/index.d.ts +12 -17
  20. package/dist/index.js +16 -1
  21. package/dist/packem_shared/NonError-D5FGLYKY.js +8 -0
  22. package/dist/packem_shared/addKnownErrorConstructor-s_3SsXtQ.js +30 -0
  23. package/dist/packem_shared/aiFinder-HftEgsry.js +277 -0
  24. package/dist/packem_shared/aiSolutionResponse-CJBMLS9t.js +34 -0
  25. package/dist/packem_shared/captureRawStackTrace-ySw7cU0U.js +10 -0
  26. package/dist/packem_shared/deserializeError-E0VQnnm0.js +116 -0
  27. package/dist/packem_shared/errorHintFinder-DEaeRnRW.js +21 -0
  28. package/dist/packem_shared/formatStackFrameLine-D3_6oSWZ.js +24 -0
  29. package/dist/packem_shared/getErrorCauses-DpUsmuqw.js +43 -0
  30. package/dist/packem_shared/index-y_UPkY2Z.js +9 -0
  31. package/dist/packem_shared/indexToLineColumn-Bg8UW1bU.js +50 -0
  32. package/dist/packem_shared/isVisulimaError-DA7QsCxH.js +34 -0
  33. package/dist/packem_shared/parseStacktrace-oQvk7wYp.js +273 -0
  34. package/dist/packem_shared/renderError-C30PRFtU.js +206 -0
  35. package/dist/packem_shared/ruleBasedFinder-C2F8rQ30.js +207 -0
  36. package/dist/packem_shared/serializeError-BZ62KiYZ.js +142 -0
  37. package/dist/solution/ai/ai-finder.d.ts +12 -0
  38. package/dist/solution/ai/ai-prompt.d.ts +2 -4
  39. package/dist/solution/ai/ai-prompt.js +13 -7
  40. package/dist/{packem_shared/ai-solution-response-BuaDQAEU.d.ts → solution/ai/ai-solution-response.d.ts} +1 -2
  41. package/dist/solution/ai/index.d.ts +3 -16
  42. package/dist/solution/ai/index.js +3 -1
  43. package/dist/solution/error-hint-finder.d.ts +3 -0
  44. package/dist/solution/index.d.ts +3 -8
  45. package/dist/solution/index.js +2 -1
  46. package/dist/solution/rule-based-finder.d.ts +3 -0
  47. package/dist/{packem_shared/types-BtQS7FHG.d.ts → solution/types.d.ts} +4 -6
  48. package/dist/stacktrace/index.d.ts +3 -26
  49. package/dist/stacktrace/index.js +2 -1
  50. package/dist/stacktrace/parse-stacktrace.d.ts +6 -0
  51. package/dist/stacktrace/stringify.d.ts +15 -0
  52. package/dist/stacktrace/types.d.ts +10 -0
  53. package/dist/util/normalize-lf.d.ts +2 -0
  54. package/dist/util/process.d.ts +5 -0
  55. package/package.json +1 -1
  56. package/dist/packem_shared/NonError-CS10kwil.js +0 -1
  57. package/dist/packem_shared/addKnownErrorConstructor-BqqnTSZp.js +0 -1
  58. package/dist/packem_shared/aiFinder-DPoqj12B.js +0 -1
  59. package/dist/packem_shared/aiSolutionResponse-RD0AK1jh.js +0 -10
  60. package/dist/packem_shared/captureRawStackTrace-CQPNHvBG.js +0 -1
  61. package/dist/packem_shared/deserializeError-BJM8Kd6G.js +0 -1
  62. package/dist/packem_shared/errorHintFinder-C_g0nvml.js +0 -2
  63. package/dist/packem_shared/formatStackFrameLine-iU54KA81.js +0 -2
  64. package/dist/packem_shared/getErrorCauses-geeK5cwE.js +0 -1
  65. package/dist/packem_shared/index-CLFYRLyq.js +0 -1
  66. package/dist/packem_shared/indexToLineColumn-B1F7aNZh.js +0 -1
  67. package/dist/packem_shared/isVisulimaError-jVZgumOU.js +0 -1
  68. package/dist/packem_shared/parseStacktrace-Dnxnc4PL.js +0 -2
  69. package/dist/packem_shared/renderError-ZMlMvw1N.js +0 -18
  70. package/dist/packem_shared/ruleBasedFinder-P88d0gpK.js +0 -34
  71. package/dist/packem_shared/serializeError-CTpDr3CL.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,34 @@
1
+ ## @visulima/error [5.0.5](https://github.com/visulima/visulima/compare/@visulima/error@5.0.4...@visulima/error@5.0.5) (2025-11-12)
2
+
3
+ ### Bug Fixes
4
+
5
+ * update package configurations and TypeScript definitions ([b59aa59](https://github.com/visulima/visulima/commit/b59aa59dac1508216b944f4b917fb4a7ab1f70a4))
6
+
7
+ ### Miscellaneous Chores
8
+
9
+ * Add jsr file to all packages for release ([#565](https://github.com/visulima/visulima/issues/565)) ([ec91652](https://github.com/visulima/visulima/commit/ec91652b4e4112adf14ba152c1239a7703ba425a))
10
+ * update license files and clean up TypeScript definitions ([fe668cc](https://github.com/visulima/visulima/commit/fe668cc26de23591d4df54a0954455ebbe31b22d))
11
+
12
+
13
+ ### Dependencies
14
+
15
+ * **@visulima/path:** upgraded to 2.0.4
16
+
17
+ ## @visulima/error [5.0.4](https://github.com/visulima/visulima/compare/@visulima/error@5.0.3...@visulima/error@5.0.4) (2025-11-07)
18
+
19
+ ### Bug Fixes
20
+
21
+ * update TypeScript configurations and improve linting across multiple packages ([6f25ec7](https://github.com/visulima/visulima/commit/6f25ec7841da7246f8f9166efc5292a7089d37ee))
22
+
23
+ ### Miscellaneous Chores
24
+
25
+ * update npm and pnpm configurations for monorepo optimization ([#564](https://github.com/visulima/visulima/issues/564)) ([5512b42](https://github.com/visulima/visulima/commit/5512b42f672c216b6a3c9e39035199a4ebd9a4b8))
26
+
27
+
28
+ ### Dependencies
29
+
30
+ * **@visulima/path:** upgraded to 2.0.3
31
+
1
32
  ## @visulima/error [5.0.3](https://github.com/visulima/visulima/compare/@visulima/error@5.0.2...@visulima/error@5.0.3) (2025-11-05)
2
33
 
3
34
  ### Bug Fixes
@@ -0,0 +1,19 @@
1
+ /**
2
+ * This is a copy of the codeFrame function from Babel
3
+ * @see https://github.com/babel/babel/blob/85e649203b61b7c908eb04c05511a0d35f893e8e/packages/babel-code-frame/src/index.ts#L68-L143
4
+ *
5
+ * MIT License
6
+ *
7
+ * Copyright (c) 2014-present Sebastian McKenzie and other contributors
8
+ */
9
+ /**
10
+ * Extract what lines should be marked and highlighted.
11
+ */
12
+ import type { CodeFrameNodeLocation } from "./types.d.ts";
13
+ type MarkerLines = Record<number, true | [number | undefined, number | undefined]>;
14
+ declare const getMarkerLines: (loc: CodeFrameNodeLocation, source: string[], linesAbove: number, linesBelow: number) => {
15
+ end: number;
16
+ markerLines: MarkerLines;
17
+ start: number;
18
+ };
19
+ export default getMarkerLines;
@@ -0,0 +1,7 @@
1
+ declare const indexToLineColumn: (input: number[] | string, index: number, options?: {
2
+ skipChecks: boolean;
3
+ }) => {
4
+ column: number;
5
+ line: number;
6
+ };
7
+ export default indexToLineColumn;
@@ -1,7 +1,15 @@
1
- import { a as CodeFrameNodeLocation, b as CodeFrameOptions } from '../packem_shared/types-CrVmNoPV.js';
2
- export { C as CodeFrameLocation, c as ColorizeMethod } from '../packem_shared/types-CrVmNoPV.js';
3
-
4
- declare const CODE_FRAME_POINTER: string;
5
- declare const codeFrame: (source: string, loc: CodeFrameNodeLocation, options?: CodeFrameOptions) => string;
6
-
7
- export { CODE_FRAME_POINTER, CodeFrameNodeLocation, CodeFrameOptions, codeFrame };
1
+ /**
2
+ * This is a modified copy of the codeFrameColumns function from Babel
3
+ * @see https://github.com/babel/babel/blob/85e649203b61b7c908eb04c05511a0d35f893e8e/packages/babel-code-frame/src/index.ts#L145-L217
4
+ *
5
+ * MIT License
6
+ *
7
+ * Copyright (c) 2014-present Sebastian McKenzie and other contributors
8
+ */
9
+ import type { CodeFrameNodeLocation, CodeFrameOptions } from "./types.d.ts";
10
+ export declare const CODE_FRAME_POINTER: string;
11
+ /**
12
+ * Generate a code frame from string and an error location.
13
+ */
14
+ export declare const codeFrame: (source: string, loc: CodeFrameNodeLocation, options?: CodeFrameOptions) => string;
15
+ export type { CodeFrameLocation, CodeFrameNodeLocation, CodeFrameOptions, ColorizeMethod } from "./types.d.ts";
@@ -1,6 +1,125 @@
1
- var M=Object.defineProperty;var v=(t,e)=>M(t,"name",{value:e,configurable:!0});var F=Object.defineProperty,P=v((t,e)=>F(t,"name",{value:e,configurable:!0}),"r$1");const E=P(t=>t.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
2
- `),"normalizeLF"),S=globalThis.process||Object.create(null),y={versions:{}},k=new Proxy(S,{get(t,e){if(e in t)return t[e];if(e in y)return y[e]}});var W=Object.defineProperty,T=v((t,e)=>W(t,"name",{value:e,configurable:!0}),"b");const _=T((t,e,h,n)=>{const f={column:0,line:-1,...t.start},i={...f,...t.end},o=f.line,l=f.column,u=i.line,m=i.column;let g=Math.max(o-(h+1),0),p=Math.min(e.length,u+n);o===-1&&(g=0),u===-1&&(p=e.length);const b=u-o,a={};if(b)for(let r=0;r<=b;r++){const s=r+o;if(!l)a[s]=!0;else if(r===0){const c=e[s-1]?.length;a[s]=[l,(c??0)-l+1]}else if(r===b)a[s]=[0,m];else{const c=e[s-r]?.length;a[s]=[0,c]}}else l===m?a[o]=l?[l,0]:!0:a[o]=[l,(m??0)-(l??0)];return{end:p,markerLines:a,start:g}},"getMarkerLines");var B=Object.defineProperty,$=v((t,e)=>B(t,"name",{value:e,configurable:!0}),"o");const C=k.platform==="win32"&&!k.env?.WT_SESSION?">":"❯",I=$((t,e,h)=>{const n={linesAbove:2,linesBelow:3,prefix:"",showGutter:!0,tabWidth:4,...h,color:{gutter:$(r=>r,"gutter"),marker:$(r=>r,"marker"),message:$(r=>r,"message"),...h?.color}},f=e.start&&typeof e.start.column=="number";let i=E(t).split(`
3
- `);typeof n?.tabWidth=="number"&&(i=i.map(r=>r.replaceAll(" "," ".repeat(n.tabWidth))));const{end:o,markerLines:l,start:u}=_(e,i,n.linesAbove,n.linesBelow),m=String(o).length,{gutter:g,marker:p,message:b}=n.color;let a=i.slice(u,o).map((r,s)=>{const c=u+1+s,d=l[c],j=` ${c}`.slice(-m),O=!l[c+1],x=` ${j}${n.showGutter?" |":""}`;if(d){let A="";if(Array.isArray(d)){const w=r.replaceAll(/[^\t]/g," ").slice(0,Math.max(d[0]-1,0)),L=d[1]||1;A=[`
4
- `,n.prefix+g(x.replaceAll(/\d/g," "))," ",w,p("^").repeat(L)].join(""),O&&n.message&&(A+=` ${b(n.message)}`)}return[n.prefix+p(C),g(x),r.length>0?` ${r}`:"",A].join("")}return`${n.prefix} ${g(x)}${r.length>0?` ${r}`:""}`}).join(`
5
- `);return n.message&&!f&&(a=`${n.prefix+" ".repeat(m+1)+n.message}
6
- ${a}`),a},"codeFrame");export{C as CODE_FRAME_POINTER,I as codeFrame};
1
+ const normalizeLF = (code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n");
2
+
3
+ const _process = globalThis.process || /* @__PURE__ */ Object.create(null);
4
+ const processShims = {
5
+ versions: {}
6
+ };
7
+ const process = new Proxy(_process, {
8
+ get(target, property) {
9
+ if (property in target) {
10
+ return target[property];
11
+ }
12
+ if (property in processShims) {
13
+ return processShims[property];
14
+ }
15
+ return void 0;
16
+ }
17
+ });
18
+
19
+ const getMarkerLines = (loc, source, linesAbove, linesBelow) => {
20
+ const startLoc = {
21
+ column: 0,
22
+ // @ts-expect-error Can be overwritten
23
+ line: -1,
24
+ ...loc.start
25
+ };
26
+ const endLoc = {
27
+ ...startLoc,
28
+ ...loc.end
29
+ };
30
+ const startLine = startLoc.line;
31
+ const startColumn = startLoc.column;
32
+ const endLine = endLoc.line;
33
+ const endColumn = endLoc.column;
34
+ let start = Math.max(startLine - (linesAbove + 1), 0);
35
+ let end = Math.min(source.length, endLine + linesBelow);
36
+ if (startLine === -1) {
37
+ start = 0;
38
+ }
39
+ if (endLine === -1) {
40
+ end = source.length;
41
+ }
42
+ const lineDiff = endLine - startLine;
43
+ const markerLines = {};
44
+ if (lineDiff) {
45
+ for (let index = 0; index <= lineDiff; index++) {
46
+ const lineNumber = index + startLine;
47
+ if (!startColumn) {
48
+ markerLines[lineNumber] = true;
49
+ } else if (index === 0) {
50
+ const sourceLength = source[lineNumber - 1]?.length;
51
+ markerLines[lineNumber] = [startColumn, (sourceLength ?? 0) - startColumn + 1];
52
+ } else if (index === lineDiff) {
53
+ markerLines[lineNumber] = [0, endColumn];
54
+ } else {
55
+ const sourceLength = source[lineNumber - index]?.length;
56
+ markerLines[lineNumber] = [0, sourceLength];
57
+ }
58
+ }
59
+ } else if (startColumn === endColumn) {
60
+ markerLines[startLine] = startColumn ? [startColumn, 0] : true;
61
+ } else {
62
+ markerLines[startLine] = [startColumn, (endColumn ?? 0) - (startColumn ?? 0)];
63
+ }
64
+ return { end, markerLines, start };
65
+ };
66
+
67
+ const CODE_FRAME_POINTER = process.platform === "win32" && !process.env?.WT_SESSION ? ">" : "❯";
68
+ const codeFrame = (source, loc, options) => {
69
+ const config = {
70
+ // grab 2 lines before, and 3 lines after focused line
71
+ linesAbove: 2,
72
+ linesBelow: 3,
73
+ prefix: "",
74
+ showGutter: true,
75
+ tabWidth: 4,
76
+ ...options,
77
+ color: {
78
+ gutter: (value) => value,
79
+ marker: (value) => value,
80
+ message: (value) => value,
81
+ ...options?.color
82
+ }
83
+ };
84
+ const hasColumns = loc.start && typeof loc.start.column === "number";
85
+ let lines = normalizeLF(source).split("\n");
86
+ if (typeof config?.tabWidth === "number") {
87
+ lines = lines.map((ln) => ln.replaceAll(" ", " ".repeat(config.tabWidth)));
88
+ }
89
+ const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);
90
+ const numberMaxWidth = String(end).length;
91
+ const { gutter: colorizeGutter, marker: colorizeMarker, message: colorizeMessage } = config.color;
92
+ let frame = lines.slice(start, end).map((line, index) => {
93
+ const number = start + 1 + index;
94
+ const hasMarker = markerLines[number];
95
+ const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
96
+ const lastMarkerLine = !markerLines[number + 1];
97
+ const gutter = ` ${paddedNumber}${config.showGutter ? " |" : ""}`;
98
+ if (hasMarker) {
99
+ let markerLine = "";
100
+ if (Array.isArray(hasMarker)) {
101
+ const markerSpacing = line.replaceAll(/[^\t]/g, " ").slice(0, Math.max(hasMarker[0] - 1, 0));
102
+ const numberOfMarkers = hasMarker[1] || 1;
103
+ markerLine = [
104
+ "\n ",
105
+ config.prefix + colorizeGutter(gutter.replaceAll(/\d/g, " ")),
106
+ " ",
107
+ markerSpacing,
108
+ colorizeMarker("^").repeat(numberOfMarkers)
109
+ ].join("");
110
+ if (lastMarkerLine && config.message) {
111
+ markerLine += ` ${colorizeMessage(config.message)}`;
112
+ }
113
+ }
114
+ return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
115
+ }
116
+ return `${config.prefix} ${colorizeGutter(gutter)}${line.length > 0 ? ` ${line}` : ""}`;
117
+ }).join("\n");
118
+ if (config.message && !hasColumns) {
119
+ frame = `${config.prefix + " ".repeat(numberMaxWidth + 1) + config.message}
120
+ ${frame}`;
121
+ }
122
+ return frame;
123
+ };
124
+
125
+ export { CODE_FRAME_POINTER, codeFrame };
@@ -1,13 +1,13 @@
1
- type CodeFrameLocation = {
1
+ export type CodeFrameLocation = {
2
2
  column?: number;
3
3
  line: number;
4
4
  };
5
- type CodeFrameNodeLocation = {
5
+ export type CodeFrameNodeLocation = {
6
6
  end?: CodeFrameLocation;
7
7
  start: CodeFrameLocation;
8
8
  };
9
- type ColorizeMethod = (value: string) => string;
10
- type CodeFrameOptions = {
9
+ export type ColorizeMethod = (value: string) => string;
10
+ export type CodeFrameOptions = {
11
11
  color?: {
12
12
  gutter?: ColorizeMethod;
13
13
  marker?: ColorizeMethod;
@@ -21,5 +21,3 @@ type CodeFrameOptions = {
21
21
  showLineNumbers?: boolean;
22
22
  tabWidth?: number | false;
23
23
  };
24
-
25
- export type { CodeFrameLocation as C, CodeFrameNodeLocation as a, CodeFrameOptions as b, ColorizeMethod as c };
@@ -0,0 +1,2 @@
1
+ declare const captureRawStackTrace: () => string | undefined;
2
+ export default captureRawStackTrace;
@@ -0,0 +1,6 @@
1
+ import type { VisulimaError } from "./visulima-error.d.ts";
2
+ /**
3
+ * Will return an array of all causes in the error in the order they occurred.
4
+ */
5
+ declare const getErrorCauses: <E = Error | VisulimaError | unknown>(error: E) => E[];
6
+ export default getErrorCauses;
@@ -1,96 +1,12 @@
1
- import { b as CodeFrameOptions, c as ColorizeMethod } from '../packem_shared/types-CrVmNoPV.js';
2
-
3
- declare const captureRawStackTrace: () => string | undefined;
4
-
5
- interface ErrorProperties {
6
- cause?: Error | unknown;
7
- hint?: ErrorHint;
8
- location?: ErrorLocation;
9
- message?: string;
10
- name: string;
11
- stack?: string;
12
- title?: string;
13
- }
14
- interface ErrorLocation {
15
- column?: number;
16
- file?: string;
17
- line?: number;
18
- }
19
- type ErrorHint = string[] | string;
20
-
21
- declare const isVisulimaError: (error: unknown) => error is VisulimaError;
22
- declare class VisulimaError extends Error {
23
- loc: ErrorLocation | undefined;
24
- title: string | undefined;
25
- hint: ErrorHint | undefined;
26
- type: string;
27
- constructor({ cause, hint, location, message, name, stack, title }: ErrorProperties);
28
- setLocation(location: ErrorLocation): void;
29
- setName(name: string): void;
30
- setMessage(message: string): void;
31
- setHint(hint: ErrorHint): void;
32
- }
33
-
34
- declare const getErrorCauses: <E = Error | VisulimaError | unknown>(error: E) => E[];
35
-
36
- type Options$1 = Omit<CodeFrameOptions, "message | prefix"> & {
37
- color: CodeFrameOptions["color"] & {
38
- fileLine: ColorizeMethod;
39
- hint: ColorizeMethod;
40
- method: ColorizeMethod;
41
- title: ColorizeMethod;
42
- };
43
- cwd: string;
44
- displayShortPath: boolean;
45
- filterStacktrace: ((line: string) => boolean) | undefined;
46
- framesMaxLimit: number;
47
- hideErrorCauseCodeView: boolean;
48
- hideErrorCodeView: boolean;
49
- hideErrorErrorsCodeView: boolean;
50
- hideErrorTitle: boolean;
51
- hideMessage: boolean;
52
- indentation: number | "\t";
53
- prefix: string;
54
- };
55
- declare const renderError: (error: AggregateError | Error | VisulimaError, options?: Partial<Options$1>) => string;
56
-
57
- interface DeserializeOptions {
58
- maxDepth?: number;
59
- }
60
- type DeserializeOptionsType = DeserializeOptions;
61
- declare const deserialize: (value: unknown, options?: DeserializeOptionsType) => Error;
62
-
63
- type ErrorConstructor = new (...arguments_: any[]) => Error;
64
- declare const addKnownErrorConstructor: (constructor: ErrorConstructor, name?: string) => void;
65
- declare const isErrorLike: (value: unknown) => value is {
66
- message?: string;
67
- name?: string;
68
- stack?: string;
69
- };
70
-
71
- type SerializedError<ErrorType = Error> = Record<PropertyKey, unknown> & {
72
- aggregateErrors?: SerializedError<ErrorType>[];
73
- cause?: unknown;
74
- code?: string;
75
- message: string;
76
- name: string;
77
- raw?: ErrorType;
78
- stack?: string;
79
- };
80
-
81
- declare class NonError extends Error {
82
- constructor(message: string);
83
- }
84
-
85
- interface JsonError extends Error {
86
- toJSON: () => SerializedError;
87
- }
88
- type Options = {
89
- exclude?: string[];
90
- maxDepth?: number;
91
- useToJSON?: boolean;
92
- };
93
- declare const serialize: (error: AggregateError | Error | JsonError, options?: Options) => SerializedError;
94
-
95
- export { NonError, VisulimaError, addKnownErrorConstructor, captureRawStackTrace, deserialize as deserializeError, getErrorCauses, isErrorLike, isVisulimaError, renderError, serialize as serializeError };
96
- export type { ErrorHint, ErrorLocation, ErrorProperties, Options as ErrorWithCauseSerializerOptions, Options$1 as RenderErrorOptions, SerializedError };
1
+ export { default as captureRawStackTrace } from "./capture-raw-stack-trace.d.ts";
2
+ export { default as getErrorCauses } from "./get-error-causes.d.ts";
3
+ export type { Options as RenderErrorOptions } from "./render/error.d.ts";
4
+ export { renderError } from "./render/error.d.ts";
5
+ export { default as deserializeError } from "./serialize/deserialize.d.ts";
6
+ export { addKnownErrorConstructor, isErrorLike } from "./serialize/error-constructors.d.ts";
7
+ export type { SerializedError } from "./serialize/error-proto.d.ts";
8
+ export { default as NonError } from "./serialize/non-error.d.ts";
9
+ export type { Options as ErrorWithCauseSerializerOptions } from "./serialize/serialize.d.ts";
10
+ export { serialize as serializeError } from "./serialize/serialize.d.ts";
11
+ export type { ErrorHint, ErrorLocation, ErrorProperties } from "./types.d.ts";
12
+ export { isVisulimaError, VisulimaError } from "./visulima-error.d.ts";
@@ -1 +1,8 @@
1
- import{default as e}from"../packem_shared/captureRawStackTrace-CQPNHvBG.js";import{default as t}from"../packem_shared/getErrorCauses-geeK5cwE.js";import{renderError as i}from"../packem_shared/renderError-ZMlMvw1N.js";import{default as m}from"../packem_shared/deserializeError-BJM8Kd6G.js";import{addKnownErrorConstructor as p,isErrorLike as u}from"../packem_shared/addKnownErrorConstructor-BqqnTSZp.js";import{default as d}from"../packem_shared/NonError-CS10kwil.js";import{serialize as n}from"../packem_shared/serializeError-CTpDr3CL.js";import{VisulimaError as z,isVisulimaError as k}from"../packem_shared/isVisulimaError-jVZgumOU.js";export{d as NonError,z as VisulimaError,p as addKnownErrorConstructor,e as captureRawStackTrace,m as deserializeError,t as getErrorCauses,u as isErrorLike,k as isVisulimaError,i as renderError,n as serializeError};
1
+ export { default as captureRawStackTrace } from '../packem_shared/captureRawStackTrace-ySw7cU0U.js';
2
+ export { default as getErrorCauses } from '../packem_shared/getErrorCauses-DpUsmuqw.js';
3
+ export { renderError } from '../packem_shared/renderError-C30PRFtU.js';
4
+ export { default as deserializeError } from '../packem_shared/deserializeError-E0VQnnm0.js';
5
+ export { addKnownErrorConstructor, isErrorLike } from '../packem_shared/addKnownErrorConstructor-s_3SsXtQ.js';
6
+ export { default as NonError } from '../packem_shared/NonError-D5FGLYKY.js';
7
+ export { serialize as serializeError } from '../packem_shared/serializeError-BZ62KiYZ.js';
8
+ export { VisulimaError, isVisulimaError } from '../packem_shared/isVisulimaError-DA7QsCxH.js';
@@ -0,0 +1,22 @@
1
+ import type { CodeFrameOptions, ColorizeMethod } from "../../index.d.ts";
2
+ import type { VisulimaError } from "../visulima-error.d.ts";
3
+ export type Options = Omit<CodeFrameOptions, "message | prefix"> & {
4
+ color: CodeFrameOptions["color"] & {
5
+ fileLine: ColorizeMethod;
6
+ hint: ColorizeMethod;
7
+ method: ColorizeMethod;
8
+ title: ColorizeMethod;
9
+ };
10
+ cwd: string;
11
+ displayShortPath: boolean;
12
+ filterStacktrace: ((line: string) => boolean) | undefined;
13
+ framesMaxLimit: number;
14
+ hideErrorCauseCodeView: boolean;
15
+ hideErrorCodeView: boolean;
16
+ hideErrorErrorsCodeView: boolean;
17
+ hideErrorTitle: boolean;
18
+ hideMessage: boolean;
19
+ indentation: number | "\t";
20
+ prefix: string;
21
+ };
22
+ export declare const renderError: (error: AggregateError | Error | VisulimaError, options?: Partial<Options>) => string;
@@ -0,0 +1,14 @@
1
+ interface DeserializeOptions {
2
+ maxDepth?: number;
3
+ }
4
+ /**
5
+ * Options for deserializing error objects.
6
+ */
7
+ type DeserializeOptionsType = DeserializeOptions;
8
+ /**
9
+ * Deserialize a value back to its original form.
10
+ * If the value looks like a serialized error, it will be reconstructed as an Error instance.
11
+ * Otherwise, it will be wrapped in a NonError.
12
+ */
13
+ declare const deserialize: (value: unknown, options?: DeserializeOptionsType) => Error;
14
+ export default deserialize;
@@ -0,0 +1,25 @@
1
+ type ErrorConstructor = new (...arguments_: any[]) => Error;
2
+ /**
3
+ * Add a known error constructor to the registry.
4
+ * @param constructor The error constructor to add
5
+ * @param name Optional custom name to use instead of instance.name
6
+ * @throws {Error} If the constructor is already known or incompatible
7
+ */
8
+ export declare const addKnownErrorConstructor: (constructor: ErrorConstructor, name?: string) => void;
9
+ /**
10
+ * Get all known error constructors.
11
+ */
12
+ export declare const getKnownErrorConstructors: () => Map<string, new (...arguments_: any[]) => Error>;
13
+ /**
14
+ * Get a specific error constructor by name.
15
+ */
16
+ export declare const getErrorConstructor: (name: string) => (new (...arguments_: any[]) => Error) | undefined;
17
+ /**
18
+ * Check if an object looks like a serialized error.
19
+ */
20
+ export declare const isErrorLike: (value: unknown) => value is {
21
+ message?: string;
22
+ name?: string;
23
+ stack?: string;
24
+ };
25
+ export {};
@@ -0,0 +1,10 @@
1
+ export declare const ErrorProto: SerializedError;
2
+ export type SerializedError<ErrorType = Error> = Record<PropertyKey, unknown> & {
3
+ aggregateErrors?: SerializedError<ErrorType>[];
4
+ cause?: unknown;
5
+ code?: string;
6
+ message: string;
7
+ name: string;
8
+ raw?: ErrorType;
9
+ stack?: string;
10
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * NonError class for deserializing non-error-like objects
3
+ */
4
+ declare class NonError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export default NonError;
@@ -0,0 +1,14 @@
1
+ import type { SerializedError } from "./error-proto.d.ts";
2
+ interface JsonError extends Error {
3
+ toJSON: () => SerializedError;
4
+ }
5
+ export type Options = {
6
+ exclude?: string[];
7
+ maxDepth?: number;
8
+ useToJSON?: boolean;
9
+ };
10
+ /**
11
+ * Serialize an `Error` object into a plain object.
12
+ */
13
+ export declare const serialize: (error: AggregateError | Error | JsonError, options?: Options) => SerializedError;
14
+ export {};
@@ -0,0 +1,33 @@
1
+ export interface ErrorProperties {
2
+ cause?: Error | unknown;
3
+ hint?: ErrorHint;
4
+ location?: ErrorLocation;
5
+ message?: string;
6
+ name: string;
7
+ stack?: string;
8
+ title?: string;
9
+ }
10
+ export interface ErrorLocation {
11
+ column?: number;
12
+ file?: string;
13
+ line?: number;
14
+ }
15
+ /**
16
+ * A message that explains to the user how they can fix the error.
17
+ * @example
18
+ * ```ts
19
+ * const error = new VisulimaError({
20
+ * hint: "Try running `npm install` to install missing dependencies.",
21
+ * location: {
22
+ * file: "src/index.ts",
23
+ * line: 1,
24
+ * column: 1,
25
+ * },
26
+ * message: "Cannot find module 'react'",
27
+ * name: "ModuleNotFoundError",
28
+ * });
29
+ * ```
30
+ *
31
+ * For more complex hints, you can pass an array of strings or a single string in markdown format.
32
+ */
33
+ export type ErrorHint = string[] | string;
@@ -0,0 +1,16 @@
1
+ import type { ErrorHint, ErrorLocation, ErrorProperties } from "./types.d.ts";
2
+ export declare const isVisulimaError: (error: unknown) => error is VisulimaError;
3
+ export declare class VisulimaError extends Error {
4
+ loc: ErrorLocation | undefined;
5
+ title: string | undefined;
6
+ /**
7
+ * A message that explains to the user how they can fix the error.
8
+ */
9
+ hint: ErrorHint | undefined;
10
+ type: string;
11
+ constructor({ cause, hint, location, message, name, stack, title }: ErrorProperties);
12
+ setLocation(location: ErrorLocation): void;
13
+ setName(name: string): void;
14
+ setMessage(message: string): void;
15
+ setHint(hint: ErrorHint): void;
16
+ }
package/dist/index.d.ts CHANGED
@@ -1,17 +1,12 @@
1
- export { CODE_FRAME_POINTER, codeFrame } from './code-frame/index.js';
2
- export { default as aiPrompt } from './solution/ai/ai-prompt.js';
3
- export { a as aiSolutionResponse } from './packem_shared/ai-solution-response-BuaDQAEU.js';
4
- export { errorHintFinder, ruleBasedFinder } from './solution/index.js';
5
- export { S as Solution, a as SolutionError, b as SolutionFinder, c as SolutionFinderFile } from './packem_shared/types-BtQS7FHG.js';
6
- export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, NonError, RenderErrorOptions, SerializedError, VisulimaError, addKnownErrorConstructor, captureRawStackTrace, deserializeError, getErrorCauses, isErrorLike, isVisulimaError, renderError, serializeError } from './error/index.js';
7
- export { Trace, TraceType, formatStackFrameLine, formatStacktrace, parseStacktrace } from './stacktrace/index.js';
8
- export { C as CodeFrameLocation, a as CodeFrameNodeLocation, b as CodeFrameOptions, c as ColorizeMethod } from './packem_shared/types-CrVmNoPV.js';
9
-
10
- declare const indexToLineColumn: (input: number[] | string, index: number, options?: {
11
- skipChecks: boolean;
12
- }) => {
13
- column: number;
14
- line: number;
15
- };
16
-
17
- export { indexToLineColumn };
1
+ export type { CodeFrameLocation, CodeFrameNodeLocation, CodeFrameOptions, ColorizeMethod } from "./code-frame/index.d.ts";
2
+ export { CODE_FRAME_POINTER, codeFrame } from "./code-frame/index.d.ts";
3
+ export { default as indexToLineColumn } from "./code-frame/index-to-line-column.d.ts";
4
+ export type { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, RenderErrorOptions, SerializedError } from "./error/index.d.ts";
5
+ export { addKnownErrorConstructor, captureRawStackTrace, deserializeError, getErrorCauses, isErrorLike, isVisulimaError, NonError, renderError, serializeError, VisulimaError, } from "./error/index.d.ts";
6
+ export { default as aiPrompt } from "./solution/ai/ai-prompt.d.ts";
7
+ export { default as aiSolutionResponse } from "./solution/ai/ai-solution-response.d.ts";
8
+ export { default as errorHintFinder } from "./solution/error-hint-finder.d.ts";
9
+ export { default as ruleBasedFinder } from "./solution/rule-based-finder.d.ts";
10
+ export type { Solution, SolutionError, SolutionFinder, SolutionFinderFile } from "./solution/types.d.ts";
11
+ export type { Trace, TraceType } from "./stacktrace/index.d.ts";
12
+ export { formatStackFrameLine, formatStacktrace, parseStacktrace } from "./stacktrace/index.d.ts";
package/dist/index.js CHANGED
@@ -1 +1,16 @@
1
- import{CODE_FRAME_POINTER as o,codeFrame as a}from"./code-frame/index.js";import{default as f}from"./packem_shared/indexToLineColumn-B1F7aNZh.js";import{default as m}from"./solution/ai/ai-prompt.js";import{default as p}from"./packem_shared/aiSolutionResponse-RD0AK1jh.js";import{default as l}from"./packem_shared/errorHintFinder-C_g0nvml.js";import{default as x}from"./packem_shared/ruleBasedFinder-P88d0gpK.js";import{default as E}from"./packem_shared/captureRawStackTrace-CQPNHvBG.js";import{default as k}from"./packem_shared/deserializeError-BJM8Kd6G.js";import{default as S}from"./packem_shared/getErrorCauses-geeK5cwE.js";import{default as R}from"./packem_shared/NonError-CS10kwil.js";import{default as L}from"./packem_shared/parseStacktrace-Dnxnc4PL.js";import{addKnownErrorConstructor as w,isErrorLike as N}from"./packem_shared/addKnownErrorConstructor-BqqnTSZp.js";import{VisulimaError as P,isVisulimaError as V}from"./packem_shared/isVisulimaError-jVZgumOU.js";import{renderError as g}from"./packem_shared/renderError-ZMlMvw1N.js";import{serialize as B}from"./packem_shared/serializeError-CTpDr3CL.js";import{formatStackFrameLine as H,formatStacktrace as I}from"./packem_shared/formatStackFrameLine-iU54KA81.js";export{o as CODE_FRAME_POINTER,R as NonError,P as VisulimaError,w as addKnownErrorConstructor,m as aiPrompt,p as aiSolutionResponse,E as captureRawStackTrace,a as codeFrame,k as deserializeError,l as errorHintFinder,H as formatStackFrameLine,I as formatStacktrace,S as getErrorCauses,f as indexToLineColumn,N as isErrorLike,V as isVisulimaError,L as parseStacktrace,g as renderError,x as ruleBasedFinder,B as serializeError};
1
+ export { CODE_FRAME_POINTER, codeFrame } from './code-frame/index.js';
2
+ export { default as indexToLineColumn } from './packem_shared/indexToLineColumn-Bg8UW1bU.js';
3
+ export { default as aiPrompt } from './solution/ai/ai-prompt.js';
4
+ export { default as aiSolutionResponse } from './packem_shared/aiSolutionResponse-CJBMLS9t.js';
5
+ export { default as errorHintFinder } from './packem_shared/errorHintFinder-DEaeRnRW.js';
6
+ export { default as ruleBasedFinder } from './packem_shared/ruleBasedFinder-C2F8rQ30.js';
7
+ export { default as captureRawStackTrace } from './packem_shared/captureRawStackTrace-ySw7cU0U.js';
8
+ export { default as deserializeError } from './packem_shared/deserializeError-E0VQnnm0.js';
9
+ export { default as getErrorCauses } from './packem_shared/getErrorCauses-DpUsmuqw.js';
10
+ export { default as NonError } from './packem_shared/NonError-D5FGLYKY.js';
11
+ export { default as parseStacktrace } from './packem_shared/parseStacktrace-oQvk7wYp.js';
12
+ export { addKnownErrorConstructor, isErrorLike } from './packem_shared/addKnownErrorConstructor-s_3SsXtQ.js';
13
+ export { VisulimaError, isVisulimaError } from './packem_shared/isVisulimaError-DA7QsCxH.js';
14
+ export { renderError } from './packem_shared/renderError-C30PRFtU.js';
15
+ export { serialize as serializeError } from './packem_shared/serializeError-BZ62KiYZ.js';
16
+ export { formatStackFrameLine, formatStacktrace } from './packem_shared/formatStackFrameLine-D3_6oSWZ.js';
@@ -0,0 +1,8 @@
1
+ class NonError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = "NonError";
5
+ }
6
+ }
7
+
8
+ export { NonError as default };
@@ -0,0 +1,30 @@
1
+ const defaultErrorConstructors = /* @__PURE__ */ new Map([
2
+ ["Error", Error],
3
+ ["EvalError", EvalError],
4
+ ["RangeError", RangeError],
5
+ ["ReferenceError", ReferenceError],
6
+ ["SyntaxError", SyntaxError],
7
+ ["TypeError", TypeError],
8
+ ["URIError", URIError]
9
+ ]);
10
+ if (typeof AggregateError !== "undefined") {
11
+ defaultErrorConstructors.set("AggregateError", AggregateError);
12
+ }
13
+ const addKnownErrorConstructor = (constructor, name) => {
14
+ let instance;
15
+ try {
16
+ instance = new constructor();
17
+ } catch (error) {
18
+ throw new Error(`The error constructor "${constructor.name}" is not compatible`, { cause: error });
19
+ }
20
+ const resolvedName = name ?? instance.name;
21
+ if (defaultErrorConstructors.has(resolvedName)) {
22
+ throw new Error(`The error constructor "${resolvedName}" is already known.`);
23
+ }
24
+ defaultErrorConstructors.set(resolvedName, constructor);
25
+ };
26
+ const getKnownErrorConstructors = () => new Map(defaultErrorConstructors);
27
+ const getErrorConstructor = (name) => defaultErrorConstructors.get(name);
28
+ const isErrorLike = (value) => value !== null && typeof value === "object" && typeof value.name === "string" && typeof value.message === "string" && (getErrorConstructor(value.name) !== void 0 || value.name === "Error");
29
+
30
+ export { addKnownErrorConstructor, getErrorConstructor, getKnownErrorConstructors, isErrorLike };