Better HN
topnewbestaskshowjobs
Log inSign up

gfreezy

0 karma · joined Jan 13, 2021 (5y ago) · 3 submissions

Submissions

comment 1y ago · link · parent

    async fn handle_request(req: Request) -> Result<Output> {
        let msg = decode_msg(&req.msg).context(DecodeMessage)?; // propagate error with new stack and context
        verify_msg(&msg)?; // pass error to the caller directly
        process_msg(msg).await? // pass error to the caller directly
    }

    async fn decode_msg(msg: &RawMessage) -> Result<Message> {
        serde_json::from_slice(&msg).context(SerdeJson) // propagate error with new stack and context
    }

how to capture the virtual stack when `verify_msg` returns an error? Do you have some lint to make sure every error is attached with a context?