hen 0.18.1

Run protocol-aware API request collections from the command line or through MCP.
Documentation
use crate::request::TemplateError;

use super::{Rule, context};

pub(super) fn template_error_to_span(
    error: TemplateError,
    span: pest::Span<'_>,
) -> pest::error::Error<Rule> {
    pest::error::Error::new_from_span(
        pest::error::ErrorVariant::CustomError {
            message: error.to_string(),
        },
        span,
    )
}

pub(super) fn template_error_to_collection_error(
    error: TemplateError,
    source: &str,
) -> pest::error::Error<Rule> {
    pest::error::Error::new_from_span(
        pest::error::ErrorVariant::CustomError {
            message: error.to_string(),
        },
        pest::Span::new(source, 0, source.len()).unwrap(),
    )
}

pub(super) fn prompt_error_to_span(
    error: context::PromptInputError,
    span: pest::Span<'_>,
) -> pest::error::Error<Rule> {
    pest::error::Error::new_from_span(
        pest::error::ErrorVariant::CustomError {
            message: error.to_string(),
        },
        span,
    )
}

pub(super) fn prompt_error_to_template_error(
    request: &str,
    error: context::PromptInputError,
) -> TemplateError {
    TemplateError::PromptInput {
        request: request.to_string(),
        prompt: error.prompt().to_string(),
        default: error.default().map(str::to_string),
    }
}