devbox
devbox copied to clipboard
[Bug]: `devbox shell` won't run if color codes exist in `init_hook`
Current Behavior (bug) when you try to color error text red, devbox gets pissy.
Expected Behavior (fix) let me make text red
Additional context
# devbox.json
...
"shell": {
"init_hook": [
"RED='\033[0;31m'",
"source parameters/dev.env",
"source parameters/local.env",
"export CI_JOB_TOKEN=$GITLAB_ACCESS_TOKEN",
"aws sts get-caller-identity >& /dev/null || aws configure",
"[ ! -z $GITLAB_USERNAME ] || { echo \"${RED}error: need your gitlab credentials (set GITLAB_USERNAME AND GITLAB_ACCESS_TOKEN)\" >&2; exit 1; }"
],
...
justin$ devbox shell
Info: New devbox available: 0.7.1 -> v0.8.1. Please run `devbox version update`.
Error: invalid character '0' in string escape code
I believe that is a JSON parsing error -- JSON has a different format for backslash escape codes. Since this shell code is within JSON, and you want the shell that runs it (RED='\033[0;31m') to see a literal \, you need to use \\. The \\ specifies a literal \ in JSON.
I have run into similar issues with devbox.json -- it would be very helpful for it to report that the error happened while parsing the JSON. It also would be helpful to get at least a line number for context.