@autometa/errors
Advanced tools
+6
-0
| # Gherkin | ||
| ## 0.1.2 | ||
| ### Patch Changes | ||
| - 12bd4b1e: fix: hooks not handling errors correctly | ||
| ## 0.1.1 | ||
@@ -4,0 +10,0 @@ |
+13
-5
@@ -21,13 +21,21 @@ // src/automation-error.ts | ||
| function safe(action, ...args) { | ||
| const result = action(...args); | ||
| if (result instanceof Promise) { | ||
| return result.catch((e) => e); | ||
| try { | ||
| return action(...args); | ||
| } catch (e) { | ||
| return e; | ||
| } | ||
| return result; | ||
| } | ||
| async function safeAsync(action, ...args) { | ||
| try { | ||
| return await action(...args); | ||
| } catch (e) { | ||
| return e; | ||
| } | ||
| } | ||
| export { | ||
| AutomationError, | ||
| raise, | ||
| safe | ||
| safe, | ||
| safeAsync | ||
| }; | ||
| //# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../../src/automation-error.ts","../../src/raise.ts","../../src/safe-error.ts"],"sourcesContent":["export class AutomationError extends Error {\n constructor(message: string, public opts: { cause?: Error } = {}) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n super(message, opts);\n this.name = \"AutomationError\";\n }\n}\n","import { AutomationError } from \"./automation-error\";\nimport { Class } from \"@autometa/types\";\n\nexport function raise(\n message: string,\n opts?: { cause?: Error; type?: Class<AutomationError> }\n): never {\n const actual = opts ?? {};\n if (actual.type && actual.type.prototype instanceof Error) {\n throw new actual.type(message, { cause: actual.cause });\n }\n throw new AutomationError(message, { cause: actual.cause });\n}\n","import { AutomationError } from \"./automation-error\";\n\nexport function safe(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n action: (...args: any[]) => any | Promise<any>,\n ...args: unknown[]\n): AutomationError | undefined | Promise<AutomationError | undefined> {\n const result = action(...args);\n if (result instanceof Promise) {\n return result.catch((e) => e as AutomationError);\n }\n return result;\n}\n"],"mappings":";AAAO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YAAY,SAAwB,OAA0B,CAAC,GAAG;AAGhE,UAAM,SAAS,IAAI;AAHe;AAIlC,SAAK,OAAO;AAAA,EACd;AACF;;;ACJO,SAAS,MACd,SACA,MACO;AACP,QAAM,SAAS,QAAQ,CAAC;AACxB,MAAI,OAAO,QAAQ,OAAO,KAAK,qBAAqB,OAAO;AACzD,UAAM,IAAI,OAAO,KAAK,SAAS,EAAE,OAAO,OAAO,MAAM,CAAC;AAAA,EACxD;AACA,QAAM,IAAI,gBAAgB,SAAS,EAAE,OAAO,OAAO,MAAM,CAAC;AAC5D;;;ACVO,SAAS,KAEd,WACG,MACiE;AACpE,QAAM,SAAS,OAAO,GAAG,IAAI;AAC7B,MAAI,kBAAkB,SAAS;AAC7B,WAAO,OAAO,MAAM,CAAC,MAAM,CAAoB;AAAA,EACjD;AACA,SAAO;AACT;","names":[]} | ||
| {"version":3,"sources":["../../src/automation-error.ts","../../src/raise.ts","../../src/safe-error.ts"],"sourcesContent":["export class AutomationError extends Error {\n constructor(message: string, public opts: { cause?: Error } = {}) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n super(message, opts);\n this.name = \"AutomationError\";\n }\n}\n","import { AutomationError } from \"./automation-error\";\nimport { Class } from \"@autometa/types\";\n\nexport function raise(\n message: string,\n opts?: { cause?: Error; type?: Class<AutomationError> }\n): never {\n const actual = opts ?? {};\n if (actual.type && actual.type.prototype instanceof Error) {\n throw new actual.type(message, { cause: actual.cause });\n }\n throw new AutomationError(message, { cause: actual.cause });\n}\n","import { AutomationError } from \"./automation-error\";\n\nexport function safe<T>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n action: (...args: any) => T ,\n ...args: unknown[]\n): AutomationError | T {\n try{\n return action(...args);\n } catch (e) {\n return e as AutomationError\n }\n}\n\nexport async function safeAsync<T>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n action: (...args: any) => T | Promise<T>,\n ...args: unknown[]\n): Promise<AutomationError | T> {\n try{\n return await action(...args);\n } catch (e) {\n return e as AutomationError\n }\n}\n"],"mappings":";AAAO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YAAY,SAAwB,OAA0B,CAAC,GAAG;AAGhE,UAAM,SAAS,IAAI;AAHe;AAIlC,SAAK,OAAO;AAAA,EACd;AACF;;;ACJO,SAAS,MACd,SACA,MACO;AACP,QAAM,SAAS,QAAQ,CAAC;AACxB,MAAI,OAAO,QAAQ,OAAO,KAAK,qBAAqB,OAAO;AACzD,UAAM,IAAI,OAAO,KAAK,SAAS,EAAE,OAAO,OAAO,MAAM,CAAC;AAAA,EACxD;AACA,QAAM,IAAI,gBAAgB,SAAS,EAAE,OAAO,OAAO,MAAM,CAAC;AAC5D;;;ACVO,SAAS,KAEd,WACG,MACkB;AACrB,MAAG;AACD,WAAO,OAAO,GAAG,IAAI;AAAA,EACvB,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;AAEA,eAAsB,UAEpB,WACG,MAC2B;AAC9B,MAAG;AACD,WAAO,MAAM,OAAO,GAAG,IAAI;AAAA,EAC7B,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;","names":[]} |
+3
-2
@@ -17,4 +17,5 @@ import { Class } from '@autometa/types'; | ||
| declare function safe(action: (...args: any[]) => any | Promise<any>, ...args: unknown[]): AutomationError | undefined | Promise<AutomationError | undefined>; | ||
| declare function safe<T>(action: (...args: any) => T, ...args: unknown[]): AutomationError | T; | ||
| declare function safeAsync<T>(action: (...args: any) => T | Promise<T>, ...args: unknown[]): Promise<AutomationError | T>; | ||
| export { AutomationError, raise, safe }; | ||
| export { AutomationError, raise, safe, safeAsync }; |
+3
-2
@@ -17,4 +17,5 @@ import { Class } from '@autometa/types'; | ||
| declare function safe(action: (...args: any[]) => any | Promise<any>, ...args: unknown[]): AutomationError | undefined | Promise<AutomationError | undefined>; | ||
| declare function safe<T>(action: (...args: any) => T, ...args: unknown[]): AutomationError | T; | ||
| declare function safeAsync<T>(action: (...args: any) => T | Promise<T>, ...args: unknown[]): Promise<AutomationError | T>; | ||
| export { AutomationError, raise, safe }; | ||
| export { AutomationError, raise, safe, safeAsync }; |
+15
-6
@@ -25,3 +25,4 @@ "use strict"; | ||
| raise: () => raise, | ||
| safe: () => safe | ||
| safe: () => safe, | ||
| safeAsync: () => safeAsync | ||
| }); | ||
@@ -50,8 +51,15 @@ module.exports = __toCommonJS(src_exports); | ||
| function safe(action, ...args) { | ||
| const result = action(...args); | ||
| if (result instanceof Promise) { | ||
| return result.catch((e) => e); | ||
| try { | ||
| return action(...args); | ||
| } catch (e) { | ||
| return e; | ||
| } | ||
| return result; | ||
| } | ||
| async function safeAsync(action, ...args) { | ||
| try { | ||
| return await action(...args); | ||
| } catch (e) { | ||
| return e; | ||
| } | ||
| } | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
@@ -61,4 +69,5 @@ 0 && (module.exports = { | ||
| raise, | ||
| safe | ||
| safe, | ||
| safeAsync | ||
| }); | ||
| //# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/index.ts","../src/automation-error.ts","../src/raise.ts","../src/safe-error.ts"],"sourcesContent":["export * from \"./automation-error\";\nexport * from \"./raise\";\nexport * from \"./safe-error\";","export class AutomationError extends Error {\n constructor(message: string, public opts: { cause?: Error } = {}) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n super(message, opts);\n this.name = \"AutomationError\";\n }\n}\n","import { AutomationError } from \"./automation-error\";\nimport { Class } from \"@autometa/types\";\n\nexport function raise(\n message: string,\n opts?: { cause?: Error; type?: Class<AutomationError> }\n): never {\n const actual = opts ?? {};\n if (actual.type && actual.type.prototype instanceof Error) {\n throw new actual.type(message, { cause: actual.cause });\n }\n throw new AutomationError(message, { cause: actual.cause });\n}\n","import { AutomationError } from \"./automation-error\";\n\nexport function safe(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n action: (...args: any[]) => any | Promise<any>,\n ...args: unknown[]\n): AutomationError | undefined | Promise<AutomationError | undefined> {\n const result = action(...args);\n if (result instanceof Promise) {\n return result.catch((e) => e as AutomationError);\n }\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YAAY,SAAwB,OAA0B,CAAC,GAAG;AAGhE,UAAM,SAAS,IAAI;AAHe;AAIlC,SAAK,OAAO;AAAA,EACd;AACF;;;ACJO,SAAS,MACd,SACA,MACO;AACP,QAAM,SAAS,QAAQ,CAAC;AACxB,MAAI,OAAO,QAAQ,OAAO,KAAK,qBAAqB,OAAO;AACzD,UAAM,IAAI,OAAO,KAAK,SAAS,EAAE,OAAO,OAAO,MAAM,CAAC;AAAA,EACxD;AACA,QAAM,IAAI,gBAAgB,SAAS,EAAE,OAAO,OAAO,MAAM,CAAC;AAC5D;;;ACVO,SAAS,KAEd,WACG,MACiE;AACpE,QAAM,SAAS,OAAO,GAAG,IAAI;AAC7B,MAAI,kBAAkB,SAAS;AAC7B,WAAO,OAAO,MAAM,CAAC,MAAM,CAAoB;AAAA,EACjD;AACA,SAAO;AACT;","names":[]} | ||
| {"version":3,"sources":["../src/index.ts","../src/automation-error.ts","../src/raise.ts","../src/safe-error.ts"],"sourcesContent":["export * from \"./automation-error\";\nexport * from \"./raise\";\nexport * from \"./safe-error\";","export class AutomationError extends Error {\n constructor(message: string, public opts: { cause?: Error } = {}) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n super(message, opts);\n this.name = \"AutomationError\";\n }\n}\n","import { AutomationError } from \"./automation-error\";\nimport { Class } from \"@autometa/types\";\n\nexport function raise(\n message: string,\n opts?: { cause?: Error; type?: Class<AutomationError> }\n): never {\n const actual = opts ?? {};\n if (actual.type && actual.type.prototype instanceof Error) {\n throw new actual.type(message, { cause: actual.cause });\n }\n throw new AutomationError(message, { cause: actual.cause });\n}\n","import { AutomationError } from \"./automation-error\";\n\nexport function safe<T>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n action: (...args: any) => T ,\n ...args: unknown[]\n): AutomationError | T {\n try{\n return action(...args);\n } catch (e) {\n return e as AutomationError\n }\n}\n\nexport async function safeAsync<T>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n action: (...args: any) => T | Promise<T>,\n ...args: unknown[]\n): Promise<AutomationError | T> {\n try{\n return await action(...args);\n } catch (e) {\n return e as AutomationError\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YAAY,SAAwB,OAA0B,CAAC,GAAG;AAGhE,UAAM,SAAS,IAAI;AAHe;AAIlC,SAAK,OAAO;AAAA,EACd;AACF;;;ACJO,SAAS,MACd,SACA,MACO;AACP,QAAM,SAAS,QAAQ,CAAC;AACxB,MAAI,OAAO,QAAQ,OAAO,KAAK,qBAAqB,OAAO;AACzD,UAAM,IAAI,OAAO,KAAK,SAAS,EAAE,OAAO,OAAO,MAAM,CAAC;AAAA,EACxD;AACA,QAAM,IAAI,gBAAgB,SAAS,EAAE,OAAO,OAAO,MAAM,CAAC;AAC5D;;;ACVO,SAAS,KAEd,WACG,MACkB;AACrB,MAAG;AACD,WAAO,OAAO,GAAG,IAAI;AAAA,EACvB,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;AAEA,eAAsB,UAEpB,WACG,MAC2B;AAC9B,MAAG;AACD,WAAO,MAAM,OAAO,GAAG,IAAI;AAAA,EAC7B,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;","names":[]} |
+1
-1
| { | ||
| "name": "@autometa/errors", | ||
| "version": "0.1.1", | ||
| "version": "0.1.2", | ||
| "main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/esm/index.js", |
14906
6.87%135
15.38%