flipped-aurora/gin-vue-admin · critical
fatal error config file: %w
Error message
fatal error config file: %w
What it means
core.Viper bootstraps the global config with spf13/viper at server startup. If v.ReadInConfig fails (file missing, unreadable, malformed YAML), the function panics with this error because the server cannot start without configuration.
Source
Thrown at server/core/viper.go:25
"path/filepath"
"github.com/flipped-aurora/gin-vue-admin/server/core/internal"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/fsnotify/fsnotify"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
)
// Viper 配置
func Viper() *viper.Viper {
config := getConfigPath()
v := viper.New()
v.SetConfigFile(config)
v.SetConfigType("yaml")
err := v.ReadInConfig()
if err != nil {
panic(fmt.Errorf("fatal error config file: %w", err))
}
v.WatchConfig()
v.OnConfigChange(func(e fsnotify.Event) {
fmt.Println("config file changed:", e.Name)
if err = v.Unmarshal(&global.GVA_CONFIG); err != nil {
fmt.Println(err)
}
})
if err = v.Unmarshal(&global.GVA_CONFIG); err != nil {
panic(fmt.Errorf("fatal error unmarshal config: %w", err))
}
// root 适配性 根据root位置去找到对应迁移位置,保证root路径有效
global.GVA_CONFIG.AutoCode.Root, _ = filepath.Abs("..")
return v
}
View on GitHub (pinned to 3136500ef3)
Solutions
- Read the wrapped viper error: it distinguishes 'Config File Not Found' from parse errors
- Ensure config.yaml exists in the directory the server runs from (or fix the path passed to core.Viper)
- Validate YAML syntax after edits before restarting
- Check file readability for the process user (especially in Docker/K8s with mounted configs)
Example fix
// before cd /opt && ./server # config.yaml is in /opt/server // after cd /opt/server && ./server
Defensive patterns
Strategy: validation
Validate before calling
if _, err := os.Stat(configPath); err != nil {
log.Fatalf("config file unreadable before start: %v", err)
} Try / catch
// recover at main level if desired
defer func() {
if r := recover(); r != nil {
log.Fatalf("startup failed: %v", r)
}
}() Prevention
- Always start the server from its working directory or pass an absolute config path
- Validate config.yaml with yamllint in the deploy pipeline
- Ensure configs are copied/mounted correctly in Docker/K8s
When it happens
Trigger: Server startup when config.yaml is absent at the path given to Viper(), unreadable, or contains invalid YAML that viper cannot parse.
Common situations: Running the server binary from the wrong directory so the relative config path is wrong; deploying without copying config.yaml; YAML syntax error after editing; file permission issues in containers.
Related errors
- fatal error unmarshal config: %w
- panic(err) — standalone MCP config load failed
- 未找到 MCP 独立配置文件,请在当前目录、cmd/mcp 目录或通过 -config / GVA_MCP_CONFIG
- 未能自动识别项目根目录,请在 MCP 配置中设置 autocode.root
- 读取 MCP 配置失败: %w
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/6365ec127644663d.
Report an issue: GitHub.