{"record":{"id":"276f0e8969662e4d","repo":"linera-io/linera-protocol","slug":"test-log-rust-log-span-events-must-be-valid-utf-8","errorCode":null,"errorMessage":"test-log: RUST_LOG_SPAN_EVENTS must be valid UTF-8","messagePattern":"test-log: RUST_LOG_SPAN_EVENTS must be valid UTF-8","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"linera-storage-service/src/server.rs","lineNumber":611,"sourceCode":"    )]\n    async fn process_delete_all(&self, _request: Request<()>) -> Result<Response<()>, Status> {\n        self.delete_all().await?;\n        Ok(Response::new(()))\n    }\n}\n\n#[tokio::main]\nasync fn main() {\n    let env_filter = tracing_subscriber::EnvFilter::builder()\n        .with_default_directive(tracing_subscriber::filter::LevelFilter::INFO.into())\n        .from_env_lossy();\n    let internal_event_filter = {\n        match std::env::var_os(\"RUST_LOG_SPAN_EVENTS\") {\n            Some(mut value) => {\n                value.make_ascii_lowercase();\n                let value = value\n                    .to_str()\n                    .expect(\"test-log: RUST_LOG_SPAN_EVENTS must be valid UTF-8\");\n                value\n                    .split(',')\n                    .map(|filter| match filter.trim() {\n                        \"new\" => FmtSpan::NEW,\n                        \"enter\" => FmtSpan::ENTER,\n                        \"exit\" => FmtSpan::EXIT,\n                        \"close\" => FmtSpan::CLOSE,\n                        \"active\" => FmtSpan::ACTIVE,\n                        \"full\" => FmtSpan::FULL,\n                        _ => panic!(\"test-log: RUST_LOG_SPAN_EVENTS must contain filters separated by `,`.\\n\\t\\\n                                     For example: `active` or `new,close`\\n\\t\\\n                                     Supported filters: new, enter, exit, close, active, full\\n\\t\\\n                                     Got: {value}\"),\n                    })\n                    .fold(FmtSpan::NONE, |acc, filter| filter | acc)\n            }\n            None => FmtSpan::NONE,\n        }","sourceCodeStart":593,"sourceCodeEnd":629,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-storage-service/src/server.rs#L593-L629","documentation":"linera-storage-service configures tracing-subscriber span events from the RUST_LOG_SPAN_EVENTS variable (filters: new, enter, exit, close, active, full). It reads the variable with std::env::var_os, which returns an OsString because Unix environment variables are arbitrary bytes, then calls .to_str(); that returns None when the bytes are not valid UTF-8, and .expect() panics before the server starts. The 'test-log:' prefix comes from the well-known tokio test-log snippet this code follows.","triggerScenarios":"Starting linera-storage-service with RUST_LOG_SPAN_EVENTS whose raw bytes are non-UTF-8: a latin-1 encoded accented character, a stray 0x80-0xFF byte, or a value injected from a script or .env file saved in a legacy encoding. Pure-ASCII values like `new,close` never trigger it.","commonSituations":"Values written by older Windows shells or PowerShell in a legacy code page; .env files saved by a non-UTF-8 editor; CI variables pasted from rich text with invisible non-UTF-8 bytes; Docker ENV injected from a binary file.","solutions":["Re-set the variable to plain ASCII filters: export RUST_LOG_SPAN_EVENTS=\"new,close\"","Or unset it entirely: None selects FmtSpan::NONE and the server starts normally","Find the offending bytes with `printf '%s' \"$RUST_LOG_SPAN_EVENTS\" | od -c` and look for non-ASCII byte sequences","Re-save the script/.env/CI variable definition as UTF-8"],"exampleFix":"# before: .env saved as latin-1, RUST_LOG_SPAN_EVENTS=\"café,close\" carries 0xE9 bytes -> panic\n# after: UTF-8 file, or ASCII-only value\nexport RUST_LOG_SPAN_EVENTS=\"new,close\"","handlingStrategy":"validation","validationCode":"// Rust launcher: use var() (UTF-8 checked) instead of var_os before spawning the server\nmatch std::env::var(\"RUST_LOG_SPAN_EVENTS\") {\n    Ok(v) => { /* safe: guaranteed valid UTF-8 */ }\n    Err(std::env::VarError::NotUnicode(_)) => { /* clear the variable or abort with a clear message */ }\n    Err(std::env::VarError::NotPresent) => {}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep RUST_LOG_SPAN_EVENTS to ASCII filter names (new, enter, exit, close, active, full)","Save .env and CI variable files as UTF-8","In your own code prefer std::env::var over var_os when a String is required: it returns NotUnicode instead of raw bytes"],"tags":["env-var","utf-8","tracing","startup","rust"],"backgroundTag":"non-utf8-env-var","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}