@vltpkg/error-cause 0.0.0-8 → 1.0.0-rc.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.
@@ -7,7 +7,7 @@ import type { IncomingHttpHeaders, IncomingMessage } from 'http';
7
7
  * Several of these types are just very basic duck-typing, because referencing
8
8
  * internal types directly would create a workspace dependency cycle.
9
9
  */
10
- export type ErrorCauseObject = {
10
+ export type ErrorCauseOptions = {
11
11
  /**
12
12
  * The `cause` field within a `cause` object should
13
13
  * always be an `Error` object that was previously thrown. Note
@@ -17,7 +17,7 @@ export type ErrorCauseObject = {
17
17
  * because we use `useUnknownInCatchVariables` so this makes it easier
18
18
  * to rethrow a caught error without recasting it.
19
19
  */
20
- cause?: ErrorCause | unknown;
20
+ cause?: unknown;
21
21
  /** the name of something */
22
22
  name?: string;
23
23
  /** byte offset in a Buffer or file */
@@ -39,7 +39,7 @@ export type ErrorCauseObject = {
39
39
  target?: string;
40
40
  /** Spec object/string relevant to an operation that failed */
41
41
  spec?: string | {
42
- type: 'file' | 'git' | 'registry' | 'remote' | 'workspace';
42
+ type: 'file' | 'git' | 'registry' | 'remote' | 'workspace' | 'catalog';
43
43
  spec: string;
44
44
  [k: number | string | symbol]: any;
45
45
  };
@@ -63,7 +63,7 @@ export type ErrorCauseObject = {
63
63
  * Array of valid options when something is not a valid option.
64
64
  * (For use in `did you mean X?` output.)
65
65
  */
66
- validOptions?: any[];
66
+ validOptions?: unknown[] | readonly unknown[];
67
67
  /**
68
68
  * message indicating what bit of work this might be a part of, what feature
69
69
  * needs to be implemented, etc. Eg, `{ todo: 'nested workspace support' }`.
@@ -73,18 +73,20 @@ export type ErrorCauseObject = {
73
73
  * A desired value that was not found, or a regular expression or other
74
74
  * pattern describing it.
75
75
  */
76
- wanted?: any;
76
+ wanted?: unknown;
77
77
  /** actual value, which was not wanted */
78
- found?: any;
78
+ found?: unknown;
79
79
  /** HTTP message, fetch.Response, or `@vltpkg/registry-client.CacheEntry` */
80
80
  response?: IncomingMessage | Response | {
81
81
  statusCode: number;
82
- headers: Buffer[] | Record<string, string[] | string> | IncomingHttpHeaders;
82
+ headers?: Uint8Array[] | Record<string, string[] | string> | IncomingHttpHeaders;
83
83
  text?: () => string;
84
84
  [k: number | string | symbol]: any;
85
85
  };
86
86
  /** string or URL object */
87
87
  url?: URL | string;
88
+ /** HTTP method */
89
+ method?: string;
88
90
  /** git repository remote or path */
89
91
  repository?: string;
90
92
  /** string or `@vltpkg/semver.Version` object */
@@ -112,9 +114,9 @@ export type ErrorCauseObject = {
112
114
  time?: Record<string, string>;
113
115
  };
114
116
  /** maximum value, which was exceeded */
115
- max?: any;
117
+ max?: unknown;
116
118
  /** minimum value, which was not met */
117
- min?: any;
119
+ min?: unknown;
118
120
  };
119
121
  export type DuckTypeManifest = Record<string, any> & {
120
122
  name?: string;
@@ -135,62 +137,33 @@ export type DuckTypeManifest = Record<string, any> & {
135
137
  }[];
136
138
  };
137
139
  };
138
- export type ErrorCause = Error | ErrorCauseObject;
139
- /**
140
- * An error with a cause that is a direct error cause object and not another
141
- * nested error.
142
- */
143
- export type ErrorWithCauseObject = Error & {
144
- cause: ErrorCauseObject;
145
- };
146
- /**
147
- * A TypeError with a cause that is a direct error cause object and not
148
- * another nested error
149
- */
150
- /**
151
- * If it is any sort of plain-ish object, assume its an error cause
152
- * because all properties of the cause are optional.
153
- */
154
- export declare const isErrorCauseObject: (v: unknown) => v is ErrorCauseObject;
155
- /**
156
- * Type guard for {@link ErrorWithCauseObject} type
157
- */
158
- export declare const isErrorRoot: (er: unknown) => er is ErrorWithCauseObject;
159
- export declare const asErrorCause: (er: unknown) => ErrorCause;
160
140
  /**
161
141
  * Valid properties for the 'code' field in an Error cause.
162
142
  * Add new options to this list as needed.
163
143
  */
164
- export type Codes = 'EEXIST' | 'EINTEGRITY' | 'EINVAL' | 'ELIFECYCLE' | 'EMAXREDIRECT' | 'ENEEDAUTH' | 'ENOENT' | 'ENOGIT' | 'ERESOLVE' | 'EUNKNOWN' | 'EUSAGE';
165
- export type From = ((...a: any[]) => any) | (new (...a: any[]) => any);
166
- export declare function error(message: string, cause?: undefined, from?: From): Error;
167
- export declare function error(message: string, cause: ErrorCauseObject, from?: From): Error & {
168
- cause: ErrorCauseObject;
169
- };
170
- export declare function error(message: string, cause: Error, from?: From): Error & {
144
+ export type Codes = 'EEXIST' | 'EINTEGRITY' | 'EINVAL' | 'ELIFECYCLE' | 'EMAXREDIRECT' | 'ENEEDAUTH' | 'ENOENT' | 'ENOGIT' | 'ERESOLVE' | 'EUNKNOWN' | 'EUSAGE' | 'EREQUEST' | 'ECONFIG';
145
+ export type ErrorCtor<T extends Error> = new (message: string, options?: {
146
+ cause: Error | ErrorCauseOptions;
147
+ }) => T;
148
+ export declare function error(message: string, cause?: undefined, from?: Function): Error;
149
+ export declare function error(message: string, cause: Error, from?: Function): Error & {
171
150
  cause: Error;
172
151
  };
173
- export declare function error(message: string, cause: ErrorCause, from?: From): Error & {
174
- cause: ErrorCause;
175
- };
176
- export declare function typeError(message: string, cause?: undefined, from?: From): TypeError;
177
- export declare function typeError(message: string, cause: ErrorCauseObject, from?: From): TypeError & {
178
- cause: ErrorCauseObject;
152
+ export declare function error(message: string, cause: ErrorCauseOptions, from?: Function): Error & {
153
+ cause: ErrorCauseOptions;
179
154
  };
180
- export declare function typeError(message: string, cause: Error, from?: From): TypeError & {
155
+ export declare function typeError(message: string, cause?: undefined, from?: Function): TypeError;
156
+ export declare function typeError(message: string, cause: Error, from?: Function): TypeError & {
181
157
  cause: Error;
182
158
  };
183
- export declare function typeError(message: string, cause: ErrorCause, from?: From): TypeError & {
184
- cause: ErrorCause;
185
- };
186
- export declare function syntaxError(message: string, cause?: undefined, from?: From): SyntaxError;
187
- export declare function syntaxError(message: string, cause: ErrorCauseObject, from?: From): SyntaxError & {
188
- cause: ErrorCauseObject;
159
+ export declare function typeError(message: string, cause: ErrorCauseOptions, from?: Function): TypeError & {
160
+ cause: ErrorCauseOptions;
189
161
  };
190
- export declare function syntaxError(message: string, cause: Error, from?: From): SyntaxError & {
162
+ export declare function syntaxError(message: string, cause?: undefined, from?: Function): SyntaxError;
163
+ export declare function syntaxError(message: string, cause: Error, from?: Function): SyntaxError & {
191
164
  cause: Error;
192
165
  };
193
- export declare function syntaxError(message: string, cause: ErrorCause, from?: From): SyntaxError & {
194
- cause: ErrorCause;
166
+ export declare function syntaxError(message: string, cause: ErrorCauseOptions, from?: Function): SyntaxError & {
167
+ cause: ErrorCauseOptions;
195
168
  };
196
169
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AAEhE;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,CAAA;IAE5B,4BAA4B;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;;;OAIG;IACH,IAAI,CAAC,EAAE,KAAK,CAAA;IAEZ,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,8DAA8D;IAC9D,IAAI,CAAC,EACD,MAAM,GACN;QACE,IAAI,EAAE,MAAM,GAAG,KAAK,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,CAAA;QAC1D,IAAI,EAAE,MAAM,CAAA;QACZ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,CAAA;KACnC,CAAA;IAEL,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,C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ACd,SAAS,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAA;AAC/B,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,iBAAiB,EACxB,IAAI,CAAC,EAAE,QAAQ,GACd,SAAS,GAAG;IAAE,KAAK,EAAE,iBAAiB,CAAA;CAAE,CAAA;AAS3C,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,SAAS,EACjB,IAAI,CAAC,EAAE,QAAQ,GACd,WAAW,CAAA;AACd,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,KAAK,EACZ,IAAI,CAAC,EAAE,QAAQ,GACd,WAAW,GAAG;IAAE,KAAK,EAAE,KAAK,CAAA;CAAE,CAAA;AACjC,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,iBAAiB,EACxB,IAAI,CAAC,EAAE,QAAQ,GACd,WAAW,GAAG;IAAE,KAAK,EAAE,iBAAiB,CAAA;CAAE,CAAA"}
package/dist/esm/index.js CHANGED
@@ -1,26 +1,10 @@
1
- /**
2
- * A TypeError with a cause that is a direct error cause object and not
3
- * another nested error
4
- */
5
- /**
6
- * If it is any sort of plain-ish object, assume its an error cause
7
- * because all properties of the cause are optional.
8
- */
9
- export const isErrorCauseObject = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
10
- /**
11
- * Type guard for {@link ErrorWithCauseObject} type
12
- */
13
- export const isErrorRoot = (er) => er instanceof Error && isErrorCauseObject(er.cause);
14
- export const asErrorCause = (er) => er instanceof Error ? er
15
- : isErrorCauseObject(er) ? er
16
- // otherwise, make an error of the stringified message
17
- : new Error(
18
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
19
- er == null ? 'Unknown error' : String(er) || 'Unknown error');
1
+ /* eslint-disable @typescript-eslint/no-unsafe-function-type */
2
+ // `captureStackTrace` is non-standard so explicitly type it as possibly
3
+ // undefined since it might be in browsers.
4
+ const { captureStackTrace } = Error;
20
5
  function create(cls, defaultFrom, message, cause, from = defaultFrom) {
21
6
  const er = new cls(message, cause ? { cause } : undefined);
22
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
23
- Error.captureStackTrace?.(er, from);
7
+ captureStackTrace?.(er, from);
24
8
  return er;
25
9
  }
26
10
  export function error(message, cause, from) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AA4LA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,CAAU,EACa,EAAE,CACzB,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,EAAW,EACiB,EAAE,CAC9B,EAAE,YAAY,KAAK,IAAI,kBAAkB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;AAErD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAW,EAAc,EAAE,CACtD,EAAE,YAAY,KAAK,CAAC,CAAC,CAAC,EAAE;IACxB,CAAC,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;QAC3B,sDAAsD;QACxD,CAAC,CAAC,IAAI,KAAK;QACP,gEAAgE;QAChE,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,eAAe,CAC7D,CAAA;AAoDL,SAAS,MAAM,CACb,GAAiB,EACjB,WAAgE,EAChE,OAAe,EACf,KAAkB,EAClB,OAAa,WAAW;IAExB,MAAM,EAAE,GAAG,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAC1D,uEAAuE;IACvE,KAAK,CAAC,iBAAiB,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;IACnC,OAAO,EAAE,CAAA;AACX,CAAC;AAwBD,MAAM,UAAU,KAAK,CACnB,OAAe,EACf,KAAkB,EAClB,IAAW;IAEX,OAAO,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;AACnD,CAAC;AAsBD,MAAM,UAAU,SAAS,CACvB,OAAe,EACf,KAAkB,EAClB,IAAW;IAEX,OAAO,MAAM,CAAY,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;AACtE,CAAC;AAsBD,MAAM,UAAU,WAAW,CACzB,OAAe,EACf,KAAkB,EAClB,IAAW;IAEX,OAAO,MAAM,CACX,WAAW,EACX,WAAW,EACX,OAAO,EACP,KAAK,EACL,IAAI,CACL,CAAA;AACH,CAAC","sourcesContent":["import type { IncomingHttpHeaders, IncomingMessage } from 'http'\n\n/**\n * Codification of vlt's Error.cause conventions\n *\n * Add new properties to this list as needed.\n *\n * Several of these types are just very basic duck-typing, because referencing\n * internal types directly would create a workspace dependency cycle.\n */\nexport type ErrorCauseObject = {\n /**\n * The `cause` field within a `cause` object should\n * always be an `Error` object that was previously thrown. Note\n * that the `cause` on an Error itself might _also_ be a\n * previously thrown error, if no additional information could be\n * usefully added beyond improving the message. It is typed as `unknown`\n * because we use `useUnknownInCatchVariables` so this makes it easier\n * to rethrow a caught error without recasting it.\n */\n cause?: ErrorCause | unknown // eslint-disable-line @typescript-eslint/no-redundant-type-constituents\n\n /** the name of something */\n name?: string\n\n /** byte offset in a Buffer or file */\n offset?: number\n\n /**\n * This should only be a string code that we set. See {@link Codes} for\n * the supported options. Lower-level system codes like `ENOENT` should\n * remain on the errors that generated them.\n */\n code?: Codes\n\n /** target of a file system operation */\n path?: string\n\n /**\n * file path origin of a resolution that failed, for example in the case\n * of `file://` specifiers.\n */\n from?: string\n\n /** path on disk that is being written, linked, or extracted to */\n target?: string\n\n /** Spec object/string relevant to an operation that failed */\n spec?:\n | string\n | {\n type: 'file' | 'git' | 'registry' | 'remote' | 'workspace'\n spec: string\n [k: number | string | symbol]: any\n }\n\n /** exit code of a process, or HTTP response status code */\n status?: number | null\n\n /** null or a signal that a process received */\n signal?: NodeJS.Signals | null\n\n /** the root of a project */\n projectRoot?: string\n\n /** the current working directory of a process */\n cwd?: string\n\n /** a command being run in a child process */\n command?: string\n\n /** the arguments passed to a process */\n args?: string[]\n\n /** standard output from a process */\n stdout?: Buffer | string | null\n\n /** standard error from a process */\n stderr?: Buffer | string | null\n\n /**\n * Array of valid options when something is not a valid option.\n * (For use in `did you mean X?` output.)\n */\n validOptions?: any[]\n\n /**\n * message indicating what bit of work this might be a part of, what feature\n * needs to be implemented, etc. Eg, `{ todo: 'nested workspace support' }`.\n */\n todo?: string\n\n /**\n * A desired value that was not found, or a regular expression or other\n * pattern describing it.\n */\n wanted?: any\n\n /** actual value, which was not wanted */\n found?: any\n\n /** HTTP message, fetch.Response, or `@vltpkg/registry-client.CacheEntry` */\n response?:\n | IncomingMessage\n | Response\n | {\n statusCode: number\n headers:\n | Buffer[]\n | Record<string, string[] | string>\n | IncomingHttpHeaders\n text?: () => string\n [k: number | string | symbol]: any\n }\n\n /** string or URL object */\n url?: URL | string\n\n /** git repository remote or path */\n repository?: string\n\n /** string or `@vltpkg/semver.Version` object */\n version?:\n | string\n | {\n raw: string\n major: number\n minor: number\n patch: number\n [k: number | string | symbol]: any\n }\n\n /** string or `@vltpkg/semver.Range` object */\n range?:\n | string\n | {\n raw: string\n isAny: boolean\n includePrerelease: boolean\n [k: number | string | symbol]: any\n }\n\n /** a package manifest, either from `package.json` or a registry */\n manifest?: DuckTypeManifest\n\n /** registry top-level package document */\n packument?: {\n name: string\n 'dist-tags': Record<string, string>\n versions: Record<string, DuckTypeManifest>\n time?: Record<string, string>\n }\n\n /** maximum value, which was exceeded */\n max?: any\n\n /** minimum value, which was not met */\n min?: any\n}\n\nexport type DuckTypeManifest = Record<string, any> & {\n name?: string\n version?: string\n deprecated?: string\n engines?: Record<string, string>\n os?: string[] | string\n arch?: string[] | string\n dist?: {\n integrity?: string\n shasum?: string\n tarball?: string\n fileCount?: number\n unpackedSize?: number\n signatures?: {\n keyid: string\n sig: string\n }[]\n }\n}\n\nexport type ErrorCause = Error | ErrorCauseObject\n\n/**\n * An error with a cause that is a direct error cause object and not another\n * nested error.\n */\nexport type ErrorWithCauseObject = Error & { cause: ErrorCauseObject }\n\n/**\n * A TypeError with a cause that is a direct error cause object and not\n * another nested error\n */\n\n/**\n * If it is any sort of plain-ish object, assume its an error cause\n * because all properties of the cause are optional.\n */\nexport const isErrorCauseObject = (\n v: unknown,\n): v is ErrorCauseObject =>\n !!v && typeof v === 'object' && !Array.isArray(v)\n\n/**\n * Type guard for {@link ErrorWithCauseObject} type\n */\nexport const isErrorRoot = (\n er: unknown,\n): er is ErrorWithCauseObject =>\n er instanceof Error && isErrorCauseObject(er.cause)\n\nexport const asErrorCause = (er: unknown): ErrorCause =>\n er instanceof Error ? er\n : isErrorCauseObject(er) ? er\n // otherwise, make an error of the stringified message\n : new Error(\n // eslint-disable-next-line @typescript-eslint/no-base-to-string\n er == null ? 'Unknown error' : String(er) || 'Unknown error',\n )\n\n/**\n * Valid properties for the 'code' field in an Error cause.\n * Add new options to this list as needed.\n */\nexport type Codes =\n | 'EEXIST'\n | 'EINTEGRITY'\n | 'EINVAL'\n | 'ELIFECYCLE'\n | 'EMAXREDIRECT'\n | 'ENEEDAUTH'\n | 'ENOENT'\n | 'ENOGIT'\n | 'ERESOLVE'\n | 'EUNKNOWN'\n | 'EUSAGE'\n\ntype ErrorCtor<T extends Error> = new (\n message: string,\n options?: { cause: ErrorCause },\n) => T\n\nfunction create<T extends Error>(\n cls: ErrorCtor<T>,\n defaultFrom: ((...a: any[]) => any) | (new (...a: any[]) => any),\n message: string,\n cause?: undefined,\n from?: From,\n): T\nfunction create<T extends Error>(\n cls: ErrorCtor<T>,\n defaultFrom: ((...a: any[]) => any) | (new (...a: any[]) => any),\n message: string,\n cause?: ErrorCauseObject,\n from?: From,\n): T & { cause: ErrorCauseObject }\nfunction create<T extends Error>(\n cls: ErrorCtor<T>,\n defaultFrom: ((...a: any[]) => any) | (new (...a: any[]) => any),\n message: string,\n cause?: Error,\n from?: From,\n): T & { cause: Error }\nfunction create<T extends Error>(\n cls: ErrorCtor<T>,\n defaultFrom: ((...a: any[]) => any) | (new (...a: any[]) => any),\n message: string,\n cause?: ErrorCause,\n from?: From,\n): T & { cause: ErrorCause }\nfunction create<T extends Error>(\n cls: ErrorCtor<T>,\n defaultFrom: ((...a: any[]) => any) | (new (...a: any[]) => any),\n message: string,\n cause?: ErrorCause,\n from: From = defaultFrom,\n) {\n const er = new cls(message, cause ? { cause } : undefined)\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n Error.captureStackTrace?.(er, from)\n return er\n}\n\nexport type From = ((...a: any[]) => any) | (new (...a: any[]) => any)\n\nexport function error(\n message: string,\n cause?: undefined,\n from?: From,\n): Error\nexport function error(\n message: string,\n cause: ErrorCauseObject,\n from?: From,\n): Error & { cause: ErrorCauseObject }\nexport function error(\n message: string,\n cause: Error,\n from?: From,\n): Error & { cause: Error }\nexport function error(\n message: string,\n cause: ErrorCause,\n from?: From,\n): Error & { cause: ErrorCause }\nexport function error(\n message: string,\n cause?: ErrorCause,\n from?: From,\n) {\n return create(Error, error, message, cause, from)\n}\n\nexport function typeError(\n message: string,\n cause?: undefined,\n from?: From,\n): TypeError\nexport function typeError(\n message: string,\n cause: ErrorCauseObject,\n from?: From,\n): TypeError & { cause: ErrorCauseObject }\nexport function typeError(\n message: string,\n cause: Error,\n from?: From,\n): TypeError & { cause: Error }\nexport function typeError(\n message: string,\n cause: ErrorCause,\n from?: From,\n): TypeError & { cause: ErrorCause }\nexport function typeError(\n message: string,\n cause?: ErrorCause,\n from?: From,\n) {\n return create<TypeError>(TypeError, typeError, message, cause, from)\n}\n\nexport function syntaxError(\n message: string,\n cause?: undefined,\n from?: From,\n): SyntaxError\nexport function syntaxError(\n message: string,\n cause: ErrorCauseObject,\n from?: From,\n): SyntaxError & { cause: ErrorCauseObject }\nexport function syntaxError(\n message: string,\n cause: Error,\n from?: From,\n): SyntaxError & { cause: Error }\nexport function syntaxError(\n message: string,\n cause: ErrorCause,\n from?: From,\n): SyntaxError & { cause: ErrorCause }\nexport function syntaxError(\n message: string,\n cause?: ErrorCause,\n from?: From,\n) {\n return create<SyntaxError>(\n SyntaxError,\n syntaxError,\n message,\n cause,\n from,\n )\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAkN/D,wEAAwE;AACxE,2CAA2C;AAC3C,MAAM,EAAE,iBAAiB,EAAE,GAAG,KAE7B,CAAA;AA4BD,SAAS,MAAM,CACb,GAAiB,EACjB,WAAqB,EACrB,OAAe,EACf,KAAiC,EACjC,OAAiB,WAAW;IAE5B,MAAM,EAAE,GAAG,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAC1D,iBAAiB,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;IAC7B,OAAO,EAAE,CAAA;AACX,CAAC;AAiBD,MAAM,UAAU,KAAK,CACnB,OAAe,EACf,KAAiC,EACjC,IAAe;IAEf,OAAO,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;AACnD,CAAC;AAiBD,MAAM,UAAU,SAAS,CACvB,OAAe,EACf,KAAiC,EACjC,IAAe;IAEf,OAAO,MAAM,CAAY,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;AACtE,CAAC;AAiBD,MAAM,UAAU,WAAW,CACzB,OAAe,EACf,KAAiC,EACjC,IAAe;IAEf,OAAO,MAAM,CACX,WAAW,EACX,WAAW,EACX,OAAO,EACP,KAAK,EACL,IAAI,CACL,CAAA;AACH,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-function-type */\n\nimport type { IncomingHttpHeaders, IncomingMessage } from 'http'\n\n/**\n * Codification of vlt's Error.cause conventions\n *\n * Add new properties to this list as needed.\n *\n * Several of these types are just very basic duck-typing, because referencing\n * internal types directly would create a workspace dependency cycle.\n */\nexport type ErrorCauseOptions = {\n /**\n * The `cause` field within a `cause` object should\n * always be an `Error` object that was previously thrown. Note\n * that the `cause` on an Error itself might _also_ be a\n * previously thrown error, if no additional information could be\n * usefully added beyond improving the message. It is typed as `unknown`\n * because we use `useUnknownInCatchVariables` so this makes it easier\n * to rethrow a caught error without recasting it.\n */\n cause?: unknown\n\n /** the name of something */\n name?: string\n\n /** byte offset in a Buffer or file */\n offset?: number\n\n /**\n * This should only be a string code that we set. See {@link Codes} for\n * the supported options. Lower-level system codes like `ENOENT` should\n * remain on the errors that generated them.\n */\n code?: Codes\n\n /** target of a file system operation */\n path?: string\n\n /**\n * file path origin of a resolution that failed, for example in the case\n * of `file://` specifiers.\n */\n from?: string\n\n /** path on disk that is being written, linked, or extracted to */\n target?: string\n\n /** Spec object/string relevant to an operation that failed */\n spec?:\n | string\n | {\n type:\n | 'file'\n | 'git'\n | 'registry'\n | 'remote'\n | 'workspace'\n | 'catalog'\n spec: string\n [k: number | string | symbol]: any\n }\n\n /** exit code of a process, or HTTP response status code */\n status?: number | null\n\n /** null or a signal that a process received */\n signal?: NodeJS.Signals | null\n\n /** the root of a project */\n projectRoot?: string\n\n /** the current working directory of a process */\n cwd?: string\n\n /** a command being run in a child process */\n command?: string\n\n /** the arguments passed to a process */\n args?: string[]\n\n /** standard output from a process */\n stdout?: Buffer | string | null\n\n /** standard error from a process */\n stderr?: Buffer | string | null\n\n /**\n * Array of valid options when something is not a valid option.\n * (For use in `did you mean X?` output.)\n */\n validOptions?: unknown[] | readonly unknown[]\n\n /**\n * message indicating what bit of work this might be a part of, what feature\n * needs to be implemented, etc. Eg, `{ todo: 'nested workspace support' }`.\n */\n todo?: string\n\n /**\n * A desired value that was not found, or a regular expression or other\n * pattern describing it.\n */\n wanted?: unknown\n\n /** actual value, which was not wanted */\n found?: unknown\n\n /** HTTP message, fetch.Response, or `@vltpkg/registry-client.CacheEntry` */\n response?:\n | IncomingMessage\n | Response\n | {\n statusCode: number\n headers?:\n | Uint8Array[]\n | Record<string, string[] | string>\n | IncomingHttpHeaders\n text?: () => string\n [k: number | string | symbol]: any\n }\n\n /** string or URL object */\n url?: URL | string\n\n /** HTTP method */\n method?: string\n\n /** git repository remote or path */\n repository?: string\n\n /** string or `@vltpkg/semver.Version` object */\n version?:\n | string\n | {\n raw: string\n major: number\n minor: number\n patch: number\n [k: number | string | symbol]: any\n }\n\n /** string or `@vltpkg/semver.Range` object */\n range?:\n | string\n | {\n raw: string\n isAny: boolean\n includePrerelease: boolean\n [k: number | string | symbol]: any\n }\n\n /** a package manifest, either from `package.json` or a registry */\n manifest?: DuckTypeManifest\n\n /** registry top-level package document */\n packument?: {\n name: string\n 'dist-tags': Record<string, string>\n versions: Record<string, DuckTypeManifest>\n time?: Record<string, string>\n }\n\n /** maximum value, which was exceeded */\n max?: unknown\n\n /** minimum value, which was not met */\n min?: unknown\n}\n\nexport type DuckTypeManifest = Record<string, any> & {\n name?: string\n version?: string\n deprecated?: string\n engines?: Record<string, string>\n os?: string[] | string\n arch?: string[] | string\n dist?: {\n integrity?: string\n shasum?: string\n tarball?: string\n fileCount?: number\n unpackedSize?: number\n signatures?: {\n keyid: string\n sig: string\n }[]\n }\n}\n\n/**\n * Valid properties for the 'code' field in an Error cause.\n * Add new options to this list as needed.\n */\nexport type Codes =\n | 'EEXIST'\n | 'EINTEGRITY'\n | 'EINVAL'\n | 'ELIFECYCLE'\n | 'EMAXREDIRECT'\n | 'ENEEDAUTH'\n | 'ENOENT'\n | 'ENOGIT'\n | 'ERESOLVE'\n | 'EUNKNOWN'\n | 'EUSAGE'\n | 'EREQUEST'\n | 'ECONFIG'\n\n// `captureStackTrace` is non-standard so explicitly type it as possibly\n// undefined since it might be in browsers.\nconst { captureStackTrace } = Error as {\n captureStackTrace?: ErrorConstructor['captureStackTrace']\n}\n\nexport type ErrorCtor<T extends Error> = new (\n message: string,\n options?: { cause: Error | ErrorCauseOptions },\n) => T\n\nfunction create<T extends Error>(\n cls: ErrorCtor<T>,\n defaultFrom: Function,\n message: string,\n cause?: undefined,\n from?: Function,\n): T\nfunction create<T extends Error>(\n cls: ErrorCtor<T>,\n defaultFrom: Function,\n message: string,\n cause?: Error,\n from?: Function,\n): T & { cause: Error }\nfunction create<T extends Error>(\n cls: ErrorCtor<T>,\n defaultFrom: Function,\n message: string,\n cause?: ErrorCauseOptions,\n from?: Function,\n): T & { cause: ErrorCauseOptions }\nfunction create<T extends Error>(\n cls: ErrorCtor<T>,\n defaultFrom: Function,\n message: string,\n cause?: Error | ErrorCauseOptions,\n from: Function = defaultFrom,\n) {\n const er = new cls(message, cause ? { cause } : undefined)\n captureStackTrace?.(er, from)\n return er\n}\n\nexport function error(\n message: string,\n cause?: undefined,\n from?: Function,\n): Error\nexport function error(\n message: string,\n cause: Error,\n from?: Function,\n): Error & { cause: Error }\nexport function error(\n message: string,\n cause: ErrorCauseOptions,\n from?: Function,\n): Error & { cause: ErrorCauseOptions }\nexport function error(\n message: string,\n cause?: Error | ErrorCauseOptions,\n from?: Function,\n) {\n return create(Error, error, message, cause, from)\n}\n\nexport function typeError(\n message: string,\n cause?: undefined,\n from?: Function,\n): TypeError\nexport function typeError(\n message: string,\n cause: Error,\n from?: Function,\n): TypeError & { cause: Error }\nexport function typeError(\n message: string,\n cause: ErrorCauseOptions,\n from?: Function,\n): TypeError & { cause: ErrorCauseOptions }\nexport function typeError(\n message: string,\n cause?: Error | ErrorCauseOptions,\n from?: Function,\n) {\n return create<TypeError>(TypeError, typeError, message, cause, from)\n}\n\nexport function syntaxError(\n message: string,\n cause?: undefined,\n from?: Function,\n): SyntaxError\nexport function syntaxError(\n message: string,\n cause: Error,\n from?: Function,\n): SyntaxError & { cause: Error }\nexport function syntaxError(\n message: string,\n cause: ErrorCauseOptions,\n from?: Function,\n): SyntaxError & { cause: ErrorCauseOptions }\nexport function syntaxError(\n message: string,\n cause?: Error | ErrorCauseOptions,\n from?: Function,\n) {\n return create<SyntaxError>(\n SyntaxError,\n syntaxError,\n message,\n cause,\n from,\n )\n}\n"]}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@vltpkg/error-cause",
3
3
  "description": "vlts Error.cause convention",
4
- "version": "0.0.0-8",
4
+ "version": "1.0.0-rc.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
8
8
  "directory": "src/error-cause"
9
9
  },
10
+ "author": "vlt technology inc. <support@vlt.sh> (http://vlt.sh)",
10
11
  "tshy": {
11
12
  "selfLink": false,
12
13
  "liveDev": true,
@@ -19,16 +20,15 @@
19
20
  }
20
21
  },
21
22
  "devDependencies": {
22
- "@eslint/js": "^9.20.0",
23
- "@types/eslint__js": "^8.42.3",
24
- "@types/node": "^22.13.1",
25
- "eslint": "^9.20.0",
26
- "prettier": "^3.4.2",
23
+ "@eslint/js": "^9.34.0",
24
+ "@types/node": "^22.17.2",
25
+ "eslint": "^9.34.0",
26
+ "prettier": "^3.6.2",
27
27
  "tap": "^21.1.0",
28
28
  "tshy": "^3.0.2",
29
- "typedoc": "0.27.6",
29
+ "typedoc": "~0.27.9",
30
30
  "typescript": "5.7.3",
31
- "typescript-eslint": "^8.23.0"
31
+ "typescript-eslint": "^8.40.0"
32
32
  },
33
33
  "license": "BSD-2-Clause-Patent",
34
34
  "engines": {
@@ -60,6 +60,7 @@
60
60
  "snap": "tap",
61
61
  "test": "tap",
62
62
  "posttest": "tsc --noEmit",
63
+ "tshy": "tshy",
63
64
  "typecheck": "tsc --noEmit"
64
65
  }
65
66
  }