{"record":{"id":"9c3d43978e4d37fc","repo":"kopia/kopia","slug":"must-be-v-and-v-or-q","errorCode":null,"errorMessage":"must be >= %v and <= %v or %q","messagePattern":"must be >= (.+?) and <= (.+?) or %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command_policy_set_logging.go","lineNumber":77,"sourceCode":"func applyPolicyLogDetailPtr(ctx context.Context, desc string, val **policy.LogDetail, str string, changeCount *int) error {\n\tif str == \"\" {\n\t\t// not changed\n\t\treturn nil\n\t}\n\n\tif str == inheritPolicyString {\n\t\t*changeCount++\n\n\t\tlog(ctx).Infof(\" - resetting %q to a default value inherited from parent.\", desc)\n\n\t\t*val = nil\n\n\t\treturn nil\n\t}\n\n\tv, err := strconv.Atoi(str)\n\tif err != nil || v < int(policy.LogDetailNone) || v > int(policy.LogDetailMax) {\n\t\treturn errors.Errorf(\"must be >= %v and <= %v or %q\", policy.LogDetailNone, policy.LogDetailMax, inheritPolicyString)\n\t}\n\n\t*changeCount++\n\n\tlog(ctx).Infof(\" - setting %q to %v.\", desc, v)\n\n\tov := policy.LogDetail(v)\n\t*val = &ov\n\n\treturn nil\n}\n","sourceCodeStart":59,"sourceCodeEnd":89,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/cli/command_policy_set_logging.go#L59-L89","documentation":"The root-cause error for all six log-detail flags: applyPolicyLogDetailPtr rejected the supplied value because strconv.Atoi failed or the integer falls outside [policy.LogDetailNone, policy.LogDetailMax]. The message itself states the accepted range and the 'inherit' alternative.","triggerScenarios":"Any of --log-dir-snapshotted, --log-dir-ignored, --log-entry-snapshotted, --log-entry-ignored, --log-entry-cache-hit, --log-entry-cache-miss given a value that Atoi cannot parse (non-numeric, float, empty-with-content flags) or an integer < LogDetailNone or > LogDetailMax.","commonSituations":"Users guessing verbosity levels (e.g. 5, 10) beyond the small enum range; passing 'none'/'max' names instead of numbers; typos and whitespace in scripted invocations.","solutions":["Read the message's range hint and retry with an integer in [LogDetailNone..LogDetailMax].","Pass 'inherit' to reset the field to the parent policy's value.","In automation, clamp/validate the integer against the enum bounds before calling kopia."],"exampleFix":"// before\nkopia policy set /path --log-dir-snapshotted 10\n// after\nkopia policy set /path --log-dir-snapshotted 2","handlingStrategy":"validation","validationCode":"func clampLogDetail(v int) (policy.LogDetail, error) {\n    if v < int(policy.LogDetailNone) || v > int(policy.LogDetailMax) {\n        return 0, fmt.Errorf(\"log detail %d outside [%d,%d]\", v, policy.LogDetailNone, policy.LogDetailMax)\n    }\n    return policy.LogDetail(v), nil\n}","typeGuard":"func isInRange(v int) bool {\n    return v >= int(policy.LogDetailNone) && v <= int(policy.LogDetailMax)\n}","tryCatchPattern":"if _, err := strconv.Atoi(s); err != nil {\n    return fmt.Errorf(\"log detail must be an integer in [%d,%d] or %q\", policy.LogDetailNone, policy.LogDetailMax, \"inherit\")\n}","preventionTips":["Memorize/derive the bounds from policy.LogDetailNone and policy.LogDetailMax — don't guess levels like 5 or 10.","Offer named levels (none/1/2) in your wrapper tooling mapped to valid integers.","Validate with the same range check the library uses before shelling out to kopia."],"tags":["cli","policy","enum","validation"],"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"}