Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libchisel/src/binaryenopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl ModuleConfig for BinaryenOptimiser {
if let Some(preset) = config.get("preset") {
BinaryenOptimiser::with_preset(preset)
} else {
Err(ModuleError::NotSupported)
Err(ModuleError::MissingConfigKey("preset"))
}
}
}
Expand All @@ -55,7 +55,7 @@ impl ModulePreset for BinaryenOptimiser {
"O4" => Ok(BinaryenOptimiser::O4),
"Os" => Ok(BinaryenOptimiser::Os),
"Oz" => Ok(BinaryenOptimiser::Oz),
_ => Err(ModuleError::NotSupported),
_ => Err(ModuleError::InvalidConfigValue("preset", preset)),
}
}
}
Expand Down
24 changes: 21 additions & 3 deletions libchisel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pub enum ModuleKind {
pub enum ModuleError {
NotSupported,
NotFound,
InvalidConfigKey(String),
InvalidConfigValue(String, String),
MissingConfigKey(String),
Custom(String),
}

Expand Down Expand Up @@ -110,9 +113,19 @@ impl fmt::Display for ModuleError {
f,
"{}",
match self {
ModuleError::NotSupported => "Method unsupported",
ModuleError::NotFound => "Not found",
ModuleError::Custom(msg) => msg,
ModuleError::NotSupported => "Method unsupported".to_string(),
ModuleError::NotFound => "Not found".to_string(),
ModuleError::InvalidConfigKey(key) => {
format!("Invalid configuration key supplied ({})", key)
}
ModuleError::InvalidConfigValue(key, value) => format!(
"For the configuration key ({}) invalid value ({}) was supplied",
key, value
),
ModuleError::MissingConfigKey(key) => {
format!("Missing required configuration key ({})", key)
}
ModuleError::Custom(msg) => msg.to_string(),
}
)
}
Expand All @@ -123,6 +136,11 @@ impl error::Error for ModuleError {
match self {
ModuleError::NotSupported => "Method unsupported",
ModuleError::NotFound => "Not found",
ModuleError::InvalidConfigKey(_) => "Invalid configuration key supplied",
ModuleError::InvalidConfigValue(_, _) => {
"Invalid value was supplied for the configuration key"
}
ModuleError::MissingConfigKey(_) => "Missing required configuration key",
ModuleError::Custom(msg) => msg,
}
}
Expand Down
9 changes: 7 additions & 2 deletions libchisel/src/remapimports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'a> ModuleConfig for RemapImports<'a> {
if let Some(preset) = config.get("preset") {
RemapImports::with_preset(preset)
} else {
Err(ModuleError::NotSupported)
Err(ModuleError::MissingConfigKey("preset".to_string()))
}
}
}
Expand Down Expand Up @@ -73,7 +73,12 @@ impl<'a> ModulePreset for RemapImports<'a> {
ImportList::with_preset("bignum")?,
Some("bignum_"),
)),
_ => return Err(ModuleError::NotSupported),
_ => {
return Err(ModuleError::InvalidConfigValue(
"preset".to_string(),
preset_individual.to_string(),
))
}
}
}

Expand Down