refactor: simplify error handling and conditionals in meta plugins
This commit is contained in:
committed by
Andrew Phillips (aider)
parent
022bc70f53
commit
27d3ecad04
@@ -67,10 +67,10 @@ impl MagicFileMetaPlugin {
|
||||
// Use the existing cookie and just change flags
|
||||
if let Some(cookie) = &self.cookie {
|
||||
cookie.set_flags(flags)
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to set magic flags: {}", e)))?;
|
||||
.map_err(|e| io::Error::other(format!("Failed to set magic flags: {}", e)))?;
|
||||
|
||||
let result = cookie.buffer(&self.buffer)
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("Failed to analyze buffer: {}", e)))?;
|
||||
.map_err(|e| io::Error::other(format!("Failed to analyze buffer: {}", e)))?;
|
||||
|
||||
// Clean up the result - remove extra whitespace and take first part if needed
|
||||
let trimmed = result.trim();
|
||||
@@ -86,7 +86,7 @@ impl MagicFileMetaPlugin {
|
||||
|
||||
Ok(cleaned.to_string())
|
||||
} else {
|
||||
Err(io::Error::new(io::ErrorKind::Other, "Magic cookie not initialized"))
|
||||
Err(io::Error::other("Magic cookie not initialized"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,16 +102,15 @@ impl MagicFileMetaPlugin {
|
||||
];
|
||||
|
||||
for (name, flags) in types_to_process.iter() {
|
||||
if let Ok(result) = self.get_magic_result(*flags) {
|
||||
if !result.is_empty() {
|
||||
// Use process_metadata_outputs to handle output mapping
|
||||
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
|
||||
name,
|
||||
serde_yaml::Value::String(result),
|
||||
self.base.outputs()
|
||||
) {
|
||||
metadata.push(meta_data);
|
||||
}
|
||||
if let Ok(result) = self.get_magic_result(*flags)
|
||||
&& !result.is_empty() {
|
||||
// Use process_metadata_outputs to handle output mapping
|
||||
if let Some(meta_data) = crate::meta_plugin::process_metadata_outputs(
|
||||
name,
|
||||
serde_yaml::Value::String(result),
|
||||
self.base.outputs()
|
||||
) {
|
||||
metadata.push(meta_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -242,4 +241,4 @@ fn register_magic_file_plugin() {
|
||||
register_meta_plugin(MetaPluginType::MagicFile, |options, outputs| {
|
||||
Box::new(MagicFileMetaPlugin::new(options, outputs))
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user