Skip to content

Commit 450c551

Browse files
authored
Merge pull request #3565 from itowlson/spin-new-env-should-not-fail-if-refreshing-templates-fails
`spin new -E` should not fail just because template update fails
2 parents 67e4d10 + 8e8a755 commit 450c551

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

src/commands/new.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,24 +309,44 @@ async fn env_templates_and_plugins(
309309
.await?;
310310
let env_name = loaded_env.name;
311311
let env_def = loaded_env.env_def;
312-
// - create a TM for it
312+
313+
// Create a TemplateManager for this environment's templates
313314
let template_manager = TemplateManager::for_environment(&env_name)?;
314-
// - install the templates to that TM
315+
316+
// If the env has templates, install the templates to that TemplateManager.
317+
// If this fails, fall back to already installed templates for that env,
318+
// or bail if we don't have env templates already installed.
315319
let env_templates = env_def.templates();
316320
if let Some(env_templates) = env_templates {
317321
let source = spin_templates::TemplateSource::try_from_git(
318322
env_templates.url(),
319323
env_templates.tag(),
320324
crate::build_info::SPIN_VERSION,
321-
)?;
322-
template_manager
325+
)
326+
.with_context(|| format!("Invalid templates URL in environment '{env_ref}'"))?;
327+
if let Err(e) = template_manager
323328
.install(
324329
&source,
325330
&spin_templates::InstallOptions::default().update(true),
326331
&DiscardingReporter,
327332
)
328-
.await?;
333+
.await
334+
{
335+
// Couldn't fetch templates, and we don't already have them from a previous use.
336+
if is_empty(&template_manager).await {
337+
return Err(e).with_context(|| {
338+
format!("Cannot install templates for '{env_ref}' environment")
339+
});
340+
}
341+
// Couldn't fetch templates, but we do have some existing ones
342+
terminal::warn!(
343+
"Cannot check for updated templates for '{env_ref}' environment"
344+
);
345+
eprintln!("Using your existing templates");
346+
eprintln!();
347+
}
329348
}
349+
330350
if is_empty(&template_manager).await {
331351
match variant {
332352
TemplateVariantInfo::NewApplication => {

0 commit comments

Comments
 (0)