{"record":{"id":"cf8980b93dca4ad7","repo":"valeriansaliou/sonic","slug":"invalid-log-level","errorCode":null,"errorMessage":"invalid log level","messagePattern":"invalid log level","errorType":"validation","errorClass":"panic","httpStatus":null,"severity":"error","filePath":"server/src/main.rs","lineNumber":98,"sourceCode":"        .about(clap::crate_description!())\n        .arg(\n            Arg::new(\"config\")\n                .short('c')\n                .long(\"config\")\n                .help(\"Path to configuration file\"),\n        )\n        .get_matches();\n\n    // Generate owned app arguments\n    AppArgs {\n        config: matches.get_one::<String>(\"config\").cloned(),\n    }\n}\n\nfn main() {\n    ConfigLogger::init(\n        std::env::var(\"SONIC_SERVER__LOG_LEVEL\")\n            .map(|level| LevelFilter::from_str(&level).expect(\"invalid log level\"))\n            .unwrap_or(LevelFilter::DEBUG),\n    );\n\n    let app_args = make_app_args();\n\n    let app_conf = read_config(app_args.config.as_deref());\n\n    ConfigLogger::update(\n        LevelFilter::from_str(&app_conf.server.log_level).expect(\"invalid log level\"),\n    );\n\n    // Validate the app configuration.\n    {\n        let invalid_stopwords = (app_conf.sonic.stopwords.allow)\n            .intersection(&app_conf.sonic.stopwords.deny)\n            .collect::<Vec<_>>();\n        if !invalid_stopwords.is_empty() {\n            tracing::error!(invalid = ?invalid_stopwords, \"Some stopwords are both allowed and denied. Fix your `stopwords` configuration.\");","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/valeriansaliou/sonic/blob/e6a72da6a532bc3f31d7d93ef1e0964a1a5d01b2/server/src/main.rs#L80-L116","documentation":"In main(), the startup log level is read from the SONIC_SERVER__LOG_LEVEL environment variable and parsed with LevelFilter::from_str; an unrecognized value panics with \"invalid log level\" before the server even starts. The value must be a valid log crate level name.","triggerScenarios":"Setting SONIC_SERVER__LOG_LEVEL to anything other than off/error/warn/info/debug/trace (case variations like DEBUG are accepted by from_str; arbitrary words or numbers are not).","commonSituations":"Typos in env var value (\"verbose\", \"5\"); copy-pasted values with surrounding whitespace/quotes; CI or Kubernetes manifests exporting an invalid default.","solutions":["Set SONIC_SERVER__LOG_LEVEL to one of: off, error, warn, info, debug, trace","Trim whitespace and remove enclosing quotes from the env value","Unset the variable to fall back to the default DEBUG level","Note: after config load the log_level config field is parsed the same way — make both consistent"],"exampleFix":"// before\nexport SONIC_SERVER__LOG_LEVEL=verbose\n// after\nexport SONIC_SERVER__LOG_LEVEL=debug","handlingStrategy":"validation","validationCode":"// Rust/shell: validate before launch\nLEVEL=\"${SONIC_SERVER__LOG_LEVEL:-debug}\"\ncase \"${LEVEL,,}\" in off|error|warn|info|debug|trace) ;; *) echo \"invalid log level: $LEVEL\"; exit 1;; esac","typeGuard":"fn is_valid_level(s: &str) -> bool {\n    matches!(s.to_ascii_lowercase().as_str(), \"off\"|\"error\"|\"warn\"|\"info\"|\"debug\"|\"trace\")\n}","tryCatchPattern":"let level = LevelFilter::from_str(&raw).unwrap_or(LevelFilter::DEBUG); // or log + exit instead of expect","preventionTips":["Only set SONIC_SERVER__LOG_LEVEL to off/error/warn/info/debug/trace","Trim whitespace and avoid quoting issues in env manifests","Add a startup lint in your deployment scripts for the env value","Keep env value and config file log_level consistent"],"tags":["rust","configuration","logging","environment"],"backgroundTag":"invalid-log-level","analyzedSha":"e6a72da6a532bc3f31d7d93ef1e0964a1a5d01b2","analyzedAt":"2026-09-01T14:10:00.384Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T20:17:18.057Z"}