{"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":"validation","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/8a468df065a75c1c7cf9f6850f32148746590ea5/tpl/crypto/crypto.go#L67-L103","documentation":"`crypto.Hash` accepts either one argument (the value, hashed with the default sha256) or two arguments (algorithm name, then value). Any other arity — zero arguments or three or more — hits the switch default and returns this error before any hashing happens.","triggerScenarios":"`{{ crypto.Hash }}` with no arguments; `{{ crypto.Hash \"sha256\" $v $extra }}` with three arguments; passing an encoding argument by analogy with `hmac`, which does take an optional encoding — `crypto.Hash` does not.","commonSituations":"Copying an `hmac` call pattern (which takes hash, key, message, encoding) to `crypto.Hash`; splitting a value into multiple template arguments accidentally (unquoted strings with spaces); pipelines that append an extra final argument, e.g. `{{ $v | crypto.Hash \"sha256\" \"hex\" }}`.","solutions":["Call it as `crypto.Hash VALUE` or `crypto.Hash ALGORITHM VALUE` — exactly one or two arguments.","If you wanted a keyed/encoded digest, use `hmac` instead, which takes hash, key, message, and an optional encoding.","Quote multi-word string arguments so they aren't parsed as separate arguments."],"exampleFix":"<!-- before -->\n{{ crypto.Hash \"sha256\" $content \"hex\" }}\n<!-- after -->\n{{ crypto.Hash \"sha256\" $content }}","handlingStrategy":"validation","validationCode":"{{/* call with exactly (options?, data): */}}\n{{ crypto.Hash \"sha256\" \"data\" }} or {{ \"data\" | crypto.Hash \"sha256\" }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["crypto.Hash takes 1 or 2 arguments — algorithm plus data; never pipe extra values","Check pipeline order: `| crypto.Hash \"sha256\"` appends data as the last arg","Consult the Hugo docs signature before adding option maps"],"tags":["hugo","templates","crypto","arguments"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}