Skip to content

More detailled reporting of errors from flavors #232

@sirhcel

Description

@sirhcel

The Flavor trait reports errors as postcard::Error. This enum has no variant for indicating an error specifically originating from data handling from a flavor. There are variants like SerializeBufferFull and SerdeSerCustom but they might be misleading.

To illustrate this with an example for adding a MAC to postcard frames:

impl<B> Flavor for Mac<B>
where
    B: Flavor
{
    // ...

    fn try_extend(&mut self, data: &[u8]) -> postcard::Result<()> {
        self.mac
            .update(data)
            .map_err(|_| postcard::Error:::SerializeBufferFull)?;
        self.base.try_extend(data)
    }

    fn finalize(mut self) ->- postcard::Result<Self::Output> {
        let mac = self
            .mac
            .finish()
            .map_err(|_| postcard::Error::SerializeBufferFull)?
            .as_bytes();
        self.base.try_extend(mac)?;
        self.base.finalize()
    }
}

Today I spent some time debugging this because I fell for my own red herring SerializeBufferFull when I was looking into the TX buffer in the first place where actually the mac computation failed. Strictly, the latter is neither SerialializeBufferFull, SerializeSeqLengthUnknown, or SerdeSerCustom.

Logging the error with inspect_err, will provide at least a clue to the friendly reader. But this needs to be taken care of for every potential souce while converting the original error needs to be done anyways and gets checked by the compiler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Q2 '25 TriageItems tracked as part of https://github.com/jamesmunns/postcard/issues/241postcard-2.0Tracking issues for an eventual 2.0 version of the postcard wire format (not currently planned)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions