deepwiki-lab
Relevant source files
  • docs/debugging.md
  • lib/return/final-error.js
  • test-d/arguments/env.test-d.ts
  • docs/bash.md

Debugging Execa Applications

Command

Execa provides two properties on the error object: command and escapedCommand. These properties contain the file and arguments that were run. They are intended for logging or debugging.

command contains the file and arguments as they were passed to the subprocess, without any escaping.

escapedCommand is the same, except control characters are escaped. This makes it safe to either print or copy and paste in a terminal, for debugging purposes.

Duration

The durationMs property on the error object contains the duration of the subprocess in milliseconds.

Verbose Mode

Execa provides a verbose option that can be used to print more information about the subprocess. There are three modes:

  • short: prints the command, duration, and error messages on stderr.
  • full: prints the subprocess' stdout, stderr, and IPC messages on stderr.
  • none: does not print any information.

Custom Logging

The verbose option can also be a function that customizes logging. It is called once per log line, and can return a string to be printed on stderr, or undefined to suppress the log line.

Example

import {execa} from 'execa';

const execa = execa({
	verbose(verboseLine, {type}) {
		return type === 'duration' ? verboseLine : undefined;
	},
});

try {
	await execa`npm run build`;
} catch (error) {
	console.error(error);
}

Advanced Logging

Execa also provides a verbose option that can be a function that takes an object with more information about the log line. This can be used to customize the logging format.

Example

import {execa} from 'execa';

const execa = execa({
	verbose(verboseLine, verboseObject) {
		return JSON.stringify(verboseObject);
	},
});

try {
	await execa`npm run build`;
} catch (error) {
	console.error(error);
}

Sources:

docs/debugging.md lib/return/final-error.js test-d/arguments/env.test-d.ts docs/bash.md