@dinoxx/dinox-cli 1.0.16 → 1.0.18

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.
@@ -1,10 +1,27 @@
1
+ export type DinoxErrorOptions = {
2
+ exitCode?: number;
3
+ cause?: unknown;
4
+ details?: unknown;
5
+ code?: string;
6
+ suggestion?: string;
7
+ recoverable?: boolean;
8
+ };
9
+ export type StructuredErrorPayload = {
10
+ name: string;
11
+ code: string;
12
+ message: string;
13
+ recoverable: boolean;
14
+ suggestion?: string;
15
+ details?: unknown;
16
+ stack?: string;
17
+ };
1
18
  export declare class DinoxError extends Error {
2
19
  readonly exitCode: number;
3
20
  readonly details?: unknown;
4
- constructor(message: string, options?: {
5
- exitCode?: number;
6
- cause?: unknown;
7
- details?: unknown;
8
- });
21
+ readonly code?: string;
22
+ readonly suggestion?: string;
23
+ readonly recoverable: boolean;
24
+ constructor(message: string, options?: DinoxErrorOptions);
9
25
  }
10
26
  export declare function isDinoxError(error: unknown): error is DinoxError;
27
+ export declare function buildStructuredErrorPayload(error: unknown, verbose: boolean): StructuredErrorPayload;
@@ -1,11 +1,17 @@
1
1
  export class DinoxError extends Error {
2
2
  exitCode;
3
3
  details;
4
+ code;
5
+ suggestion;
6
+ recoverable;
4
7
  constructor(message, options) {
5
8
  super(message);
6
9
  this.name = 'DinoxError';
7
10
  this.exitCode = options?.exitCode ?? 1;
8
11
  this.details = options?.details;
12
+ this.code = options?.code;
13
+ this.suggestion = options?.suggestion;
14
+ this.recoverable = options?.recoverable ?? true;
9
15
  if (options?.cause !== undefined) {
10
16
  // Node 16+ supports Error.cause.
11
17
  this.cause = options.cause;
@@ -15,3 +21,26 @@ export class DinoxError extends Error {
15
21
  export function isDinoxError(error) {
16
22
  return Boolean(error) && typeof error === 'object' && error.name === 'DinoxError';
17
23
  }
24
+ export function buildStructuredErrorPayload(error, verbose) {
25
+ const message = error instanceof Error ? error.message : String(error);
26
+ const name = error instanceof Error ? error.name : 'Error';
27
+ const stack = error instanceof Error ? error.stack : undefined;
28
+ if (isDinoxError(error)) {
29
+ return {
30
+ name,
31
+ code: error.code ?? 'DINOX_ERROR',
32
+ message,
33
+ recoverable: error.recoverable,
34
+ ...(error.suggestion ? { suggestion: error.suggestion } : {}),
35
+ ...(error.details !== undefined ? { details: error.details } : {}),
36
+ ...(verbose && stack ? { stack } : {}),
37
+ };
38
+ }
39
+ return {
40
+ name,
41
+ code: 'INTERNAL_ERROR',
42
+ message,
43
+ recoverable: false,
44
+ ...(verbose && stack ? { stack } : {}),
45
+ };
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dinoxx/dinox-cli",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Dinox CLI",
5
5
  "main": "dist/dinox.js",
6
6
  "scripts": {