refactor: update error messages to be more uniform
This commit is contained in:
parent
4d512afdae
commit
b1f86262f3
|
@ -933,7 +933,7 @@ impl std::str::FromStr for BottomWidgetType {
|
||||||
"empty" => Ok(BottomWidgetType::Empty),
|
"empty" => Ok(BottomWidgetType::Empty),
|
||||||
"battery" | "batt" => Ok(BottomWidgetType::Battery),
|
"battery" | "batt" => Ok(BottomWidgetType::Battery),
|
||||||
_ => Err(BottomError::ConfigError(format!(
|
_ => Err(BottomError::ConfigError(format!(
|
||||||
"Invalid widget type: {}",
|
"invalid widget type: {}",
|
||||||
s
|
s
|
||||||
))),
|
))),
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,7 +166,8 @@ impl CanvasColours {
|
||||||
pub fn set_battery_colours(&mut self, colours: &[String]) -> error::Result<()> {
|
pub fn set_battery_colours(&mut self, colours: &[String]) -> error::Result<()> {
|
||||||
if colours.is_empty() {
|
if colours.is_empty() {
|
||||||
Err(error::BottomError::ConfigError(
|
Err(error::BottomError::ConfigError(
|
||||||
"Battery colour list must have at least one colour!".to_string(),
|
"invalid colour config: battery colour list must have at least one colour!"
|
||||||
|
.to_string(),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
let generated_colours: Result<Vec<_>, _> = colours
|
let generated_colours: Result<Vec<_>, _> = colours
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub struct ConfigFlags {
|
||||||
pub default_widget_type: Option<String>,
|
pub default_widget_type: Option<String>,
|
||||||
pub default_widget_count: Option<u64>,
|
pub default_widget_count: Option<u64>,
|
||||||
pub use_old_network_legend: Option<bool>,
|
pub use_old_network_legend: Option<bool>,
|
||||||
pub hide_table_gap : Option<bool>,
|
pub hide_table_gap: Option<bool>,
|
||||||
//disabled_cpu_cores: Option<Vec<u64>>, // TODO: [FEATURE] Enable disabling cores in config/flags
|
//disabled_cpu_cores: Option<Vec<u64>>, // TODO: [FEATURE] Enable disabling cores in config/flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +219,11 @@ pub fn build_app(
|
||||||
hide_time: get_hide_time(matches, config),
|
hide_time: get_hide_time(matches, config),
|
||||||
autohide_time,
|
autohide_time,
|
||||||
use_old_network_legend: get_use_old_network_legend(matches, config),
|
use_old_network_legend: get_use_old_network_legend(matches, config),
|
||||||
table_gap: if get_hide_table_gap(matches, config){0}else{1},
|
table_gap: if get_hide_table_gap(matches, config) {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let used_widgets = UsedWidgets {
|
let used_widgets = UsedWidgets {
|
||||||
|
@ -286,7 +290,7 @@ pub fn get_widget_layout(
|
||||||
ret_bottom_layout
|
ret_bottom_layout
|
||||||
} else {
|
} else {
|
||||||
return Err(error::BottomError::ConfigError(
|
return Err(error::BottomError::ConfigError(
|
||||||
"Invalid layout - please have at least one widget.".to_string(),
|
"invalid layout config: please have at least one widget.".to_string(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -342,7 +346,7 @@ fn get_temperature(
|
||||||
"kelvin" | "k" => Ok(data_harvester::temperature::TemperatureType::Kelvin),
|
"kelvin" | "k" => Ok(data_harvester::temperature::TemperatureType::Kelvin),
|
||||||
"celsius" | "c" => Ok(data_harvester::temperature::TemperatureType::Celsius),
|
"celsius" | "c" => Ok(data_harvester::temperature::TemperatureType::Celsius),
|
||||||
_ => Err(BottomError::ConfigError(
|
_ => Err(BottomError::ConfigError(
|
||||||
"Invalid temperature type. Please have the value be of the form \
|
"invalid temperature type: please have the value be of the form \
|
||||||
<kelvin|k|celsius|c|fahrenheit|f>"
|
<kelvin|k|celsius|c|fahrenheit|f>"
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)),
|
)),
|
||||||
|
@ -633,4 +637,3 @@ pub fn get_hide_table_gap(matches: &clap::ArgMatches<'static>, config: &Config)
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,24 +28,24 @@ impl std::fmt::Display for BottomError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
BottomError::InvalidIO(ref message) => {
|
BottomError::InvalidIO(ref message) => {
|
||||||
write!(f, "Encountered an IO exception: {}", message)
|
write!(f, "encountered an IO exception: {}", message)
|
||||||
}
|
}
|
||||||
BottomError::InvalidArg(ref message) => write!(f, "Invalid argument: {}", message),
|
BottomError::InvalidArg(ref message) => write!(f, "Invalid argument: {}", message),
|
||||||
BottomError::InvalidHeim(ref message) => write!(
|
BottomError::InvalidHeim(ref message) => write!(
|
||||||
f,
|
f,
|
||||||
"Invalid error during data collection due to Heim: {}",
|
"invalid error during data collection due to heim: {}",
|
||||||
message
|
message
|
||||||
),
|
),
|
||||||
BottomError::CrosstermError(ref message) => {
|
BottomError::CrosstermError(ref message) => {
|
||||||
write!(f, "Invalid error due to Crossterm: {}", message)
|
write!(f, "invalid error due to Crossterm: {}", message)
|
||||||
}
|
}
|
||||||
BottomError::GenericError(ref message) => write!(f, "{}", message),
|
BottomError::GenericError(ref message) => write!(f, "{}", message),
|
||||||
BottomError::FernError(ref message) => write!(f, "Invalid fern error: {}", message),
|
BottomError::FernError(ref message) => write!(f, "Invalid fern error: {}", message),
|
||||||
BottomError::ConfigError(ref message) => {
|
BottomError::ConfigError(ref message) => {
|
||||||
write!(f, "Invalid config file error: {}", message)
|
write!(f, "invalid config file error: {}", message)
|
||||||
}
|
}
|
||||||
BottomError::ConversionError(ref message) => {
|
BottomError::ConversionError(ref message) => {
|
||||||
write!(f, "Unable to convert: {}", message)
|
write!(f, "unable to convert: {}", message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue