{"record":{"id":"9a55373e1d5cd39c","repo":"kopia/kopia","slug":"action-script-file-v-too-long-v-max-allowed","errorCode":null,"errorMessage":"action script file (%v) too long: %v, max allowed %d","messagePattern":"action script file \\((.+?)\\) too long: (.+?), max allowed (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command_policy_set_actions.go","lineNumber":89,"sourceCode":"\n\t\treturn nil\n\t}\n\n\t*cmd = &policy.ActionCommand{\n\t\tTimeoutSeconds: int(c.policySetActionCommandTimeout.Seconds()),\n\t\tMode:           c.policySetActionCommandMode,\n\t}\n\n\t*changeCount++\n\n\tif c.policySetPersistActionScript {\n\t\tscript, err := os.ReadFile(value) //nolint:gosec\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"unable to read script file\")\n\t\t}\n\n\t\tif len(script) > maxScriptLength {\n\t\t\treturn errors.Errorf(\"action script file (%v) too long: %v, max allowed %d\", value, len(script), maxScriptLength)\n\t\t}\n\n\t\tlog(ctx).Infof(\" - setting %v (%v) action script from file %v (%v bytes) with timeout %v\", actionName, c.policySetActionCommandMode, value, len(script), c.policySetActionCommandTimeout)\n\n\t\t(*cmd).Script = string(script)\n\n\t\treturn nil\n\t}\n\n\t// parse path as CSV as if space was the separator, this automatically takes care of quotations\n\tr := csv.NewReader(strings.NewReader(value))\n\tr.Comma = ' ' // space\n\n\tfields, err := r.Read()\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"error parsing %v command\", actionName)\n\t}\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/cli/command_policy_set_actions.go#L71-L107","documentation":"Raised by setActionCommandFromFlags when the script file supplied via --action-command-script-file is larger than maxScriptLength. Kopia refuses to store oversized action scripts in the policy to keep policy documents small. The error message includes the file path, its byte length, and the maximum allowed size.","triggerScenarios":"Running `kopia policy set ... --action-command-script-file <path>` where the file's byte size exceeds maxScriptLength. Check `wc -c <path>` against the limit shown in the error message.","commonSituations":"Pointing the flag at a large payload/data file by mistake, bundling a whole library into the action script, or auto-generated scripts that grew over time.","solutions":["Shrink the script: move large data or helper code out of the action script and keep only the orchestration logic.","Have the script reference external files on disk instead of embedding their content.","Check the size with `wc -c <file>` and compare with the 'max allowed' value in the error message to confirm the overage.","If the file was picked by mistake, point the flag at the intended, small script file."],"exampleFix":"// before: embedding 2MB of data in the action script\nkopia policy set --global --action-command-script-file ./huge-script-with-embedded-data.sh\n// error: action script file (./huge-script-with-embedded-data.sh) too long: 2048000, max allowed 65536\n\n// after: keep the script small, reference external data\nhead -c 100 huge-script-with-embedded-data.sh > action.sh  # or rewrite it to read /var/lib/kopia/data at runtime\nkopia policy set --global --action-command-script-file ./action.sh","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst MAX_SCRIPT_LENGTH = 65536; // confirm against the limit in the error message\nfunction validateScriptSize(path) {\n  const size = fs.statSync(path).size;\n  if (size > MAX_SCRIPT_LENGTH) {\n    throw new Error(`Script ${path} is ${size} bytes; max ${MAX_SCRIPT_LENGTH}`);\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  run(['kopia', 'policy', 'set', '--global', '--action-command-script-file', scriptPath]);\n} catch (err) {\n  if (/too long: \\d+, max allowed (\\d+)/.test(String(err.stderr))) {\n    const max = Number(err.stderr.match(/max allowed (\\d+)/)[1]);\n    console.error(`Shrink script to <= ${max} bytes`);\n  }\n  throw err;\n}","preventionTips":["Check `wc -c <script>` before passing it to --action-command-script-file.","Keep action scripts minimal; load large data from external files at runtime.","Add a size lint step to CI for any script committed for kopia actions."],"tags":["cli","validation","kopia"],"backgroundTag":"file-size-limit-exceeded","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"}