{"record":{"id":"08562ae70f88cb27","repo":"valeriansaliou/sonic","slug":"cannot-find-config-file-at-custom-path","errorCode":null,"errorMessage":"Cannot find config file at {custom_path:?}","messagePattern":"Cannot find config file at (.+?)","errorType":"validation","errorClass":"panic","httpStatus":null,"severity":"critical","filePath":"server/src/config.rs","lineNumber":124,"sourceCode":"\n        back_compat::migrate_channel_search(&mut server_config.channel, &mut core_config);\n\n        // Validate configuration.\n        core_config.validate();\n\n        Config {\n            channel: server_config.channel,\n            server: server_config.server,\n            sonic: Arc::new(core_config),\n        }\n    }\n}\n\npub fn read_config(custom_path: Option<&str>) -> Config {\n    if let Some(custom_path) = custom_path {\n        // Abort if the user specified a config path that does not exist.\n        if !std::path::Path::new(custom_path).exists() {\n            panic!(\"Cannot find config file at {custom_path:?}\");\n        }\n\n        let path = std::path::absolute(custom_path).unwrap();\n        tracing::debug!(\"reading config file: {path:?}\");\n\n        Config::parse(config::File::from(path).format(config::FileFormat::Toml))\n    } else {\n        for path in DEFAULT_CONFIG_FILE_PATHS {\n            let path = std::path::absolute(path).unwrap();\n            tracing::debug!(\"looking for config file at {path:?}\");\n\n            if path.exists() {\n                tracing::debug!(\"reading config file: {path:?}\");\n\n                return Config::parse(config::File::from(path).format(config::FileFormat::Toml));\n            }\n        }\n","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/valeriansaliou/sonic/blob/e6a72da6a532bc3f31d7d93ef1e0964a1a5d01b2/server/src/config.rs#L106-L142","documentation":"read_config panics when a custom config path was supplied (e.g. via -c/--config) but no file exists at that path. Sonic aborts immediately rather than silently falling back to defaults, because the user explicitly requested that file.","triggerScenarios":"Calling read_config(Some(\"path/to/config.toml\")) where std::path::Path::new(custom_path).exists() is false — typically from main after CLI parsing.","commonSituations":"Typo in the --config flag; relative path from a different working directory; config file deleted or not mounted in a container; wrong file extension/location after a packaging change.","solutions":["Verify the path exists: ls <path> — fix typos or the working directory","Pass an absolute path to the config flag","In containers, ensure the config file is mounted into the image/pod","Omit the custom path to use the default config lookup"],"exampleFix":"// shell\n// before\n./sonic -c ./confg.toml  # typo\n// after\n./sonic -c /etc/sonic/config.toml","handlingStrategy":"validation","validationCode":"let path = std::path::Path::new(custom_path);\nif !path.exists() {\n    return Err(format!(\"config file not found: {}\", custom_path));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use absolute paths in service units/CLI flags","Mount the config explicitly in containers and verify at entrypoint","Check working directory when using relative paths"],"tags":["config","panic","file-not-found","cli"],"backgroundTag":"config-file-not-found","analyzedSha":"e6a72da6a532bc3f31d7d93ef1e0964a1a5d01b2","analyzedAt":"2026-09-01T14:10:00.384Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T20:17:18.057Z"}