haematite-cli 0.21.9

The haematite command: serve a store, its door and Studio, answer MCP, query with jq, and host the store's assistant seat
Documentation
use haematite_query::handle::Error;

use super::super::admission::StartError;
use super::super::parser::Refused;
use super::super::start;
use crate::serve::storage::Failure;

/// A start refusal; a compile refusal of plain jq also says why the text is
/// not a pipeline, so neither reading is hidden.
pub(super) fn start_failure(error: StartError, parse: Option<&Refused>) -> Failure {
    let failure = match error {
        StartError::Admission(failure) => return failure,
        StartError::Worker(error) => start::caller_failure(&error),
    };
    let compiled = matches!(
        failure.code.as_str(),
        "query_compile" | "query_function_refused"
    );
    match parse {
        Some(parse) if compiled => Failure::new(
            &failure.code,
            format!(
                "as jq: {}; as a pipeline: {parse} ({})",
                failure.message,
                parse.code()
            ),
        ),
        _ => failure,
    }
}

pub(super) fn refused(error: &Error) -> Failure {
    Failure::new(
        start::code_name(error.refusal.code),
        if error.refusal.code == haematite_query::Refusal::QueryOutputLimit {
            format!(
                "{}; ask with a larger page or add a limit",
                error.refusal.message
            )
        } else {
            error.refusal.message.clone()
        },
    )
}