{"record":{"id":"23817a61f9b2494e","repo":"dagger/dagger","slug":"failed-to-prepare-q","errorCode":null,"errorMessage":"failed to prepare %q","messagePattern":"failed to prepare %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/snapshots/merge.go","lineNumber":118,"sourceCode":"\tif leaseID, ok := leases.FromContext(ctx); !ok || leaseID == \"\" {\n\t\tleaseCtx, err := EnsureLease(ctx)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"failed to ensure temporary lease for view mounts during merge\")\n\t\t}\n\t\tctx = leaseCtx\n\t}\n\tif leaseID, ok := leases.FromContext(ctx); !ok || leaseID == \"\" {\n\t\tleaseCtx, done, err := WithLease(ctx, sn.lm, MakeTemporary)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"failed to create temporary lease for view mounts during merge\")\n\t\t}\n\t\tdefer done(context.TODO())\n\t\tctx = leaseCtx\n\t}\n\n\tprepareKey := identity.NewID()\n\tif err := sn.Prepare(ctx, prepareKey, baseKey); err != nil {\n\t\treturn errors.Wrapf(err, \"failed to prepare %q\", key)\n\t}\n\tapplyMounts, err := sn.Mounts(ctx, prepareKey)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to get mounts of %q\", key)\n\t}\n\n\tusage, err := sn.diffApply(ctx, applyMounts, diffs...)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"failed to apply diffs\")\n\t}\n\tif err := sn.Commit(ctx, key, prepareKey, withMergeUsage(usage)); err != nil {\n\t\treturn errors.Wrapf(err, \"failed to commit %q\", key)\n\t}\n\treturn nil\n}\n\nfunc (sn *mergeSnapshotter) Usage(ctx context.Context, key string) (snapshots.Usage, error) {\n\tif info, err := sn.Stat(ctx, key); err != nil {","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/engine/snapshots/merge.go#L100-L136","documentation":"Merge wraps any failure from the snapshotter's Prepare call (which creates a new snapshot keyed by a fresh identity with the computed base as parent) with \"failed to prepare %q\", where %q is the caller-supplied destination key. This library (dagger's mergeSnapshotter) throws it when the underlying containerd snapshotter cannot allocate/prepare the intermediate merge snapshot. The wrapped cause is typically an ErrExists, ErrNotFound, or storage-level failure from containerd.","triggerScenarios":"Calling MergeSnapshotter.Merge(ctx, key, diffs) where key already exists in the snapshotter, or a diff's Upper/Lower snapshot keys are missing, or the snapshotter backend (overlayfs/native) fails to create the prepare snapshot (disk full, corrupted layer dirs).","commonSituations":"Pruning garbage-collected snapshots while a merge references them; concurrent merges targeting the same key; disk exhaustion on the node holding the snapshotter state; upgrading/switching the containerd snapshotter driver mid-flight.","solutions":["Check whether the destination key already exists and delete it (or pick a fresh key) before calling Merge","Verify all diff Upper/Lower snapshot keys still exist via Stat; re-resolve from cache if they were pruned","Free disk space / check snapshotter backend health on the node","Inspect the wrapped cause with errors.Cause / %v of the inner error to distinguish ErrExists from storage failures"],"exampleFix":"// before\nif err := sn.Merge(ctx, \"my-snap\", diffs); err != nil { return err }\n// after\nif _, err := sn.Stat(ctx, \"my-snap\"); err == nil {\n    sn.Remove(ctx, \"my-snap\") // or use a fresh identity.NewID()\n}\nif err := sn.Merge(ctx, \"my-snap\", diffs); err != nil { return err }","handlingStrategy":"validation","validationCode":"if _, err := sn.Stat(ctx, key); err == nil {\n    return fmt.Errorf(\"snapshot %q already exists; remove it or use a fresh key\", key)\n}\nfor _, d := range diffs {\n    if d.Upper != \"\" {\n        if _, err := sn.Stat(ctx, d.Upper); err != nil {\n            return fmt.Errorf(\"diff upper %q missing: %w\", d.Upper, err)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := sn.Merge(ctx, key, diffs); err != nil {\n    if errors.Is(err, cerrdefs.ErrAlreadyExists) {\n        _ = sn.Remove(ctx, key)\n        err = sn.Merge(ctx, key, diffs) // retry once with fresh prepareKey\n    }\n    return err\n}","preventionTips":["Always merge into unique keys (identity.NewID()) rather than stable names","Stat-check destination and diff keys before merging","Monitor snapshotter disk usage to avoid ENOSPC during prepare","Keep GC coordinated with in-flight merge operations"],"tags":["snapshots","containerd","merge"],"backgroundTag":"snapshot-prepare-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}