ShellError represents an error that occurred while executing a shell command with the Bun Shell.
Symbol
$.ShellError.constructor
Referenced types
class ShellError
try {
const result = await $`exit 1`;
} catch (error) {
if (error instanceof ShellError) {
console.log(error.exitCode); // 1
}
}
- static prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any
Optional override for formatting stack traces
Read from stdout as an ArrayBuffer
@returnsStdout as an ArrayBuffer
const output = await $`echo hello`; console.log(output.arrayBuffer()); // ArrayBuffer { byteLength: 6 }
Read from stdout as an Uint8Array
@returnsStdout as an Uint8Array
const output = await $`echo hello`; console.log(output.bytes()); // Uint8Array { byteLength: 6 }
Read from stdout as a JSON object
@returnsStdout as a JSON object
const output = await $`echo '{"hello": 123}'`; console.log(output.json()); // { hello: 123 }
Read from stdout as a string
@param encodingThe encoding to use when decoding the output
@returnsStdout as a string with the given encoding
Read as UTF-8 string
const output = await $`echo hello`; console.log(output.text()); // "hello\n"
Read as base64 string
const output = await $`echo ${atob("hello")}`; console.log(output.text("base64")); // "hello\n"
- targetObject: object,constructorOpt?: Function): void;
Create .stack property on a target object