Skip to content
Myr

debugging.md

This file

Path

docs/debugging.md

105 lines · 3.3 KiB · Markdown

Last changed by

Add user guides (#989)ehmickybefore adoptionbe91ecf

History of this file

Take it

Add user guides (#989)ehmickybefore adoptionbe91ecf

lines 1–105why, one step back
1<picture>
2 <source media="(prefers-color-scheme: dark)" srcset="../media/logo_dark.svg">3 <img alt="execa logo" src="../media/logo.svg" width="400">4</picture>5<br>67# 🐛 Debugging89## Command1011[`error.command`](../readme.md#resultcommand) contains the file and [arguments](input.md#command-arguments) that were run. It is intended for logging or debugging.1213[`error.escapedCommand`](../readme.md#resultescapedcommand) 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.1415Since the escaping is fairly basic, neither `error.command` nor `error.escapedCommand` should be executed directly, including using [`execa()`](../readme.md#execafile-arguments-options) or [`execaCommand()`](../readme.md#execacommandcommand-options).1617```js18import {execa} from 'execa';1920try {21 await execa`npm run build\ntask`;22} catch (error) {23 console.error(error.command); // "npm run build\ntask"24 console.error(error.escapedCommand); // "npm run 'build\\ntask'"25 throw error;26}27```2829## Duration3031```js32try {33 const result = await execa`npm run build`;34 console.log('Command duration:', result.durationMs); // 15035} catch (error) {36 console.error('Command duration:', error.durationMs); // 15037 throw error;38}39```4041## Verbose mode4243### Short mode4445When the [`verbose`](../readme.md#optionsverbose) option is `'short'`, the [command](#command), [duration](#duration) and [error messages](errors.md#error-message) are printed on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).4647```js48// build.js49await execa({verbose: 'short'})`npm run build`;50```5152```sh53$ node build.js54[20:36:11.043] [0] $ npm run build55[20:36:11.885] [0] ✔ (done in 842ms)56```5758### Full mode5960When the [`verbose`](../readme.md#optionsverbose) option is `'full'`, the subprocess' [`stdout` and `stderr`](output.md) are also logged. Both are printed on [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)).6162The output is not logged if either:63- The [`stdout`](../readme.md#optionsstdout)/[`stderr`](../readme.md#optionsstderr) option is [`'ignore'`](output.md#ignore-output) or [`'inherit'`](output.md#terminal-output).64- The `stdout`/`stderr` is redirected to [a stream](streams.md#output), [a file](output.md#file-output), [a file descriptor](output.md#terminal-output), or [another subprocess](pipe.md).65- The [`encoding`](../readme.md#optionsencoding) option is [binary](binary.md#binary-output).6667```js68// build.js69await execa({verbose: 'full'})`npm run build`;70```7172```sh73$ node build.js74[20:36:11.043] [0] $ npm run build75Building application...76Done building.77[20:36:11.885] [0] ✔ (done in 842ms)78```7980### Global mode8182When the `NODE_DEBUG=execa` [environment variable](https://en.wikipedia.org/wiki/Environment_variable) is set, the [`verbose`](../readme.md#optionsverbose) option defaults to `'full'` for all commands.8384```js85// build.js8687// This is logged by default88await execa`npm run build`;89// This is not logged90await execa({verbose: 'none'})`npm run test`;91```9293```sh94$ NODE_DEBUG=execa node build.js95[20:36:11.043] [0] $ npm run build96Building application...97Done building.98[20:36:11.885] [0] ✔ (done in 842ms)99```100101<hr>102103[**Next**: 📎 Windows](windows.md)\104[**Previous**: 📞 Inter-process communication](ipc.md)\105[**Top**: Table of contents](../readme.md#documentation)