Skip to content

Commit

Permalink
Rename error variants
Browse files Browse the repository at this point in the history
  • Loading branch information
YS-L committed Jul 21, 2024
1 parent 96b9397 commit b5b5037
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
8 changes: 3 additions & 5 deletions src/delimiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ impl Delimiter {
return Ok(Delimiter::Character(b'\t'));
}
let mut chars = s.chars();
let c = chars
.next()
.ok_or_else(|| CsvlensError::DelimiterEmptyError)?;
let c = chars.next().ok_or_else(|| CsvlensError::DelimiterEmpty)?;
if !c.is_ascii() {
return Err(CsvlensError::DelimiterNotAsciiError(c));
return Err(CsvlensError::DelimiterNotAscii(c));
}
if chars.next().is_some() {
return Err(CsvlensError::DelimiterMultipleCharactersError(s.clone()));
return Err(CsvlensError::DelimiterMultipleCharacters(s.clone()));
}
Ok(Delimiter::Character(c.try_into()?))
} else {
Expand Down
16 changes: 8 additions & 8 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ pub type CsvlensResult<T> = std::result::Result<T, CsvlensError>;
/// Errors csvlens can have
#[derive(Debug, Error)]
pub enum CsvlensError {
#[error("Failed to read file: {0}")]
FileReadError(String),
#[error("File not found: {0}")]
FileNotFound(String),

#[error("Column name not found: {0}")]
ColumnNameNotFound(String),

#[error("Delimiter should not be empty")]
DelimiterEmptyError,
DelimiterEmpty,

#[error("Delimiter should be within the ASCII range: {0} is too fancy")]
DelimiterNotAsciiError(char),
DelimiterNotAscii(char),

#[error("Delimiter should be exactly one character (or \\t), got '{0}'")]
DelimiterMultipleCharactersError(String),
DelimiterMultipleCharacters(String),

#[error(transparent)]
DelimiterParseError(#[from] std::char::TryFromCharError),
DelimiterParsing(#[from] std::char::TryFromCharError),

#[error(transparent)]
CsvError(#[from] csv::Error),
Csv(#[from] csv::Error),

#[error(transparent)]
ArrowError(#[from] arrow::error::ArrowError),
Arrow(#[from] arrow::error::ArrowError),

#[error(transparent)]
Io(#[from] std::io::Error),
Expand Down
6 changes: 4 additions & 2 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ impl SeekableFile {
let inner_file_res;

if let Some(filename) = maybe_filename {
let mut f =
File::open(filename).map_err(|_| CsvlensError::FileReadError(filename.clone()))?;
let mut f = File::open(filename).map_err(|e| match e.kind() {
std::io::ErrorKind::NotFound => CsvlensError::FileNotFound(filename.clone()),
_ => e.into(),
})?;
// If not seekable, it most likely is due to process substitution using
// pipe - write out to a temp file to make it seekable
if f.seek(SeekFrom::Start(0)).is_err() {
Expand Down

0 comments on commit b5b5037

Please sign in to comment.