Skip to content

Commit c120a53

Browse files
committed
fix: better typing
1 parent 2119353 commit c120a53

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

src/SfCommandError.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7+
import { inspect } from 'node:util';
78
import { SfError, StructuredMessage } from '@salesforce/core';
89
import { AnyJson } from '@salesforce/ts-types';
910
import { computeErrorCode } from './errorHandling.js';
10-
import { removeEmpty } from './util.js';
1111

1212
// These types are 90% the same as SfErrorOptions (but they aren't exported to extend)
1313
type ErrorDataProperties = AnyJson;
@@ -25,20 +25,11 @@ export type SfCommandErrorOptions<T extends ErrorDataProperties = ErrorDataPrope
2525
warnings?: Array<StructuredMessage | string>;
2626
};
2727

28-
type SfCommandErrorJson = {
28+
type SfCommandErrorJson = SfCommandErrorOptions & {
2929
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;
3932
cause?: string;
40-
warnings?: Array<StructuredMessage | string>;
41-
result?: unknown;
4233
};
4334

4435
export class SfCommandError extends SfError {
@@ -93,17 +84,15 @@ export class SfCommandError extends SfError {
9384

9485
public toJson(): SfCommandErrorJson {
9586
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+
};
10897
}
10998
}

0 commit comments

Comments
 (0)