packages

csv::error

On this page

CsvError: what went wrong, where (line and column, 1-based), and what to write instead.

Structs

CsvErrorSource

pub struct CsvError

A CSV read, decode or write error.

nabi
let r = csv::Dialect::new().has_header(false).from_str("a,\"b\n");
let got = try r.next() catch e {
    assert(e.kind == csv::ErrorKind::UnclosedQuote && e.line == 1 && e.column == 3);
    assert(f"{e}".starts_with("line 1, column 3: "));
    return;
};
panic(f"read {got:?}");
  • What went wrong.

  • pub line: usize§

    Source

    The line, 1-based; 0 when there is none.

  • pub column: usize§

    Source

    The column in characters, 1-based; 0 when there is none.

  • pub field: str§

    Source

    The field's name (or its number when there is no header), for a decode error; else empty.

  • pub msg: str§

    Source

    The message: what is wrong and what to write instead.

  • pub fn new(kind: ErrorKind, msg: str) -> CsvError§

    Source

    An error without a position.

    nabi
    let e = csv::CsvError::new(csv::ErrorKind::Decode, "`x` is not a number");
    assert(f"{e}" == "`x` is not a number");
    
  • pub fn at(self, line: usize, column: usize) -> CsvError§

    Source

    The same error at line, column.

    nabi
    let e = csv::CsvError::new(csv::ErrorKind::Decode, "bad").at(3, 0);
    assert(f"{e}" == "line 3: bad");
    
  • pub fn message(self) -> str§

    Source

    The message with its position, as Display writes it.

    nabi
    let e = csv::CsvError::new(csv::ErrorKind::Io, "disk full");
    assert(e.message() == "disk full");
    
Trait implementations 3
  • impl Display for CsvError
  • impl Debug for CsvError
  • impl Error for CsvError

Enums

ErrorKindSource

pub enum ErrorKind

The kind of a CsvError.

nabi
let r = csv::from_str("a,b\n1\n");
let n = try r.count() catch e {
    assert(e.kind == csv::ErrorKind::FieldCount);
    return;
};
panic(f"read {n}");
  • Reading or writing the stream failed.

  • The input is not UTF-8.

  • UnclosedQuote§

    Source

    A quoted field has no closing quote.

  • AfterQuote§

    Source

    Text follows a closing quote before the delimiter.

  • FieldCount§

    Source

    A record has another field count than the first.

  • Decode§

    Source

    A field does not convert to the type asked for.

  • The writer cannot write a field as asked.