If no config file is specified on the command line and .air.toml has any parse error, then the file is completely ignored, and no error is reported.
I discovered this with an error I made in in regex escaping, but any parse error behaves the same, and it makes diagnosing the config file problem very hard. I ended up having to make an instrumented build of air, which is how I found this bug.
This is literally the first time I've ever even tried air, so excuse me if this is somehow well-known behaviour.
Steps to reproduce:
mkdir testdir ; cd testdir
air init
Make a change to the .air.toml so we can tell it's being read. e.g. change build.cmd to "echo hello", or color.runner to "blue"
run air to see the config change
add an error to the .air.toml file. e.g., remove a close bracket: sed -i.bak '/exclude_dir/s/]$//' .air.toml
run air again and see that no error is reported for the file parse failure, but the config changes we made above are not applied
Cause
The problem seems to be in the defaultPathConfig function. This function loops over the default file names and early returns if one of them parses successfully. If neither of them parses it returns the default config. It is assuming that the only errors possible in loading a config file are that the file doesn't exist, so the error is not reported and moves on.
I'm just returning to go after a several-year absence, so I'm not yet confident enough to submit a PR, but I think this should probably be handled by examining the err returned by readConfByName and, if it's not a "file not found" then reporting the error and aborting.
In the example above, the error just before the end of the loop is: &errors.errorString{s:"(11, 3): missing comma"}. This isn't perfect, but in combination with something like "Failed to parse config file .air.toml: " it would have saved me a lot of time.
If no config file is specified on the command line and
.air.toml
has any parse error, then the file is completely ignored, and no error is reported.I discovered this with an error I made in in regex escaping, but any parse error behaves the same, and it makes diagnosing the config file problem very hard. I ended up having to make an instrumented build of air, which is how I found this bug.
This is literally the first time I've ever even tried air, so excuse me if this is somehow well-known behaviour.
Steps to reproduce:
mkdir testdir ; cd testdir
air init
.air.toml
so we can tell it's being read. e.g. changebuild.cmd
to"echo hello"
, orcolor.runner
to"blue"
air
to see the config change.air.toml
file. e.g., remove a close bracket:sed -i.bak '/exclude_dir/s/]$//' .air.toml
air
again and see that no error is reported for the file parse failure, but the config changes we made above are not appliedCause
The problem seems to be in the
defaultPathConfig
function. This function loops over the default file names and early returns if one of them parses successfully. If neither of them parses it returns the default config. It is assuming that the only errors possible in loading a config file are that the file doesn't exist, so the error is not reported and moves on.I'm just returning to go after a several-year absence, so I'm not yet confident enough to submit a PR, but I think this should probably be handled by examining the
err
returned byreadConfByName
and, if it's not a "file not found" then reporting the error and aborting.In the example above, the error just before the end of the loop is:
&errors.errorString{s:"(11, 3): missing comma"}
. This isn't perfect, but in combination with something like "Failed to parse config file .air.toml: " it would have saved me a lot of time.