kubernetes/kops · error
unable to parse sha: %q, %v
Error message
unable to parse sha: %q, %v
What it means
The expected sha string is parsed via hashing.FromString(strings.TrimSpace(sha)); if the hash string cannot be parsed into a known hashing object (e.g. it is not valid hex of length 40/64, or an unrecognized algorithm prefix), the task fails with 'unable to parse sha: <sha>, <reason>'.
Source
Thrown at pkg/assets/assetcopy/copyfile.go:140
uploadVFS, err := vfsContext.BuildVfsPath(objectStore)
if err != nil {
return fmt.Errorf("error building path %q: %v", objectStore, err)
}
shaExtension, err := fileExtensionForSHA(sha)
if err != nil {
return err
}
shaTarget := objectStore + shaExtension
shaVFS, err := vfsContext.BuildVfsPath(shaTarget)
if err != nil {
return fmt.Errorf("error building path %q: %v", shaTarget, err)
}
shaHash, err := hashing.FromString(strings.TrimSpace(sha))
if err != nil {
return fmt.Errorf("unable to parse sha: %q, %v", sha, err)
}
in := bytes.NewReader(data)
dataHash, err := shaHash.Algorithm.Hash(in)
if err != nil {
return fmt.Errorf("unable to hash file %q downloaded: %v", source, err)
}
if !shaHash.Equal(dataHash) {
return fmt.Errorf("the sha value in %q does not match %q calculated value %q", shaTarget, source, dataHash.String())
}
klog.Infof("uploading %q to %q", source, objectStore)
if err := writeFile(ctx, cluster, uploadVFS, data); err != nil {
return err
}
b := []byte(shaHash.Hex())View on GitHub (pinned to 4c8573c808)
Solutions
- Inspect the sha printed in the error for non-hex characters.
- Regenerate the correct sha1/sha256 of the source file (shasum / openssl dgst).
- Fix the source checksum file or the cluster spec's sha value.
- Re-run `kops get assets --copy`.
Example fix
// before zzzz6c35c94fcfb415dbe95f408b9ce91ee846ed file.tar.gz # not hex // after 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed file.tar.gz
Defensive patterns
Strategy: validation
Validate before calling
sha := strings.TrimSpace(expectedSHA)
if _, err := hex.DecodeString(sha); err != nil {
return fmt.Errorf("sha must be hex: %v", err)
}
if len(sha) != 40 && len(sha) != 64 {
return fmt.Errorf("sha must be 40 or 64 hex chars, got %d", len(sha))
} Prevention
- Regenerate checksums with shasum/openssl instead of hand-editing
- Validate checksum files (hex, correct length) before publishing to mirrors
- Never placeholder-fill sha fields in generated specs
- Cross-check a published sha against the actual file once before bulk copy
When it happens
Trigger: FileAsset.SHAValue contains characters that are not valid hex, or a hash in a format hashing.FromString does not recognize (lengths already validated as 40/64 by fileExtensionForSHA, so this catches non-hex garbage of those lengths).
Common situations: A hand-edited checksum file or asset spec with placeholder text ('<sha256>') padded/truncated to pass length checks; a corrupted checksum fetched from a broken mirror.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- unhandled sha length for %q
- unable to hash file %q downloaded: %v
- %s: %v
- not all assets copied successfully
- unable to transfer %q to %q: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/f9df1b9c59b83112.
Report an issue: GitHub.