Add a new cmd type that wraps exec.Cmd and provides better error handling when a Nix command fails.
Calls to commandContext, exec.Command and exec.CommandContext are consolidated into the command function, which now returns a *cmd instead of an *exec.Cmd. The cmd.Run and related methods return an error that provides more detail about the command in the following format:
The shell command in the error is a properly-escaped shell string that can be copy/pasted to re-run the command.
If Nix prints a line with the prefix "error: " to stderr, then the error will include that line in its message. If there are multiple lines with that prefix, it only includes the last one. Otherwise, it will include exec.ExitError.Stderr with control characters escaped.
When the command exits on its own, the error includes the exit code. If a signal (either from Devbox or the system) terminates the command, the error includes the signal name instead of a -1 exit code.
Below are some examples of how errors will look in logs and Sentry.
Missing package:
nix: command error: nix --extra-experimental-features ca-derivations --option experimental-features 'nix-command flakes fetch-closure' search 'flake:nixpkgs#torpalorp' ^ --json: flake 'flake:nixpkgs' does not provide attribute 'packages.aarch64-darwin.torpalorp', 'legacyPackages.aarch64-darwin.torpalorp' or 'torpalorp': exit code 1
Add a new
cmd
type that wrapsexec.Cmd
and provides better error handling when a Nix command fails.Calls to
commandContext
,exec.Command
andexec.CommandContext
are consolidated into thecommand
function, which now returns a*cmd
instead of an*exec.Cmd
. Thecmd.Run
and related methods return an error that provides more detail about the command in the following format:The shell command in the error is a properly-escaped shell string that can be copy/pasted to re-run the command.
If Nix prints a line with the prefix "error: " to stderr, then the error will include that line in its message. If there are multiple lines with that prefix, it only includes the last one. Otherwise, it will include
exec.ExitError.Stderr
with control characters escaped.When the command exits on its own, the error includes the exit code. If a signal (either from Devbox or the system) terminates the command, the error includes the signal name instead of a -1 exit code.
Below are some examples of how errors will look in logs and Sentry.
Missing package:
Bad flake reference:
Killed process: