Introducing a new way to review your PRs.

Read the announcement

solana-foundation / create-solana-dapp

The fastest way to create Solana apps 🚀 Templates 👉 https://github.com/solana-foundation/templates

View on GitHub

18 documents · Updated Nov 6, 2026

docs / template-acquisition-and-recovery

Template acquisition and recovery

Template acquisition turns a selected starter source into the files in the new project directory. The flow supports remote template archives and trusted local sources, checks that the result is usable, and removes failed work when creation cannot continue. It is the source stage of the project scaffolding pipeline; target checks and project metadata belong to target path and project metadata, while package setup belongs to dependency installation and package managers.

Starter source acquisition

The acquisition stage resolves the selected template identity into a project workspace. A remote identity is downloaded and unpacked into the target directory. A local identity is copied into that directory for local development.

Source forms

The system treats a local path as a trusted development source and treats a name with a slash as an external source. A catalog template uses its registered identity. This lets one creation flow support published starters, external starters, and local work without changing the later setup stages.

SourceAcquisition behaviorTrust boundary
Catalog templateDownload and unpack the selected remote sourceThe selected catalog identity
External templateDownload and unpack the supplied external identityThe supplied external source
Local templateCopy the source into the target directoryThe local files and the user who supplied them

Local sources produce a warning because they are intended for development and are not treated as official templates. The copy also omits common generated or dependency directories so local build state does not become part of the new project.

References: src/…/find-template.ts• L16-53 src/…/create-app-task-clone-template.ts• L60-83

Acquisition boundary

The cloning task owns the boundary between a selected template and the generated workspace. It rejects an existing target before it writes, rejects a missing template identity, and checks that the acquired directory contains files before it reports success.

This boundary matters because later tasks assume that a real project exists. An empty result is reported as a template problem instead of allowing dependency installation or setup to fail with a less useful message.

References: src/…/create-app-task-clone-template.ts• L43-57 src/…/create-app-task-clone-template.ts• L86-99 src/…/get-args-result.ts• L5-19

Archive recovery

A template archive is the downloaded package of files used to build a remote starter. An interrupted download can leave a damaged cached archive, which may fail during unpacking with a low-level archive or compression error rather than a clear network message.

Malformed archive detection

The recovery path classifies known archive and compression failures as damaged-cache errors. It does not classify unrelated failures, such as an existing destination or a network lookup failure, as archive damage. This distinction prevents a retry from hiding the real cause of a different acquisition failure.

The classifier accepts both error codes and common error text because the archive tool can report the same condition in different shapes. The user-facing message names the template and the cache directory that must be cleared.

References: src/…/corrupt-archive-error.ts• L4-21 src/…/corrupt-archive-error.ts• L23-45

Retry and cache repair

When the first remote acquisition fails because the archive is damaged, the system makes one fresh acquisition attempt. The retry clears the partially extracted target before it starts, so files from the failed attempt cannot contaminate the new result.

If the retry succeeds, the normal acquisition flow continues. If the retry reports the same archive damage, the task stops with an actionable instruction to delete the template cache and try again. Other retry failures pass through as their original error.

The following flow shows how acquisition errors move from classification to recovery or final failure.

flowchart TD
    A[Acquire remote template] --> B{Acquisition succeeds?}
    B -- Yes --> C[Check workspace contents]
    B -- No --> D{Damaged archive?}
    D -- No --> E[Report acquisition failure]
    D -- Yes --> F[Retry with a clean target]
    F --> G{Retry succeeds?}
    G -- Yes --> C
    G -- No --> H{Damaged archive again?}
    H -- No --> E
    H -- Yes --> I[Show cache-clear guidance]

References: src/…/create-app-task-clone-template.ts• L9-41 src/…/corrupt-archive-error.ts• L36-45

Acquisition failure handling

Acquisition runs as the first task in project creation. Task failure is shown to the user and stops the remaining setup work, so dependency installation, initialization scripts, and git setup do not run against an incomplete workspace.

Target cleanup

The overall creation flow records whether the target existed before acquisition. If creation created the target and any later task fails, the flow removes that target. If the target existed before creation, it is left in place because it does not belong to the failed run.

This cleanup gives a failed run an all-or-nothing workspace boundary. It also protects an existing directory from removal when a later setup action fails.

References: src/…/create-app.ts• L22-30 src/…/create-app.ts• L57-78

User-facing errors

The acquisition task converts failures into task errors with a clear stage label. Archive damage gets recovery guidance. Other failures retain their cause so the user can address the actual source, such as a missing local path or an unavailable external template.

FailureUser outcomeRecovery
Target already existsCreation stops before acquisition writes to itChoose a new target path
Template identity is missingCreation stops before source resolutionSelect or supply a template
Acquired directory is emptyCreation stops with a template-id messageCheck the template source
Damaged archive on first attemptOne clean retry startsWait for the retry to complete
Damaged archive on retryThe cache location is shownDelete the template cache and try again
Unrelated acquisition errorThe original error is reportedFix the reported source or environment problem

References: src/…/create-app-task-clone-template.ts• L46-56 src/…/create-app-task-clone-template.ts• L86-96 src/…/corrupt-archive-error.ts• L41-45

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the accepted template identity forms aligned between template selection and acquisition. A source that can be selected but cannot be resolved will fail after the user has committed to creation.
  • Keep damaged-archive classification narrow enough that unrelated download failures are not retried or rewritten as cache problems.
  • Keep the retry's clean-target behavior aligned with the outer cleanup rule. A failed remote attempt must not leave files that affect the retry or a later run.
  • Keep the cache path in the recovery message aligned with the download library's cache rules on each supported platform.
  • Keep the non-empty workspace check before any downstream setup task can run.

Important failure modes

TriggerConsequenceGuard
A partial cached archive is unpackedThe user sees a low-level compression failure and may try to fix the wrong dependencyDetect archive and compression errors, retry once, then show the cache-clear path
The first failed attempt leaves files in the targetThe retry can read a mixed or incomplete projectUse a clean target for the retry
A remote source resolves to no filesLater setup receives an unusable projectCheck the acquired directory before reporting success
A later creation task fails after a new target was createdPartial project files remain on diskRemove the new target in the outer creation failure path
A later creation task fails in a pre-existing targetUser files could be lostTrack prior existence and never remove that target

Key files

FileWhy to read it
src/…/create-app-task-clone-template.tsDefines the acquisition boundary for local copies, remote unpacking, empty-workspace checks, and task errors
src/…/corrupt-archive-error.tsDefines damaged-archive recognition, cache location rules, and recovery guidance
src/…/create-app.tsShows where acquisition sits in project creation and how failed runs clean up their target
src/…/find-template.tsShows how catalog, external, and local template identities enter the acquisition stage
src/…/clack-tasks.tsShows how task failures stop the ordered creation flow and reach the user