@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.
- package/lib/sfCommand.js +27 -5
- 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
|
-
|
|
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 =
|
|
261
|
-
|
|
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
|
-
|
|
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
|