0

I'm new to Rust and I've got this error.

Error: Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E23502), message: "null value in column \"id\" of relation \"trades\" violates not-null constraint", detail: Some("Failing row contains (null, null, null, 1.89, null, 1675904400015077632, 364134, null, null, TELL)."), hint: None, position: None, where_: None, schema: Some("public"), table: Some("trades"), column: Some("id"), datatype: None, constraint: None, file: Some("execMain.c"), line: Some(1974), routine: Some("ExecConstraints") }) }

This is not very readable.

How can I pretty print this or otherwise access individual fields of it?

I know that I can return a result, or the function I am calling returns a Result. And then I have a match statement:

match res {
    Ok(_) => {}
    Err(e) => {
        println!("Error inserting row: {}", e);
    }
}

How can I access individual fields on e in this print statement: println!("Error inserting row: {}", e);?

This is the error type: https://docs.rs/tokio-postgres/latest/tokio_postgres/error/struct.DbError.html

The fields in this error type are private but are being printed.

JohnAllen
  • 7,317
  • 9
  • 41
  • 65

0 Answers0