Skip to content

Commit

Permalink
Merge pull request #1696 from fermyon/remove-decode-preinstantiation-…
Browse files Browse the repository at this point in the history
…error

trigger: Remove `decode_preinstantiation_error`
  • Loading branch information
lann authored Aug 16, 2023
2 parents 3daf17f + 2d0b74c commit 0594d20
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 38 deletions.
10 changes: 2 additions & 8 deletions crates/trigger-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,11 @@ impl TriggerExecutor for HttpTrigger {
if let Some(HttpExecutorType::Wagi(_)) = &config.executor {
let module = component.load_module(engine).await?;
Ok(EitherInstancePre::Module(
engine
.module_instantiate_pre(&module)
.map_err(spin_trigger::decode_preinstantiation_error)?,
engine.module_instantiate_pre(&module)?,
))
} else {
let comp = component.load_component(engine).await?;
Ok(EitherInstancePre::Component(
engine
.instantiate_pre(&comp)
.map_err(spin_trigger::decode_preinstantiation_error)?,
))
Ok(EitherInstancePre::Component(engine.instantiate_pre(&comp)?))
}
}
}
Expand Down
30 changes: 0 additions & 30 deletions crates/trigger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pub trait TriggerExecutor: Sized + Send + Sync {
Ok(EitherInstancePre::Component(
engine
.instantiate_pre(&comp)
.map_err(decode_preinstantiation_error)
.with_context(|| format!("Failed to instantiate component '{}'", component.id()))?,
))
}
Expand Down Expand Up @@ -354,32 +353,3 @@ pub fn parse_file_url(url: &str) -> Result<PathBuf> {
.to_file_path()
.map_err(|_| anyhow!("Invalid file URL path: {url:?}"))
}

pub fn decode_preinstantiation_error(e: anyhow::Error) -> anyhow::Error {
let err_text = e.to_string();

if err_text.contains("unknown import") && err_text.contains("has not been defined") {
// TODO: how to maintain this list?
let sdk_imported_interfaces = &[
"config",
"http",
"key-value",
"mysql",
"postgres",
"redis",
"sqlite",
];

if sdk_imported_interfaces
.iter()
.map(|s| format!("{s}::"))
.any(|s| err_text.contains(&s))
{
return anyhow!(
"{e}. Check that the component uses a SDK or plugin version that matches the Spin runtime."
);
}
}

e
}

0 comments on commit 0594d20

Please sign in to comment.