Skip to content

Commit

Permalink
refactor: restore nasty type assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Nov 20, 2023
1 parent 93e6a3f commit 9f28d30
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/sfError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { NamedError } from '@salesforce/kit';
import { hasString, isString, JsonMap } from '@salesforce/ts-types';
import { AnyJson, hasString, isString, JsonMap } from '@salesforce/ts-types';

/**
* A generalized sfdx error which also contains an action. The action is used in the
Expand Down Expand Up @@ -132,7 +132,7 @@ export class SfError<T = unknown> extends NamedError {
public toObject(): JsonMap {
const obj: JsonMap = {
name: this.name,
message: this.message || this.name,
message: this.message ?? this.name,
exitCode: this.exitCode,
actions: this.actions,
};
Expand All @@ -142,7 +142,10 @@ export class SfError<T = unknown> extends NamedError {
}

if (this.data) {
obj.data = this.data;
// DANGER: data was previously typed as `unknown` and this assertion was here on the toObject.
// TODO in next major release: put proper type constraint on SfError.data to something that can serialize
// while we're making breaking changes, provide a more definite type for toObject
obj.data = this.data as AnyJson;
}

return obj;
Expand Down

0 comments on commit 9f28d30

Please sign in to comment.