PRQL/prql · error · anyhow::Error

debug log was started, but it cannot be found after…

Error message

debug log was started, but it cannot be found after compilation

What it means

`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.

Solutions

  1. Make sure debug logging is initialized (debug::log / the debug flag) before compilation runs
  2. Call write_log only once per compilation
  3. If it reproduces in normal CLI use, file a bug with the command line
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

if let Some(log) = debug::log_finish() { write_log(&path, log)?; } else { eprintln!("debug log unavailable"); }

Prevention

When it happens

Trigger: 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).

Common situations: Invoking `execute` programmatically without calling the log-init step; calling `write_log` twice; a compiler bug where the log was dropped mid-compilation.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of PRQL/prql@e164e249b9 (2026-09-09). Data as JSON: /api/errors/7befa0a734c59c3c. Report an issue: GitHub.

Appendix: source

Thrown at prqlc/prqlc/src/cli/mod.rs:582

        Ok(output.write_all(data)?)
    }
}

fn has_debug_log(cli: &Cli) -> bool {
    matches!(
        cli.command,
        Some(Command::Compile {
            debug_log: Some(_),
            ..
        })
    )
}

pub fn write_log(path: &std::path::Path) -> Result<()> {
    let debug_log = if let Some(debug_log) = debug::log_finish() {
        debug_log
    } else {
        return Err(anyhow!(
            "debug log was started, but it cannot be found after compilation"
        ));
    };
    match path.extension().and_then(|s| s.to_str()) {
        Some("json") => {
            let file = BufWriter::new(File::create(path)?);
            serde_json::to_writer(file, &debug_log)?;
        }
        Some("html") => {
            let file = BufWriter::new(File::create(path)?);
            debug::render_log_to_html(file, &debug_log)?;
        }
        _ => {
            return Err(anyhow!("unknown debug log format for file {path:?}"));
        }
    }
    Ok(())
}

View on GitHub (pinned to e164e249b9)