diff --git a/libchisel/src/binaryenopt.rs b/libchisel/src/binaryenopt.rs index 7236e7a..94fb84c 100644 --- a/libchisel/src/binaryenopt.rs +++ b/libchisel/src/binaryenopt.rs @@ -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")) } } } @@ -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)), } } } diff --git a/libchisel/src/lib.rs b/libchisel/src/lib.rs index 1d25e35..01ec3a6 100644 --- a/libchisel/src/lib.rs +++ b/libchisel/src/lib.rs @@ -33,6 +33,9 @@ pub enum ModuleKind { pub enum ModuleError { NotSupported, NotFound, + InvalidConfigKey(String), + InvalidConfigValue(String, String), + MissingConfigKey(String), Custom(String), } @@ -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(), } ) } @@ -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, } } diff --git a/libchisel/src/remapimports.rs b/libchisel/src/remapimports.rs index 8166a96..32a9aab 100644 --- a/libchisel/src/remapimports.rs +++ b/libchisel/src/remapimports.rs @@ -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())) } } } @@ -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(), + )) + } } }