{"record":{"id":"7befa0a734c59c3c","repo":"PRQL/prql","slug":"debug-log-was-started-but-it-cannot-be-found-afte","errorCode":null,"errorMessage":"debug log was started, but it cannot be found after compilation","messagePattern":"debug log was started, but it cannot be found after compilation","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"prqlc/prqlc/src/cli/mod.rs","lineNumber":582,"sourceCode":"        Ok(output.write_all(data)?)\n    }\n}\n\nfn has_debug_log(cli: &Cli) -> bool {\n    matches!(\n        cli.command,\n        Some(Command::Compile {\n            debug_log: Some(_),\n            ..\n        })\n    )\n}\n\npub fn write_log(path: &std::path::Path) -> Result<()> {\n    let debug_log = if let Some(debug_log) = debug::log_finish() {\n        debug_log\n    } else {\n        return Err(anyhow!(\n            \"debug log was started, but it cannot be found after compilation\"\n        ));\n    };\n    match path.extension().and_then(|s| s.to_str()) {\n        Some(\"json\") => {\n            let file = BufWriter::new(File::create(path)?);\n            serde_json::to_writer(file, &debug_log)?;\n        }\n        Some(\"html\") => {\n            let file = BufWriter::new(File::create(path)?);\n            debug::render_log_to_html(file, &debug_log)?;\n        }\n        _ => {\n            return Err(anyhow!(\"unknown debug log format for file {path:?}\"));\n        }\n    }\n    Ok(())\n}","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/PRQL/prql/blob/e164e249b99485890036eb60f57c37520379b240/prqlc/prqlc/src/cli/mod.rs#L564-L600","documentation":"`write_log` serializes the debug log accumulated during compilation. The log is started via a debug flag and collected at `log_finish()`; if compilation never started (or already consumed) the log, `log_finish` returns None and this error is raised. It signals a mismatch between the debug-logging lifecycle and the write step.","triggerScenarios":"Calling the CLI with a `--debug-log` style path but the debug log was never initialized (e.g. `debug::log` not started before compilation, or finish already called once).","commonSituations":"Invoking `execute` programmatically without calling the log-init step; calling `write_log` twice; a compiler bug where the log was dropped mid-compilation.","solutions":["Make sure debug logging is initialized (debug::log / the debug flag) before compilation runs","Call write_log only once per compilation","If it reproduces in normal CLI use, file a bug with the command line"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"if let Some(log) = debug::log_finish() { write_log(&path, log)?; } else { eprintln!(\"debug log unavailable\"); }","preventionTips":["Initialize debug logging once before compilation and finish it exactly once","Wrap log-start/finish in a guard type","Only request --debug-log output when logging was enabled"],"tags":["cli","debug-logging","internal-error"],"backgroundTag":"internal-invariant-violation","analyzedSha":"e164e249b99485890036eb60f57c37520379b240","analyzedAt":"2026-09-09T12:18:38.727Z","contentChangedAt":"2026-09-09T12:18:38.727Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}