Skip to content

fix: forward extended call to sub-struct when #[api_error(transparent)] is set [release] - #41

Merged
Totodore merged 1 commit into
developfrom
fix-transparent-extended
Jul 27, 2026
Merged

fix: forward extended call to sub-struct when #[api_error(transparent)] is set [release]#41
Totodore merged 1 commit into
developfrom
fix-transparent-extended

Conversation

@Totodore

Copy link
Copy Markdown
Contributor

Description

#[api_error(transparent)] was not forwarding the call to extended` on a sub-struct. E.g with the following implementation:

#[derive(Debug, thiserror::Error, ApiError)]
pub enum RendererError {
    #[error("template rendering panicked: {0}")]
    Panic(#[from] tokio::task::JoinError),

    #[error("template rendering failed")]
    TemplateRendering(String),

    #[error("template not found at: {path}")]
    #[api_error(status_code = StatusCode::BAD_REQUEST, message(inherit))]
    TemplateNotFound { path: String },

    #[error(transparent)]
    #[api_error(transparent)]
    InvalidParams(#[from] InvalidParamsError),

    #[error("failed to encode the rendered template to a flow: {0}")]
    Serde(#[from] serde_json::Error),
}

#[derive(Debug, thiserror::Error)]
#[error("invalid parameters given for template: {template}")]
pub struct InvalidParamsError {
    params: serde_json::Value,
    template: String,
    evaluation: Evaluation,
}

impl ApiError for InvalidParamsError {
    fn status_code(&self) -> StatusCode {
        StatusCode::BAD_REQUEST
    }

    fn message(&self) -> std::borrow::Cow<'_, str> {
        dbg!("test");
        format!("invalid parameters given for template {}", self.template).into()
    }

    fn extended(&self) -> Option<serde_json::Value> {
        dbg!("test");
        Some(serde_json::json!({
            "params": self.params.clone(),
            "evaluation": self.evaluation.list(),
        }))
    }
}

@Totodore
Totodore requested a review from a team as a code owner July 27, 2026 14:09
@Totodore
Totodore requested review from leoncx and removed request for a team July 27, 2026 14:09
@Totodore Totodore added the bug Something isn't working label Jul 27, 2026
@Totodore
Totodore merged commit 4bff65a into develop Jul 27, 2026
10 checks passed
@Totodore
Totodore deleted the fix-transparent-extended branch July 27, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant