🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@autometa/errors

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@autometa/errors - npm Package Compare versions

Comparing version
0.2.1
to
0.2.2
+6
-0
CHANGELOG.md
# Gherkin
## 0.2.2
### Patch Changes
- 3fe2ad4: fix: revert dependency change on errors (breaks with jest)
## 0.2.1

@@ -4,0 +10,0 @@

+20
-2

@@ -36,6 +36,24 @@ // src/automation-error.ts

// src/formatter.ts
import mergeErrorCause from "merge-error-cause";
function formatErrorCauses(error) {
return mergeErrorCause(error);
const arr = [];
arr.push(formatError(error));
let err = error;
if (!("cause" in err)) {
return arr.join("");
}
while ("cause" in err && err?.cause) {
const { cause } = err;
if (!(cause instanceof Error)) {
arr.push(cause);
}
arr.push(formatError(cause));
err = err.cause;
}
return arr.join("\nCause:\n");
}
function formatError(error) {
return `${error.name}: ${error.message}
Stacktrace:
${error.stack}`;
}
export {

@@ -42,0 +60,0 @@ AutomationError,

+1
-1

@@ -1,1 +0,1 @@

{"version":3,"sources":["../../src/automation-error.ts","../../src/raise.ts","../../src/safe-error.ts","../../src/formatter.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","import { AutomationError } from \"./automation-error\";\nimport mergeErrorCause from \"merge-error-cause\";\nexport function formatErrorCauses(error: AutomationError) {\n return mergeErrorCause(error);\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;;;ACvBA,OAAO,qBAAqB;AACrB,SAAS,kBAAkB,OAAwB;AACxD,SAAO,gBAAgB,KAAK;AAC9B;","names":[]}
{"version":3,"sources":["../../src/automation-error.ts","../../src/raise.ts","../../src/safe-error.ts","../../src/formatter.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","import { AutomationError } from \"./automation-error\";\n\nexport function formatErrorCauses(error: AutomationError) {\n const arr: string[] = [];\n arr.push(formatError(error));\n let err = error;\n if(!('cause' in err)){\n return arr.join('');\n }\n while ('cause' in err && err?.cause) {\n const { cause } = err as { cause: AutomationError };\n if (!(cause instanceof Error)) {\n arr.push(cause);\n }\n arr.push(formatError(cause));\n err = err.cause as AutomationError;\n }\n return arr.join(\"\\nCause:\\n\");\n}\n\nfunction formatError(error: Error) {\n return `${error.name}: ${error.message}\nStacktrace:\n${error.stack}`;\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;;;ACtBO,SAAS,kBAAkB,OAAwB;AACxD,QAAM,MAAgB,CAAC;AACvB,MAAI,KAAK,YAAY,KAAK,CAAC;AAC3B,MAAI,MAAM;AACV,MAAG,EAAE,WAAW,MAAK;AACnB,WAAO,IAAI,KAAK,EAAE;AAAA,EACpB;AACA,SAAO,WAAW,OAAO,KAAK,OAAO;AACnC,UAAM,EAAE,MAAM,IAAI;AAClB,QAAI,EAAE,iBAAiB,QAAQ;AAC7B,UAAI,KAAK,KAAK;AAAA,IAChB;AACA,QAAI,KAAK,YAAY,KAAK,CAAC;AAC3B,UAAM,IAAI;AAAA,EACZ;AACD,SAAO,IAAI,KAAK,YAAY;AAC7B;AAEA,SAAS,YAAY,OAAc;AACjC,SAAO,GAAG,MAAM,IAAI,KAAK,MAAM,OAAO;AAAA;AAAA,EAEtC,MAAM,KAAK;AACb;","names":[]}

@@ -20,4 +20,4 @@ import { Class } from '@autometa/types';

declare function formatErrorCauses(error: AutomationError): Omit<AutomationError, "cause"> & Error;
declare function formatErrorCauses(error: AutomationError): string;
export { AutomationError, formatErrorCauses, raise, safe, safeAsync };

@@ -20,4 +20,4 @@ import { Class } from '@autometa/types';

declare function formatErrorCauses(error: AutomationError): Omit<AutomationError, "cause"> & Error;
declare function formatErrorCauses(error: AutomationError): string;
export { AutomationError, formatErrorCauses, raise, safe, safeAsync };
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;

@@ -20,10 +18,2 @@ var __export = (target, all) => {

};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

@@ -77,6 +67,24 @@

// src/formatter.ts
var import_merge_error_cause = __toESM(require("merge-error-cause"), 1);
function formatErrorCauses(error) {
return (0, import_merge_error_cause.default)(error);
const arr = [];
arr.push(formatError(error));
let err = error;
if (!("cause" in err)) {
return arr.join("");
}
while ("cause" in err && err?.cause) {
const { cause } = err;
if (!(cause instanceof Error)) {
arr.push(cause);
}
arr.push(formatError(cause));
err = err.cause;
}
return arr.join("\nCause:\n");
}
function formatError(error) {
return `${error.name}: ${error.message}
Stacktrace:
${error.stack}`;
}
// Annotate the CommonJS export names for ESM import in node:

@@ -83,0 +91,0 @@ 0 && (module.exports = {

@@ -1,1 +0,1 @@

{"version":3,"sources":["../src/index.ts","../src/automation-error.ts","../src/raise.ts","../src/safe-error.ts","../src/formatter.ts"],"sourcesContent":["export * from \"./automation-error\";\nexport * from \"./raise\";\nexport * from \"./safe-error\";\nexport * from './formatter'","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","import { AutomationError } from \"./automation-error\";\nimport mergeErrorCause from \"merge-error-cause\";\nexport function formatErrorCauses(error: AutomationError) {\n return mergeErrorCause(error);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;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;;;ACvBA,+BAA4B;AACrB,SAAS,kBAAkB,OAAwB;AACxD,aAAO,yBAAAA,SAAgB,KAAK;AAC9B;","names":["mergeErrorCause"]}
{"version":3,"sources":["../src/index.ts","../src/automation-error.ts","../src/raise.ts","../src/safe-error.ts","../src/formatter.ts"],"sourcesContent":["export * from \"./automation-error\";\nexport * from \"./raise\";\nexport * from \"./safe-error\";\nexport * from './formatter'","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","import { AutomationError } from \"./automation-error\";\n\nexport function formatErrorCauses(error: AutomationError) {\n const arr: string[] = [];\n arr.push(formatError(error));\n let err = error;\n if(!('cause' in err)){\n return arr.join('');\n }\n while ('cause' in err && err?.cause) {\n const { cause } = err as { cause: AutomationError };\n if (!(cause instanceof Error)) {\n arr.push(cause);\n }\n arr.push(formatError(cause));\n err = err.cause as AutomationError;\n }\n return arr.join(\"\\nCause:\\n\");\n}\n\nfunction formatError(error: Error) {\n return `${error.name}: ${error.message}\nStacktrace:\n${error.stack}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;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;;;ACtBO,SAAS,kBAAkB,OAAwB;AACxD,QAAM,MAAgB,CAAC;AACvB,MAAI,KAAK,YAAY,KAAK,CAAC;AAC3B,MAAI,MAAM;AACV,MAAG,EAAE,WAAW,MAAK;AACnB,WAAO,IAAI,KAAK,EAAE;AAAA,EACpB;AACA,SAAO,WAAW,OAAO,KAAK,OAAO;AACnC,UAAM,EAAE,MAAM,IAAI;AAClB,QAAI,EAAE,iBAAiB,QAAQ;AAC7B,UAAI,KAAK,KAAK;AAAA,IAChB;AACA,QAAI,KAAK,YAAY,KAAK,CAAC;AAC3B,UAAM,IAAI;AAAA,EACZ;AACD,SAAO,IAAI,KAAK,YAAY;AAC7B;AAEA,SAAS,YAAY,OAAc;AACjC,SAAO,GAAG,MAAM,IAAI,KAAK,MAAM,OAAO;AAAA;AAAA,EAEtC,MAAM,KAAK;AACb;","names":[]}
{
"name": "@autometa/errors",
"version": "0.2.1",
"version": "0.2.2",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "module": "dist/esm/index.js",