Skip to content

Commit 0538c58

Browse files
authored
Fix silent TOML parse errors causing exclude_dir to be ignored (#678) (#852)
1 parent 1cacca5 commit 0538c58

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Config file with duplicate key to trigger parse error
2+
root = "."
3+
4+
[build]
5+
delay = 1000
6+
delay = 2000

runner/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ func defaultPathConfig() (*Config, error) {
256256
return cfg, nil
257257
}
258258

259+
// If the config file exists but failed to parse, report the error
260+
// Only use defaults if no config file exists
261+
if !os.IsNotExist(err) {
262+
return nil, fmt.Errorf("failed to parse %s: %w", dftTOML, err)
263+
}
264+
259265
dftCfg := defaultConfig()
260266
return &dftCfg, nil
261267
}

runner/config_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ func TestReadConfByName(t *testing.T) {
111111
}
112112
}
113113

114+
func TestDefaultPathConfigWithInvalidTOML(t *testing.T) {
115+
// Test that defaultPathConfig returns an error when .air.toml exists but has parse errors
116+
// This is a regression test for issue #678
117+
t.Setenv(airWd, "_testdata/invalid_toml")
118+
_, err := defaultPathConfig()
119+
if err == nil {
120+
t.Fatal("expected error when .air.toml has parse errors, but got nil")
121+
}
122+
if !strings.Contains(err.Error(), "failed to parse") {
123+
t.Fatalf("expected error message to contain 'failed to parse', got: %s", err.Error())
124+
}
125+
if !strings.Contains(err.Error(), "defined twice") {
126+
t.Fatalf("expected error message to contain 'defined twice', got: %s", err.Error())
127+
}
128+
}
129+
114130
func TestConfPreprocess(t *testing.T) {
115131
t.Setenv(airWd, "_testdata/toml")
116132
df := defaultConfig()

0 commit comments

Comments
 (0)