4
4
* Licensed under the BSD 3-Clause license.
5
5
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
6
*/
7
+ import { inspect } from 'node:util' ;
7
8
import { SfError , StructuredMessage } from '@salesforce/core' ;
8
9
import { AnyJson } from '@salesforce/ts-types' ;
9
10
import { computeErrorCode } from './errorHandling.js' ;
10
- import { removeEmpty } from './util.js' ;
11
11
12
12
// These types are 90% the same as SfErrorOptions (but they aren't exported to extend)
13
13
type ErrorDataProperties = AnyJson ;
@@ -25,20 +25,11 @@ export type SfCommandErrorOptions<T extends ErrorDataProperties = ErrorDataPrope
25
25
warnings ?: Array < StructuredMessage | string > ;
26
26
} ;
27
27
28
- type SfCommandErrorJson = {
28
+ type SfCommandErrorJson = SfCommandErrorOptions & {
29
29
name : string ;
30
- message : string ;
31
- exitCode : number ;
32
- commandName : string ;
33
- context : string ;
34
- code : string ;
35
- status : string ;
36
- stack : string ;
37
- actions ?: string ;
38
- data ?: ErrorDataProperties ;
30
+ status : number ;
31
+ stack ?: string ;
39
32
cause ?: string ;
40
- warnings ?: Array < StructuredMessage | string > ;
41
- result ?: unknown ;
42
33
} ;
43
34
44
35
export class SfCommandError extends SfError {
@@ -93,17 +84,15 @@ export class SfCommandError extends SfError {
93
84
94
85
public toJson ( ) : SfCommandErrorJson {
95
86
return {
96
- ...removeEmpty ( {
97
- // toObject() returns name, message, exitCode, actions, context, data
98
- ...this . toObject ( ) ,
99
- stack : this . stack ,
100
- cause : this . cause ,
101
- warnings : this . warnings ,
102
- code : this . code ,
103
- status : this . status ,
104
- commandName : this . commandName ,
105
- result : this . result ,
106
- } ) ,
107
- } as SfCommandErrorJson ;
87
+ // toObject() returns name, message, exitCode, actions, context, data
88
+ ...this . toObject ( ) ,
89
+ stack : this . stack ,
90
+ cause : inspect ( this . cause ) ,
91
+ warnings : this . warnings ,
92
+ code : this . code ,
93
+ status : this . status ,
94
+ commandName : this . commandName ,
95
+ result : this . result ,
96
+ } ;
108
97
}
109
98
}
0 commit comments