PRQL/prql · error · anyhow::Error

failed to compile

Error message

failed to compile

What it means

In watch mode, `compile_path` compiles a PRQL file and prints each diagnostic; when `prqlc::compile` returns errors it collapses them into a generic anyhow error. The detailed messages were already printed to stdout; this error propagates the failure up so the watcher keeps the file marked as failed.

Solutions

  1. Fix the PRQL syntax/semantics using the printed diagnostics above the error
  2. Run `prqlc compile <file>` once (without watch) to see full error spans
  3. Verify the query compiles before enabling the watcher
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

match prqlc::compile(&src, opt) { Ok(sql) => sql, Err(errs) => { print_all(&errs.inner); return Err(anyhow!("failed to compile")); } }

Prevention

When it happens

Trigger: Saving a watched `.prql` file that fails to compile (syntax, semantic, or target/dialect errors).

Common situations: Live-editing a query and introducing a typo; watch session started against a file with errors; schema/table references not available to the compiler.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


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

Appendix: source

Thrown at prqlc/prqlc/src/cli/watch.rs:125

        // file may not exist, because this may have been a delete event
        return Ok(());
    };
    if prql_string.is_empty() {
        return Ok(());
    }

    // pre-process Jinja
    let (prql_string, jinja_context) = jinja::pre_process(&prql_string)?;

    // compile
    println!("Compiling {}", prql_path.display());
    let sql_string = match prqlc::compile(&prql_string, opt) {
        Ok(sql_string) => sql_string,
        Err(errs) => {
            for err in errs.inner {
                println!("{err}");
            }
            return Err(anyhow!("failed to compile"));
        }
    };

    // post-process Jinja
    let sql_string = jinja::post_process(&sql_string, jinja_context);

    // write
    fs::write(sql_path, sql_string)?;

    Ok(())
}

View on GitHub (pinned to e164e249b9)