Skip to content

Class: JsonOutputError ​

Error raised by the global options plugin for the JSON output, when a command is given --json.

  • err:json:not-supported: the command does not spread jsonArgs. It is raised before the command runs, and thrown in an AggregateError, as the argument errors are.
  • err:json:invalid-result: the command finished, but did not return an object to output as JSON
  • err:json:unserializable-result: the command finished, but its result cannot be converted to JSON, such as an object with a BigInt

The plugin prints it as one line of JSON to stderr, and cli() resolves with undefined. For err:json:not-supported, with renderValidationErrors: null or usageSilent, nothing is printed and cli() rejects with the AggregateError, as it does for the argument errors.

Use isJsonOutputError to tell it, since each package bundles its own copy of this class.

Extends ​

  • Error

Signature ​

ts
export class JsonOutputError extends Error

Constructors ​

Constructor ​

ts
new JsonOutputError(message: string, options: JsonOutputErrorOptions): JsonOutputError;

Create an error of the JSON output.

Parameters ​

NameTypeDescription
messagestringFallback error message
optionsJsonOutputErrorOptionsThe code of the error, and the values of its message

Returns ​

JsonOutputError

Properties ​

NameTypeDescription
code (readonly)JsonOutputErrorCodeThe code of the error, which is also the resource key of its message.
values (readonly)Record<string, unknown>Values used when localizing the message.

Released under the MIT License.