@stacksjs/error-handling 0.74.29 → 0.74.32

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 (2) hide show
  1. package/dist/handler.js +1 -1
  2. package/package.json +6 -6
package/dist/handler.js CHANGED
@@ -1,4 +1,4 @@
1
- import fs from"node:fs";import{dirname}from"node:path";import*as process from"node:process";function italic(str){return`\x1B[3m${str}\x1B[23m`}function stripAnsi(str){return str.replace(/\x1B\[[0-9;]*m/g,"")}import*as path from"@stacksjs/path";import{ExitCode}from"@stacksjs/types";export class ErrorHandler{static isTestEnvironment=!1;static shouldExitProcess=!1;static handle(err,options){if(!this.isTestEnvironment)this.shouldExitProcess=options?.shouldExit===!0;if(options?.silent!==!0)this.writeErrorToConsole(err);let errorMessage;if(options?.message)errorMessage=options.message;else if(err instanceof Error)errorMessage=err.message;else if(typeof err==="string")errorMessage=err;else errorMessage=JSON.stringify(err);const error=err instanceof Error&&errorMessage===err.message?err:Error(errorMessage,err instanceof Error?{cause:err.cause??err}:void 0);if(err instanceof Error&&error!==err){Object.assign(error,err);if(err.stack)error.stack=`${error.name}: ${errorMessage}
1
+ import fs from"node:fs";import{dirname}from"node:path";import*as process from"node:process";function italic(str){return`\x1B[3m${str}\x1B[23m`}function stripAnsi(str){return str.replace(/\x1B\[[0-9;]*m/g,"")}import*as path from"@stacksjs/path";import{ExitCode}from"@stacksjs/types/exit-code";export class ErrorHandler{static isTestEnvironment=!1;static shouldExitProcess=!1;static handle(err,options){if(!this.isTestEnvironment)this.shouldExitProcess=options?.shouldExit===!0;if(options?.silent!==!0)this.writeErrorToConsole(err);let errorMessage;if(options?.message)errorMessage=options.message;else if(err instanceof Error)errorMessage=err.message;else if(typeof err==="string")errorMessage=err;else errorMessage=JSON.stringify(err);const error=err instanceof Error&&errorMessage===err.message?err:Error(errorMessage,err instanceof Error?{cause:err.cause??err}:void 0);if(err instanceof Error&&error!==err){Object.assign(error,err);if(err.stack)error.stack=`${error.name}: ${errorMessage}
2
2
  ${err.stack.split(`
3
3
  `).slice(1).join(`
4
4
  `)}`}this.writeErrorToFile(error).catch((e)=>console.error(e));return error}static handleError(err,options){this.handle(err,options);return err}static async writeErrorToFile(err,context){if(!(err instanceof Error)){console.error("Error is not an instance of Error:",err);return}const contextStr=context?` | url=${context.url||"N/A"} method=${context.method||"N/A"} user=${context.userId||"anonymous"}`:"",stackLine=err.stack?`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/error-handling",
3
3
  "type": "module",
4
- "version": "0.74.29",
4
+ "version": "0.74.32",
5
5
  "description": "Type safe error handling.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -57,16 +57,16 @@
57
57
  "prepublishOnly": "bun run build"
58
58
  },
59
59
  "dependencies": {
60
- "@stacksjs/path": "0.74.29",
60
+ "@stacksjs/path": "0.74.32",
61
61
  "@stacksjs/stx": "^0.2.274",
62
- "@stacksjs/types": "0.74.29",
62
+ "@stacksjs/types": "0.74.32",
63
63
  "ts-error-handling": "^0.1.1",
64
64
  "ts-syntax-highlighter": "^0.2.1"
65
65
  },
66
66
  "devDependencies": {
67
- "@stacksjs/cli": "0.74.29",
68
- "@stacksjs/config": "0.74.29",
69
- "@stacksjs/validation": "0.74.29",
67
+ "@stacksjs/cli": "0.74.32",
68
+ "@stacksjs/config": "0.74.32",
69
+ "@stacksjs/validation": "0.74.32",
70
70
  "better-dx": "^0.2.24"
71
71
  },
72
72
  "sideEffects": false