@vltpkg/error-cause
Advanced tools
+24
-66
@@ -82,3 +82,3 @@ import type { IncomingHttpHeaders, IncomingMessage } from 'http'; | ||
| statusCode: number; | ||
| headers: Buffer[] | Record<string, string[] | string> | IncomingHttpHeaders; | ||
| headers?: Buffer[] | Record<string, string[] | string> | IncomingHttpHeaders; | ||
| text?: () => string; | ||
@@ -142,72 +142,30 @@ [k: number | string | symbol]: any; | ||
| /** | ||
| * The input cause for the {@link error} functions. Can either be a plain error | ||
| * or an error cause options object. | ||
| */ | ||
| export type ErrorCause = Error | ErrorCauseOptions; | ||
| /** | ||
| * The same as {@link ErrorCauseOptions} except where `cause` has been | ||
| * converted to an Error. | ||
| */ | ||
| export type ErrorCauseResult = Omit<ErrorCauseOptions, 'cause'> & { | ||
| cause?: Error; | ||
| }; | ||
| /** | ||
| * An error with a cause property. Cause defaults to `unknown`. | ||
| */ | ||
| export type ErrorWithCause<T extends Error = Error, U = unknown> = T & { | ||
| cause: U; | ||
| }; | ||
| /** | ||
| * An error with a cause property that is an Error. | ||
| */ | ||
| export type ErrorWithCauseError<T extends Error = Error> = ErrorWithCause<T, Error>; | ||
| /** | ||
| * An error with a cause property that is an {@link ErrorCauseResult}. | ||
| */ | ||
| export type ErrorWithCauseObject<T extends Error = Error> = ErrorWithCause<T, ErrorCauseResult>; | ||
| /** | ||
| * Helper util to convert unknown to a plain error. Not specifically | ||
| * related to error causes, but useful for error handling in general. | ||
| */ | ||
| export declare const asError: (er: unknown, fallbackMessage?: string) => Error; | ||
| /** | ||
| * Helper util to check if an error has any type of cause property. | ||
| * Note that this does not mean it is a cause from this library, | ||
| * just that it has a cause property. | ||
| */ | ||
| export declare const isErrorWithCause: (er: unknown) => er is ErrorWithCause; | ||
| export declare const errorCodes: readonly ["EEXIST", "EINTEGRITY", "EINVAL", "ELIFECYCLE", "EMAXREDIRECT", "ENEEDAUTH", "ENOENT", "ENOGIT", "ERESOLVE", "EUNKNOWN", "EUSAGE", "EREQUEST"]; | ||
| /** | ||
| * Valid properties for the 'code' field in an Error cause. | ||
| * Add new options to this list as needed. | ||
| */ | ||
| export type Codes = (typeof errorCodes)[number]; | ||
| /** | ||
| * An error with a cause property that is an {@link ErrorCauseResult} | ||
| * and has a code property that is a {@link Codes}. | ||
| */ | ||
| export type ErrorWithCode<T extends Error = Error> = ErrorWithCause<T, Omit<ErrorCauseResult, 'code'> & { | ||
| code: Exclude<ErrorCauseResult['code'], undefined>; | ||
| }>; | ||
| /** | ||
| * Type guard to check if an error has one of our error code properties. | ||
| * Note that the type check only checks for the code property and value, | ||
| * but since every property on {@link ErrorCauseOptions} is optional, this should | ||
| * be sufficient to know the shape of the cause and use it in printing. | ||
| */ | ||
| export declare const isErrorWithCode: (er: unknown) => er is ErrorWithCode; | ||
| export type From = Function; | ||
| export type Codes = 'EEXIST' | 'EINTEGRITY' | 'EINVAL' | 'ELIFECYCLE' | 'EMAXREDIRECT' | 'ENEEDAUTH' | 'ENOENT' | 'ENOGIT' | 'ERESOLVE' | 'EUNKNOWN' | 'EUSAGE' | 'EREQUEST' | 'ECONFIG'; | ||
| export type ErrorCtor<T extends Error> = new (message: string, options?: { | ||
| cause: Error | ErrorCauseResult; | ||
| cause: Error | ErrorCauseOptions; | ||
| }) => T; | ||
| export type ErrorResult<T extends Error = Error> = T | ErrorWithCauseError<TypeError> | ErrorWithCauseObject<TypeError>; | ||
| export declare function error(message: string, cause?: undefined, from?: From): Error; | ||
| export declare function error(message: string, cause: Error, from?: From): ErrorWithCauseError; | ||
| export declare function error(message: string, cause: ErrorCauseOptions, from?: From): ErrorWithCauseObject; | ||
| export declare function typeError(message: string, cause?: undefined, from?: From): TypeError; | ||
| export declare function typeError(message: string, cause: Error, from?: From): ErrorWithCauseError<TypeError>; | ||
| export declare function typeError(message: string, cause: ErrorCauseOptions, from?: From): ErrorWithCauseObject<TypeError>; | ||
| export declare function syntaxError(message: string, cause?: undefined, from?: From): SyntaxError; | ||
| export declare function syntaxError(message: string, cause: Error, from?: From): ErrorWithCauseError<SyntaxError>; | ||
| export declare function syntaxError(message: string, cause: ErrorCauseOptions, from?: From): ErrorWithCauseObject<SyntaxError>; | ||
| export declare function error(message: string, cause?: undefined, from?: Function): Error; | ||
| export declare function error(message: string, cause: Error, from?: Function): Error & { | ||
| cause: Error; | ||
| }; | ||
| export declare function error(message: string, cause: ErrorCauseOptions, from?: Function): Error & { | ||
| cause: ErrorCauseOptions; | ||
| }; | ||
| export declare function typeError(message: string, cause?: undefined, from?: Function): TypeError; | ||
| export declare function typeError(message: string, cause: Error, from?: Function): TypeError & { | ||
| cause: Error; | ||
| }; | ||
| export declare function typeError(message: string, cause: ErrorCauseOptions, from?: Function): TypeError & { | ||
| cause: ErrorCauseOptions; | ||
| }; | ||
| export declare function syntaxError(message: string, cause?: undefined, from?: Function): SyntaxError; | ||
| export declare function syntaxError(message: string, cause: Error, from?: Function): SyntaxError & { | ||
| cause: Error; | ||
| }; | ||
| export declare function syntaxError(message: string, cause: ErrorCauseOptions, from?: Function): SyntaxError & { | ||
| cause: ErrorCauseOptions; | ||
| }; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,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,iBAAiB,GAAG;IAC9B;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IAEf,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,EAA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 | ||
| /** | ||
| * Helper util to convert unknown to a plain error. Not specifically | ||
| * related to error causes, but useful for error handling in general. | ||
| */ | ||
| export const asError = (er, fallbackMessage = 'Unknown error') => er instanceof Error ? er : new Error(String(er) || fallbackMessage); | ||
| /** | ||
| * Helper util to check if an error has any type of cause property. | ||
| * Note that this does not mean it is a cause from this library, | ||
| * just that it has a cause property. | ||
| */ | ||
| export const isErrorWithCause = (er) => er instanceof Error && 'cause' in er; | ||
| export const errorCodes = [ | ||
| 'EEXIST', | ||
| 'EINTEGRITY', | ||
| 'EINVAL', | ||
| 'ELIFECYCLE', | ||
| 'EMAXREDIRECT', | ||
| 'ENEEDAUTH', | ||
| 'ENOENT', | ||
| 'ENOGIT', | ||
| 'ERESOLVE', | ||
| 'EUNKNOWN', | ||
| 'EUSAGE', | ||
| 'EREQUEST', | ||
| ]; | ||
| const errorCodesSet = new Set(errorCodes); | ||
| /** | ||
| * Type guard to check if an error has one of our error code properties. | ||
| * Note that the type check only checks for the code property and value, | ||
| * but since every property on {@link ErrorCauseOptions} is optional, this should | ||
| * be sufficient to know the shape of the cause and use it in printing. | ||
| */ | ||
| export const isErrorWithCode = (er) => isErrorWithCause(er) && | ||
| !!er.cause && | ||
| typeof er.cause === 'object' && | ||
| 'code' in er.cause && | ||
| typeof er.cause.code === 'string' && | ||
| errorCodesSet.has(er.cause.code); | ||
| /* eslint-disable @typescript-eslint/no-unsafe-function-type */ | ||
| // `captureStackTrace` is non-standard so explicitly type it as possibly | ||
@@ -43,17 +6,3 @@ // undefined since it might be in browsers. | ||
| function create(cls, defaultFrom, message, cause, from = defaultFrom) { | ||
| let er = null; | ||
| if (cause instanceof Error) { | ||
| er = new cls(message, { cause }); | ||
| } | ||
| else if (cause && typeof cause === 'object') { | ||
| if ('cause' in cause) { | ||
| cause.cause = asError(cause.cause); | ||
| } | ||
| er = new cls(message, { | ||
| cause: cause, | ||
| }); | ||
| } | ||
| else { | ||
| er = new cls(message); | ||
| } | ||
| const er = new cls(message, cause ? { cause } : undefined); | ||
| captureStackTrace?.(er, from); | ||
@@ -60,0 +9,0 @@ return er; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAyNA;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,EAAW,EACX,eAAe,GAAG,eAAe,EAC1B,EAAE,CACT,EAAE,YAAY,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,eAAe,CAAC,CAAA;AAErE;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAAW,EAAwB,EAAE,CACpE,EAAE,YAAY,KAAK,IAAI,OAAO,IAAI,EAAE,CAAA;AAEtC,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,QAAQ;IACR,YAAY;IACZ,QAAQ;IACR,YAAY;IACZ,cAAc;IACd,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,UAAU;IACV,QAAQ;IACR,UAAU;CACF,CAAA;AAEV,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAA;AAmBzC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAW,EAAuB,EAAE,CAClE,gBAAgB,CAAC,EAAE,CAAC;IACpB,CAAC,CAAC,EAAE,CAAC,KAAK;IACV,OAAO,EAAE,CAAC,KAAK,KAAK,QAAQ;IAC5B,MAAM,IAAI,EAAE,CAAC,KAAK;IAClB,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ;IACjC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,IAAa,CAAC,CAAA;AAM3C,wEAAwE;AACxE,2CAA2C;AAC3C,MAAM,EAAE,iBAAiB,EAAE,GAAG,KAE7B,CAAA;AAiCD,SAAS,MAAM,CACb,GAAiB,EACjB,WAAiB,EACjB,OAAe,EACf,KAAkB,EAClB,OAAa,WAAW;IAExB,IAAI,EAAE,GAAa,IAAI,CAAA;IACvB,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,EAAE,GAAG,IAAI,GAAG,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IAClC,CAAC;SAAM,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9C,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;YACrB,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACpC,CAAC;QACD,EAAE,GAAG,IAAI,GAAG,CAAC,OAAO,EAAE;YACpB,KAAK,EAAE,KAAyB;SACjC,CAAC,CAAA;IACJ,CAAC;SAAM,CAAC;QACN,EAAE,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAA;IACvB,CAAC;IACD,iBAAiB,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;IAC7B,OAAO,EAAE,CAAA;AACX,CAAC;AAiBD,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;AAiBD,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;AAiBD,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 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: '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?: 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 | 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 /** 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 * The input cause for the {@link error} functions. Can either be a plain error\n * or an error cause options object.\n */\nexport type ErrorCause = Error | ErrorCauseOptions\n\n/**\n * The same as {@link ErrorCauseOptions} except where `cause` has been\n * converted to an Error.\n */\nexport type ErrorCauseResult = Omit<ErrorCauseOptions, 'cause'> & {\n cause?: Error\n}\n\n/**\n * An error with a cause property. Cause defaults to `unknown`.\n */\nexport type ErrorWithCause<\n T extends Error = Error,\n U = unknown,\n> = T & { cause: U }\n\n/**\n * An error with a cause property that is an Error.\n */\nexport type ErrorWithCauseError<T extends Error = Error> =\n ErrorWithCause<T, Error>\n\n/**\n * An error with a cause property that is an {@link ErrorCauseResult}.\n */\nexport type ErrorWithCauseObject<T extends Error = Error> =\n ErrorWithCause<T, ErrorCauseResult>\n\n/**\n * Helper util to convert unknown to a plain error. Not specifically\n * related to error causes, but useful for error handling in general.\n */\nexport const asError = (\n er: unknown,\n fallbackMessage = 'Unknown error',\n): Error =>\n er instanceof Error ? er : new Error(String(er) || fallbackMessage)\n\n/**\n * Helper util to check if an error has any type of cause property.\n * Note that this does not mean it is a cause from this library,\n * just that it has a cause property.\n */\nexport const isErrorWithCause = (er: unknown): er is ErrorWithCause =>\n er instanceof Error && 'cause' in er\n\nexport const errorCodes = [\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] as const\n\nconst errorCodesSet = new Set(errorCodes)\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 = (typeof errorCodes)[number]\n\n/**\n * An error with a cause property that is an {@link ErrorCauseResult}\n * and has a code property that is a {@link Codes}.\n */\nexport type ErrorWithCode<T extends Error = Error> = ErrorWithCause<\n T,\n Omit<ErrorCauseResult, 'code'> & {\n code: Exclude<ErrorCauseResult['code'], undefined>\n }\n>\n\n/**\n * Type guard to check if an error has one of our error code properties.\n * Note that the type check only checks for the code property and value,\n * but since every property on {@link ErrorCauseOptions} is optional, this should\n * be sufficient to know the shape of the cause and use it in printing.\n */\nexport const isErrorWithCode = (er: unknown): er is ErrorWithCode =>\n isErrorWithCause(er) &&\n !!er.cause &&\n typeof er.cause === 'object' &&\n 'code' in er.cause &&\n typeof er.cause.code === 'string' &&\n errorCodesSet.has(er.cause.code as Codes)\n\n// Use `Function` because that is the same type as `Error.captureStackTrace`\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport type From = Function\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 | ErrorCauseResult },\n) => T\n\nexport type ErrorResult<T extends Error = Error> =\n | T\n | ErrorWithCauseError<TypeError>\n | ErrorWithCauseObject<TypeError>\n\nfunction create<T extends Error>(\n cls: ErrorCtor<T>,\n defaultFrom: From,\n message: string,\n cause?: undefined,\n from?: From,\n): T\nfunction create<T extends Error>(\n cls: ErrorCtor<T>,\n defaultFrom: From,\n message: string,\n cause?: Error,\n from?: From,\n): ErrorWithCauseError<T>\nfunction create<T extends Error>(\n cls: ErrorCtor<T>,\n defaultFrom: From,\n message: string,\n cause?: ErrorCauseOptions,\n from?: From,\n): ErrorWithCauseObject<T>\nfunction create<T extends Error>(\n cls: ErrorCtor<T>,\n defaultFrom: From,\n message: string,\n cause?: ErrorCause,\n from: From = defaultFrom,\n) {\n let er: T | null = null\n if (cause instanceof Error) {\n er = new cls(message, { cause })\n } else if (cause && typeof cause === 'object') {\n if ('cause' in cause) {\n cause.cause = asError(cause.cause)\n }\n er = new cls(message, {\n cause: cause as ErrorCauseResult,\n })\n } else {\n er = new cls(message)\n }\n captureStackTrace?.(er, from)\n return er\n}\n\nexport function error(\n message: string,\n cause?: undefined,\n from?: From,\n): Error\nexport function error(\n message: string,\n cause: Error,\n from?: From,\n): ErrorWithCauseError\nexport function error(\n message: string,\n cause: ErrorCauseOptions,\n from?: From,\n): ErrorWithCauseObject\nexport function error(\n message: string,\n cause?: ErrorCause,\n from?: From,\n): ErrorResult {\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: Error,\n from?: From,\n): ErrorWithCauseError<TypeError>\nexport function typeError(\n message: string,\n cause: ErrorCauseOptions,\n from?: From,\n): ErrorWithCauseObject<TypeError>\nexport function typeError(\n message: string,\n cause?: ErrorCause,\n from?: From,\n): ErrorResult<TypeError> {\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: Error,\n from?: From,\n): ErrorWithCauseError<SyntaxError>\nexport function syntaxError(\n message: string,\n cause: ErrorCauseOptions,\n from?: From,\n): ErrorWithCauseObject<SyntaxError>\nexport function syntaxError(\n message: string,\n cause?: ErrorCause,\n from?: From,\n): ErrorResult<SyntaxError> {\n return create<SyntaxError>(\n SyntaxError,\n syntaxError,\n message,\n cause,\n from,\n )\n}\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,+DAA+D;AA4M/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: '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?: 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 | 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 /** 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"]} |
+1
-1
| { | ||
| "name": "@vltpkg/error-cause", | ||
| "description": "vlts Error.cause convention", | ||
| "version": "0.0.0-12", | ||
| "version": "0.0.0-13", | ||
| "repository": { | ||
@@ -6,0 +6,0 @@ "type": "git", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
2
-50%35468
-19.56%186
-33.33%