Skip to content

Commit 791fa83

Browse files
michaelmcneesclaude
andcommitted
fix: config loader ignores implicit file errors to avoid reading binary
Viper's config search (SetConfigName + AddConfigPath) could find the compiled mantle binary instead of mantle.yaml, causing a YAML parse error. When no --config flag is provided, silently fall back to defaults on any ReadInConfig error. Explicit --config still hard-errors. Also updates README Configuration section to clarify that mantle.yaml is optional with a table of defaults, env vars, and CLI flags. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent abc32ad commit 791fa83

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ steps:
119119

120120
## Configuration
121121

122-
Mantle reads configuration from `mantle.yaml`, environment variables, and CLI flags (highest precedence).
122+
Mantle reads configuration from `mantle.yaml`, environment variables, and CLI flags (highest precedence). A config file is **optional** — if none is found, Mantle uses sensible defaults that work with the docker-compose setup out of the box.
123+
124+
To create a config file, add `mantle.yaml` to your working directory:
123125

124126
```yaml
125127
database:
@@ -132,11 +134,17 @@ log:
132134
level: info
133135
```
134136

135-
Environment variables use the `MANTLE_` prefix:
137+
The values shown above are the defaults. You only need to create this file if you want to override them.
138+
139+
You can also override any setting with environment variables (`MANTLE_` prefix) or CLI flags:
140+
141+
| Setting | Default | Env Var | CLI Flag |
142+
|---------|---------|---------|----------|
143+
| Database URL | `postgres://mantle:mantle@localhost:5432/mantle?sslmode=disable` | `MANTLE_DATABASE_URL` | `--database-url` |
144+
| API address | `:8080` | `MANTLE_API_ADDRESS` | `--api-address` |
145+
| Log level | `info` | `MANTLE_LOG_LEVEL` | `--log-level` |
136146

137-
- `MANTLE_DATABASE_URL`
138-
- `MANTLE_API_ADDRESS`
139-
- `MANTLE_LOG_LEVEL`
147+
Override precedence (highest to lowest): CLI flags > environment variables > config file > defaults.
140148

141149
## Architecture
142150

internal/config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ func Load(cmd *cobra.Command) (*Config, error) {
6767
// Explicit --config path: hard error
6868
return nil, err
6969
}
70-
// No explicit path: ignore file-not-found, fail on parse errors
71-
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
72-
return nil, err
73-
}
70+
// No explicit path: silently ignore all errors.
71+
// Viper may find non-config files matching the name (e.g., the mantle binary)
72+
// and fail to parse them. Since no config file was explicitly requested,
73+
// falling back to defaults is always safe.
7474
}
7575

7676
// Env vars — explicit binding for nested keys

0 commit comments

Comments
 (0)