{"record":{"id":"691eb6b7d8b3a99e","repo":"hashicorp/terraform","slug":"cannot-hash-package-at-s","errorCode":null,"errorMessage":"cannot hash package at %s","messagePattern":"cannot hash package at (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/getproviders/hash.go","lineNumber":308,"sourceCode":"\n\t\t// The dirhash.HashDir result is already in our expected h1:...\n\t\t// format, so we can just convert directly to Hash.\n\t\ts, err := dirhash.HashDir(packageDir, \"\", dirhash.Hash1)\n\t\treturn Hash(s), err\n\n\tcase PackageLocalArchive:\n\t\tarchivePath, err := filepath.EvalSymlinks(string(loc))\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\n\t\t// The dirhash.HashDir result is already in our expected h1:...\n\t\t// format, so we can just convert directly to Hash.\n\t\ts, err := dirhash.HashZip(archivePath, dirhash.Hash1)\n\t\treturn Hash(s), err\n\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"cannot hash package at %s\", loc.String())\n\t}\n}\n\n// Hash computes a hash of the contents of the package at the location\n// associated with the reciever, using whichever hash algorithm is the current\n// default.\n//\n// This method will change to use new hash versions as they are introduced\n// in future. If you need a specific hash version, call the method for that\n// version directly instead, such as HashV1.\n//\n// Hash can be used only with the two local package location types\n// PackageLocalDir and PackageLocalArchive, because it needs to access the\n// contents of the indicated package in order to compute the hash. If given\n// a non-local location this function will always return an error.\nfunc (m PackageMeta) Hash() (providerreqs.Hash, error) {\n\treturn PackageHash(m.Location)\n}","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/getproviders/hash.go#L290-L326","documentation":"`PackageHashV1` switches on the concrete location type and only handles `PackageLocalDir` and `PackageLocalArchive`. Any other `PackageLocation` (e.g. `PackageHTTPURL`, `PackageLocalArchive` mismatch, or a custom impl) hits the `default` and returns this error stating hashing is unsupported for that location.","triggerScenarios":"`PackageHashV1(loc)` is called with a location that is neither `PackageLocalDir` nor `PackageLocalArchive`; default at hash.go:308.","commonSituations":"Caller attempts to hash a remote `PackageHTTPURL` directly without downloading first; a nil or empty location slipped through; an unmounted archive whose location type is not recognised.","solutions":["Download/extract the package to a local path first, then pass `PackageLocalDir` or `PackageLocalArchive` to `PackageHashV1`.","Check the location type before calling: only hash local locations.","Ensure the cache directory is populated (run `terraform init`) before hash computation."],"exampleFix":"// before\nh, err := PackageHashV1(PackageHTTPURL(u)) // -> cannot hash\n// after: download to cache first\npath, _ := installer.DownloadAndUnpack(ctx, meta, tmpDir, nil)\nh, err := PackageHashV1(PackageLocalDir(path))","handlingStrategy":"type-guard","validationCode":"// Only hash local locations\nswitch loc.(type) {\ncase PackageLocalDir, PackageLocalArchive:\n    return PackageHashV1(loc)\ndefault:\n    return \"\", fmt.Errorf(\"cannot hash remote location %s; download first\", loc)\n}","typeGuard":"// isHashableLocal reports whether loc can be hashed\nfunc isHashableLocal(loc PackageLocation) bool {\n    switch loc.(type) {\n    case PackageLocalDir, PackageLocalArchive:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Always download/unpack providers to the local cache before hashing.","Type-check locations before invoking hash functions.","Write helper wrappers that handle only local locations and fail clearly otherwise.","Keep installer output types consistent (always return PackageLocalDir)."],"tags":["hash","package-location","installer"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}