From 9f28d303dbecee086741f5a74a6317efb5f9ef74 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 20 Nov 2023 16:28:49 -0600 Subject: [PATCH] refactor: restore nasty type assertion --- src/sfError.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/sfError.ts b/src/sfError.ts index a6004df07c..390a550285 100644 --- a/src/sfError.ts +++ b/src/sfError.ts @@ -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 @@ -132,7 +132,7 @@ export class SfError 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, }; @@ -142,7 +142,10 @@ export class SfError 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;