fix: add error handling for unknown column types
This commit is contained in:
@@ -73,6 +73,29 @@ impl ColumnType {
|
|||||||
ColumnType::Meta => "meta",
|
ColumnType::Meta => "meta",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a Result with error message if the string is not a valid ColumnType
|
||||||
|
pub fn from_str(s: &str) -> anyhow::Result<Self> {
|
||||||
|
Self::try_from(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&str> for ColumnType {
|
||||||
|
type Error = anyhow::Error;
|
||||||
|
|
||||||
|
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
||||||
|
match s {
|
||||||
|
"id" => Ok(ColumnType::Id),
|
||||||
|
"time" => Ok(ColumnType::Time),
|
||||||
|
"size" => Ok(ColumnType::Size),
|
||||||
|
"compression" => Ok(ColumnType::Compression),
|
||||||
|
"filesize" => Ok(ColumnType::FileSize),
|
||||||
|
"filepath" => Ok(ColumnType::FilePath),
|
||||||
|
"tags" => Ok(ColumnType::Tags),
|
||||||
|
"meta" => Ok(ColumnType::Meta),
|
||||||
|
_ => Err(anyhow!("Unknown column type: {}", s)),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_format_box_chars_no_border_line_separator() -> TableFormat {
|
pub fn get_format_box_chars_no_border_line_separator() -> TableFormat {
|
||||||
|
|||||||
Reference in New Issue
Block a user