@salesforce/sf-plugins-core 2.2.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/sfCommand.js +27 -5
  2. package/package.json +1 -1
package/lib/sfCommand.js CHANGED
@@ -255,11 +255,19 @@ class SfCommand extends core_1.Command {
255
255
  }
256
256
  async catch(error) {
257
257
  // transform an unknown error into one that conforms to the interface
258
- const codeFromError = error instanceof core_2.SfError ? error.exitCode : 1;
258
+ // @ts-expect-error because exitCode is not on Error
259
+ const codeFromError = error.exitCode ?? 1;
259
260
  process.exitCode ?? (process.exitCode = codeFromError);
260
- const sfErrorProperties = error instanceof core_2.SfError
261
- ? { data: error.data, actions: error.actions, code: codeFromError, context: error.context }
262
- : {};
261
+ const sfErrorProperties = removeEmpty({
262
+ // @ts-expect-error because data is not on Error
263
+ data: error.data ?? null,
264
+ // @ts-expect-error because actions is not on Error
265
+ actions: error.actions ?? null,
266
+ code: codeFromError,
267
+ // @ts-expect-error because context is not on Error
268
+ context: error.context ?? null,
269
+ });
270
+ // Create printable error object
263
271
  const sfCommandError = {
264
272
  ...sfErrorProperties,
265
273
  ...{
@@ -276,7 +284,17 @@ class SfCommand extends core_1.Command {
276
284
  else {
277
285
  this.logToStderr(this.formatError(sfCommandError));
278
286
  }
279
- return sfCommandError;
287
+ // Create SfError that can be thrown
288
+ const err = new core_2.SfError(error.message, error.name ?? 'Error',
289
+ // @ts-expect-error because actions is not on Error
290
+ error.actions ?? [], process.exitCode);
291
+ err.context = sfCommandError.context;
292
+ err.stack = sfCommandError.stack;
293
+ // @ts-expect-error because code is not on SfError
294
+ err.code = codeFromError;
295
+ // @ts-expect-error because code is not on SfError
296
+ err.status = sfCommandError.status;
297
+ throw err;
280
298
  }
281
299
  /**
282
300
  * Format errors and actions for human consumption. Adds 'Error (<ErrorCode>):',
@@ -335,4 +353,8 @@ SfCommand.enableJsonFlag = true;
335
353
  * ```
336
354
  */
337
355
  SfCommand.tableFlags = core_1.ux.table.flags;
356
+ function removeEmpty(obj) {
357
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
358
+ return Object.fromEntries(Object.entries(obj).filter(([_, v]) => v != null));
359
+ }
338
360
  //# sourceMappingURL=sfCommand.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/sf-plugins-core",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "Utils for writing Salesforce CLI plugins",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",