{"record":{"id":"d1cb08d226dedc98","repo":"kopia/kopia","slug":"invalid-kind-for-stats-v","errorCode":null,"errorMessage":"invalid kind for stats %v","messagePattern":"invalid kind for stats (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/maintenancestats/builder.go","lineNumber":74,"sourceCode":"\t\tresult = &GenerateRangeCheckpointStats{}\n\tcase advanceEpochStatsKind:\n\t\tresult = &AdvanceEpochStats{}\n\tcase compactSingleEpochStatsKind:\n\t\tresult = &CompactSingleEpochStats{}\n\tcase compactIndexesStatsKind:\n\t\tresult = &CompactIndexesStats{}\n\tcase deleteUnreferencedPacksStatsKind:\n\t\tresult = &DeleteUnreferencedPacksStats{}\n\tcase extendBlobRetentionStatsKind:\n\t\tresult = &ExtendBlobRetentionStats{}\n\tcase cleanupLogsStatsKind:\n\t\tresult = &CleanupLogsStats{}\n\tcase rewriteContentsStatsKind:\n\t\tresult = &RewriteContentsStats{}\n\tcase snapshotGCStatsKind:\n\t\tresult = &SnapshotGCStats{}\n\tdefault:\n\t\treturn nil, errors.Wrapf(ErrUnSupportedStatKindError, \"invalid kind for stats %v\", stats)\n\t}\n\n\tif err := json.Unmarshal(stats.Data, result); err != nil {\n\t\treturn nil, errors.Wrapf(err, \"error unmarshaling raw stats %v of kind %s to %T\", stats.Data, stats.Kind, result)\n\t}\n\n\treturn result, nil\n}\n","sourceCodeStart":56,"sourceCodeEnd":83,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/repo/maintenancestats/builder.go#L56-L83","documentation":"BuildFromExtra switches on the persisted stats Kind and wraps ErrUnSupportedStatKindError with \"invalid kind for stats %v\" when the kind is not one of the known stats kinds (e.g. cleanup-logs, rewrite-contents, snapshot-gc). It means the Extra blob cannot be decoded because its kind is unrecognized by this build of the library.","triggerScenarios":"Calling BuildFromExtra with a Run.Extra whose Kind was produced by a newer/older kopia version with a stats kind this binary does not know, or a corrupted/overwritten Extra record.","commonSituations":"Reading maintenance history written by a newer Kopia release after downgrading the binary; manual edits or migration bugs corrupting the stored Kind; custom stats kinds not registered.","solutions":["Check errors.Is(err, ErrUnSupportedStatKindError) and skip/ignore stats of unknown kinds instead of failing the whole run.","Upgrade the binary to a version that supports the stored stats kind.","Verify the Kind string stored in Extra against the supported kinds in maintenancestats/builder.go.","Re-create or discard the corrupted run record."],"exampleFix":"// before\nmsg, err := BuildFromExtra(ctx, run.Extra)\nif err != nil { return err }\n// after\nmsg, err := BuildFromExtra(ctx, run.Extra)\nif errors.Is(err, ErrUnSupportedStatKindError) {\n    return nil // skip unknown stats kinds (e.g. from a newer version)\n}","handlingStrategy":"fallback","validationCode":"// check kind support before decoding:\nsupported := map[string]bool{\"cleanup-logs\": true, \"rewrite-contents\": true, \"snapshot-gc\": true}\nif !supported[run.Extra.Kind] { log.Warnf(\"unknown stats kind %q, skipping\", run.Extra.Kind) }","typeGuard":"func hasSupportedStatsKind(k string) bool {\n    switch k {\n    case \"cleanup-logs\", \"rewrite-contents\", \"snapshot-gc\":\n        return true\n    }\n    return false\n}","tryCatchPattern":"msg, err := BuildFromExtra(ctx, run.Extra)\nif errors.Is(err, ErrUnSupportedStatKindError) {\n    log.Warnf(\"stats kind %q not supported by this version; skipping\", run.Extra.Kind)\n    return nil\n}","preventionTips":["Match binary version to the version that wrote maintenance history","Treat unknown stats kinds as non-fatal in UI/reporting code","Check errors.Is(err, ErrUnSupportedStatKindError) explicitly","Avoid hand-editing persisted Extra records"],"tags":["go","json","maintenance","compatibility"],"backgroundTag":"invalid-enum-value","analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}