{"record":{"id":"ffd21cb3e85c465f","repo":"docker/cli","slug":"failed-to-parse-hook-template-arg-dth-argument","errorCode":null,"errorMessage":"failed to parse hook template: arg: %dth argument not set","messagePattern":"failed to parse hook template: arg: (.+?)th argument not set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"cli-plugins/hooks/template.go","lineNumber":92,"sourceCode":"\tif c.cmd == nil {\n\t\treturn \"\", fmt.Errorf(\"%w: flagValue: cmd is nil\", ErrHookTemplateParse)\n\t}\n\tf := c.cmd.Flag(flagName)\n\tif f == nil {\n\t\treturn \"\", fmt.Errorf(\"%w: flagValue: no flags found\", ErrHookTemplateParse)\n\t}\n\treturn f.Value.String(), nil\n}\n\n// argValue returns the value of the nth argument.\nfunc (c commandInfo) argValue(n int) (string, error) {\n\tif c.cmd == nil {\n\t\treturn \"\", fmt.Errorf(\"%w: arg: cmd is nil\", ErrHookTemplateParse)\n\t}\n\tflags := c.cmd.Flags()\n\tv := flags.Arg(n)\n\tif v == \"\" && n >= flags.NArg() {\n\t\treturn \"\", fmt.Errorf(\"%w: arg: %dth argument not set\", ErrHookTemplateParse, n)\n\t}\n\treturn v, nil\n}\n","sourceCodeStart":74,"sourceCodeEnd":96,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli-plugins/hooks/template.go#L74-L96","documentation":"Returned (wrapped in ErrHookTemplateParse) by commandInfo.argValue when the requested nth positional argument was not provided (n >= NArg). The argValue template func indexes into cobra's positional args; requesting an index beyond what was supplied fails.","triggerScenarios":"A hook template using {{argValue 2}} on a command invocation that passed fewer than 3 positional arguments.","commonSituations":"A plugin template that assumes a fixed number of positional args, invoked with optional/missing trailing args, or a subcommand that accepts variadic input.","solutions":["Request argument indices only when the command is known to supply them.","Make hook logic conditional on the number of args rather than assuming a fixed arity.","Lower the requested index to one that is always present."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"flags := cmd.Flags()\nif n >= flags.NArg() {\n    return fmt.Errorf(\"argument %d not provided (have %d)\", n, flags.NArg())\n}","typeGuard":null,"tryCatchPattern":"if v, err := msgContext.argValue(n); err != nil {\n    // handle missing optional arg\n}","preventionTips":["Do not assume a fixed positional arity in hook templates.","Branch template logic on the actual number of args."],"tags":["hooks","cli-plugins","template","args"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}