{"record":{"id":"731a320832772460","repo":"gohugoio/hugo","slug":"crypto-hash-expected-1-or-2-arguments-got-d","errorCode":null,"errorMessage":"crypto.Hash: expected 1 or 2 arguments, got %d","messagePattern":"crypto\\.Hash: expected 1 or 2 arguments, got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/crypto/crypto.go","lineNumber":85,"sourceCode":"\thash := sha256.Sum256([]byte(conv))\n\treturn hex.EncodeToString(hash[:]), nil\n}\n\n// Hash returns the hex-encoded checksum of v using the given algorithm; one of\n// md5, sha1, sha256 (the default), sha384 or sha512.\n//\n// The supported algorithms match those used for the Subresource Integrity (SRI)\n// hash in .Data.Integrity on fingerprinted resources, so an SRI hash can be\n// constructed by combining this with encoding.HexDecode and encoding.Base64Encode.\nfunc (ns *Namespace) Hash(args ...any) (string, error) {\n\tvar algo, v any\n\tswitch len(args) {\n\tcase 1:\n\t\talgo, v = \"sha256\", args[0]\n\tcase 2:\n\t\talgo, v = args[0], args[1]\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"crypto.Hash: expected 1 or 2 arguments, got %d\", len(args))\n\t}\n\n\tconv, err := cast.ToStringE(v)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\talgoS, err := cast.ToStringE(algo)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\th, err := newHash(algoS)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tif _, err := h.Write([]byte(conv)); err != nil {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/crypto/crypto.go#L67-L103","documentation":"`crypto.Hash` (crypto.go:77-86) accepts either one argument (just the value, defaulting the algorithm to `sha256`) or two arguments (algorithm then value). Any other count — zero args, or three or more — hits the `default` switch arm and returns this error with the actual argument count.","triggerScenarios":"`{{ crypto.Hash }}` (no args), `{{ crypto.Hash \"sha256\" \"data\" \"extra\" }}` (3 args), or accidentally spreading an options dict.","commonSituations":"Forgetting the value; passing algorithm + value + options expecting map-args; template macro forwarding an arg slice.","solutions":["Call with one arg: `{{ crypto.Hash $value }}` (defaults to sha256).","Call with two args: `{{ crypto.Hash \"sha512\" $value }}`.","Remove any extra positional arguments beyond algorithm and value."],"exampleFix":"// before\n{{ crypto.Hash }}\n// after\n{{ crypto.Hash $value }}\n{{ crypto.Hash \"sha512\" $value }}","handlingStrategy":"validation","validationCode":"{{/* crypto.Hash: 1 arg (value, sha256) or 2 args (algo, value) */}}\n{{ crypto.Hash $value }}\n{{ crypto.Hash \"sha512\" $value }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass either just the value, or algorithm then value.","Do not spread extra args or options dicts into crypto.Hash.","Prefer the single-arg form when sha256 is acceptable."],"tags":["hugo","go-templates","crypto","hash","arity"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}