GoogleContainerTools/jib · error · CacheCorruptedException
Expected valid layer digest as contents of selector file `<s
Error message
Expected valid layer digest as contents of selector file `<selectorFile>` for selector `<selector>`, but got: <contents>
What it means
Selector files map one layer digest to an alternative (usually uncompressed) layer digest. select(selector) reads the selector file and expects its UTF-8 contents to be a valid DescriptorDigest hash; if DescriptorDigest.fromHash() fails, CacheCorruptedException is thrown showing the file path, the selector hash, and the actual (invalid) contents.
Source
Thrown at jib-core/src/main/java/com/google/cloud/tools/jib/cache/CacheStorageReader.java:258
* @param selector the selector
* @return the layer digest {@code selector} selects, if found
* @throws CacheCorruptedException if the selector file contents was not a valid layer digest
* @throws IOException if an I/O exception occurs
*/
Optional<DescriptorDigest> select(DescriptorDigest selector)
throws CacheCorruptedException, IOException {
Path selectorFile = cacheStorageFiles.getSelectorFile(selector);
if (!Files.exists(selectorFile)) {
return Optional.empty();
}
String selectorFileContents =
new String(Files.readAllBytes(selectorFile), StandardCharsets.UTF_8);
try {
return Optional.of(DescriptorDigest.fromHash(selectorFileContents));
} catch (DigestException ex) {
throw new CacheCorruptedException(
cacheStorageFiles.getCacheDirectory(),
"Expected valid layer digest as contents of selector file `"
+ selectorFile
+ "` for selector `"
+ selector.getHash()
+ "`, but got: "
+ selectorFileContents);
}
}
}
View on GitHub (pinned to fb949e2676)
Solutions
- Delete the offending selector file (path is given in the message) and rebuild
- Clear the entire cache directory to force selectors to be regenerated
- Inspect the file contents shown in the error to identify what corrupted it (often empty)
- Ensure builds are not killed abruptly (avoid SIGKILL/cancelled jobs mid-write)
Example fix
// before: selector file contains "" or "sha256:abc" // after: remove it; Jib rewrites it rm "$(echo $HOME)/.cache/google-cloud-tools-java/jib/selectors/<selector>"
Defensive patterns
Strategy: try-catch
Validate before calling
String s = Files.readString(selectorFile).trim();
if (!s.matches("[0-9a-f]{64}")) Files.deleteIfExists(selectorFile); Type guard
boolean isValidDigest(String s) {
return s != null && s.matches("[0-9a-f]{64}");
} Try / catch
try {
build();
} catch (CacheCorruptedException e) {
if (e.getMessage().contains("selector file")) {
Files.deleteIfExists(selectorPathFrom(e.getMessage()));
build();
}
} Prevention
- Never edit selector files manually
- Ensure graceful shutdown of builds (avoid SIGKILL)
- Monitor disks for corruption (fsck/SMART)
When it happens
Trigger: CacheStorageReader.select() reads a selector file whose contents are not a 64-character hex digest — e.g. empty file, truncated write, or a path/blob reference instead of a hash.
Common situations: JVM or machine crash mid-write of the selector file, disk corruption, manual editing, or cache manipulation by external scripts.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- Layer file did not include valid hash: <layerFile>
- Manifest cache empty
- Manifest(s) missing
- Manifest list missing
- Schema 1 manifests corrupted
AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06).
Data as JSON: /api/errors/3694ebb6428a930a.
Report an issue: GitHub.