{"record":{"id":"f490018f68990485","repo":"dagger/dagger","slug":"encode-persisted-client-filesync-mirror-nil-mirro","errorCode":null,"errorMessage":"encode persisted client filesync mirror: nil mirror","messagePattern":"encode persisted client filesync mirror: nil mirror","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/client_filesync_mirror.go","lineNumber":108,"sourceCode":"\t\treturn 0, false, nil\n\t}\n\tsize, err := snapshot.Size(ctx)\n\tif err != nil {\n\t\treturn 0, false, err\n\t}\n\treturn size, true, nil\n}\n\ntype persistedClientFilesyncMirrorPayload struct {\n\tStableClientID string `json:\"stableClientID\"`\n\tDrive          string `json:\"drive,omitempty\"`\n}\n\nfunc (m *ClientFilesyncMirror) EncodePersistedObject(ctx context.Context, cache dagql.PersistedObjectCache) (dagql.PersistedObjectEncoding, error) {\n\t_ = ctx\n\t_ = cache\n\tif m == nil {\n\t\treturn dagql.PersistedObjectEncoding{}, fmt.Errorf(\"encode persisted client filesync mirror: nil mirror\")\n\t}\n\tif m.StableClientID == \"\" {\n\t\treturn dagql.PersistedObjectEncoding{}, fmt.Errorf(\"encode persisted client filesync mirror: stable client id is empty\")\n\t}\n\tm.mu.Lock()\n\tvar links []dagql.PersistedSnapshotRefLink\n\tif m.snapshot != nil {\n\t\tlinks = []dagql.PersistedSnapshotRefLink{{\n\t\t\tRefKey: m.snapshot.SnapshotID(),\n\t\t\tRole:   \"snapshot\",\n\t\t}}\n\t}\n\tm.mu.Unlock()\n\tpayload, err := json.Marshal(persistedClientFilesyncMirrorPayload{\n\t\tStableClientID: m.StableClientID,\n\t\tDrive:          m.Drive,\n\t})\n\tif err != nil {","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/client_filesync_mirror.go#L90-L126","documentation":"ClientFilesyncMirror.EncodePersistedObject refuses to encode a nil receiver. Persisted objects must be concrete instances with a stable client identity; encoding a nil pointer would produce a corrupt or unusable persisted record, so the library fails fast with this sentinel-style message.","triggerScenarios":"Dagql attempts to persist a *ClientFilesyncMirror that is nil — e.g. an unset/optional field is being written to a cache or result ID store, calling EncodePersistedObject on a nil pointer.","commonSituations":"An optional ClientFilesyncMirror was never initialized before the query result was persisted; a code path returned a nil mirror without an error and downstream persistence assumed non-nil; API changes that made the field optional.","solutions":["Ensure the mirror is initialized (e.g. NewEphemeralClientFilesyncMirror or the constructor your code uses) before it can be persisted","Add a nil check at the call site and skip persistence when the mirror is absent","Trace where the nil pointer came from and return an explicit error earlier instead of nil, nil"],"exampleFix":"// before\nvar mirror *ClientFilesyncMirror\n_ = dagql.Persist(ctx, mirror)\n// after\nif mirror == nil {\n    return errors.New(\"no client filesync mirror to persist\")\n}\n_ = dagql.Persist(ctx, mirror)","handlingStrategy":"type-guard","validationCode":"if mirror == nil {\n    return errors.New(\"client filesync mirror not initialized\")\n}","typeGuard":"func isNilMirror(m *core.ClientFilesyncMirror) bool { return m == nil }","tryCatchPattern":"if err := persist(ctx, mirror); err != nil {\n    if strings.Contains(err.Error(), \"nil mirror\") {\n        // initialize and retry\n    }\n}","preventionTips":["Always construct mirrors via their constructor, never as bare nil fields","Nil-check optional mirror fields before triggering persistence","Return explicit errors instead of nil pointers from factory functions"],"tags":["persistence","nil-pointer","filesync"],"backgroundTag":"nil-pointer-receiver","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}