Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

debug nom errors #17

Open
vasilakisfil opened this issue Jul 23, 2020 · 4 comments
Open

debug nom errors #17

vasilakisfil opened this issue Jul 23, 2020 · 4 comments

Comments

@vasilakisfil
Copy link
Contributor

Hi,

I am curious how I can debug nom errors. In nom, most helpful functions (like convert_error) operate under &str while the libsip library uses &[u8]. At some point in my code I have something like:

async fn process_request(request: common::bytes::BytesMut) -> Result<Vec<u8>, String> {
    let (_, request) = libsip::parse_message::<VerboseError<&[u8]>>(&request.to_vec())
        .map_err(|e| e.to_string())?;
    let response = processor::get_response(request).await?;
    Ok(format!("{}", response).into_bytes())
}

the e.to_string() does not give very helpful data, even if I do format!("{:?}", e), it's just prints plain binary (array of numbers). Nom provides some pretty good support for human-friendly errors and I would like to use it somehow. Ideas how to convert the libsip VerboseError<&[u8]> to VerboseError<&str> ?

Sorry, I am a bit new to Rust.

@KalitaAlexey
Copy link
Contributor

In order to have VerboseError<&str> we should have functions that accept &str instead of &[u8].
@ByteBuddha Is there a reason they accept input as &[u8]? :-)

@wendivoid
Copy link
Collaborator

The only reason was to simplify reading and writing witch worked with &[u8] but I'm not opposed to change it to &str.

@KalitaAlexey
Copy link
Contributor

@ByteBuddha Are you going to work on it?

@wendivoid
Copy link
Collaborator

@KalitaAlexey I have started messing around with it, I tried first to wrap nom::error::covert_error to work with the VerboseError<&[u8]> but that causes error messages to be invalid. I won't have anytime to work on this for a couple weeks so feel free to and if not I'll pick it up as soon as I get some free time

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants