1 | import { NamedError } from '@salesforce/kit';
|
2 | import { JsonMap } from '@salesforce/ts-types';
|
3 | /**
|
4 | * A generalized sfdx error which also contains an action. The action is used in the
|
5 | * CLI to help guide users past the error.
|
6 | *
|
7 | * To throw an error in a synchronous function you must either pass the error message and actions
|
8 | * directly to the constructor, e.g.
|
9 | *
|
10 | * ```
|
11 | * // To load a message bundle (Note that __dirname should contain a messages folder)
|
12 | * Messages.importMessagesDirectory(__dirname);
|
13 | * const messages = Messages.load('myPackageName', 'myBundleName');
|
14 | *
|
15 | * // To throw a non-bundle based error:
|
16 | * throw new SfError(message.getMessage('myError'), 'MyErrorName');
|
17 | * ```
|
18 | */
|
19 | export declare class SfError extends NamedError {
|
20 | /**
|
21 | * Action messages. Hints to the users regarding what can be done to fix related issues.
|
22 | */
|
23 | actions?: string[];
|
24 | /**
|
25 | * SfdxCommand can return this process exit code.
|
26 | */
|
27 | exitCode: number;
|
28 | /**
|
29 | * The related context for this error.
|
30 | */
|
31 | context?: string;
|
32 | data?: unknown;
|
33 | /**
|
34 | * Some errors support `error.code` instead of `error.name`. This keeps backwards compatability.
|
35 | */
|
36 | private _code?;
|
37 | /**
|
38 | * Create an SfError.
|
39 | *
|
40 | * @param message The error message.
|
41 | * @param name The error name. Defaults to 'SfError'.
|
42 | * @param actions The action message(s).
|
43 | * @param exitCodeOrCause The exit code which will be used by SfdxCommand or he underlying error that caused this error to be raised.
|
44 | * @param cause The underlying error that caused this error to be raised.
|
45 | */
|
46 | constructor(message: string, name?: string, actions?: string[], exitCodeOrCause?: number | Error, cause?: Error);
|
47 | /**
|
48 | * Convert an Error to an SfError.
|
49 | *
|
50 | * @param err The error to convert.
|
51 | */
|
52 | static wrap(err: Error | string): SfError;
|
53 | get code(): string | undefined | any;
|
54 | set code(code: string);
|
55 | /**
|
56 | * Sets the context of the error. For convenience `this` object is returned.
|
57 | *
|
58 | * @param context The command name.
|
59 | */
|
60 | setContext(context: string): SfError;
|
61 | /**
|
62 | * An additional payload for the error. For convenience `this` object is returned.
|
63 | *
|
64 | * @param data The payload data.
|
65 | */
|
66 | setData(data: unknown): SfError;
|
67 | /**
|
68 | * Convert an {this error.
SfError} state to an object. Returns a plain object representing the state of |
69 | */
|
70 | toObject(): JsonMap;
|
71 | }
|
72 | /**
|
73 | * @deprecated use SfError instead
|
74 | */
|
75 | export declare class SfdxError extends SfError {
|
76 | }
|