{"record":{"id":"3694ebb6428a930a","repo":"GoogleContainerTools/jib","slug":"expected-valid-layer-digest-as-contents-of-selecto","errorCode":null,"errorMessage":"Expected valid layer digest as contents of selector file `<selectorFile>` for selector `<selector>`, but got: <contents>","messagePattern":"Expected valid layer digest as contents of selector file `<selectorFile>` for selector `<selector>`, but got: <contents>","errorType":"exception","errorClass":"CacheCorruptedException","httpStatus":null,"severity":"error","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/cache/CacheStorageReader.java","lineNumber":258,"sourceCode":"   * @param selector the selector\n   * @return the layer digest {@code selector} selects, if found\n   * @throws CacheCorruptedException if the selector file contents was not a valid layer digest\n   * @throws IOException if an I/O exception occurs\n   */\n  Optional<DescriptorDigest> select(DescriptorDigest selector)\n      throws CacheCorruptedException, IOException {\n    Path selectorFile = cacheStorageFiles.getSelectorFile(selector);\n    if (!Files.exists(selectorFile)) {\n      return Optional.empty();\n    }\n\n    String selectorFileContents =\n        new String(Files.readAllBytes(selectorFile), StandardCharsets.UTF_8);\n    try {\n      return Optional.of(DescriptorDigest.fromHash(selectorFileContents));\n\n    } catch (DigestException ex) {\n      throw new CacheCorruptedException(\n          cacheStorageFiles.getCacheDirectory(),\n          \"Expected valid layer digest as contents of selector file `\"\n              + selectorFile\n              + \"` for selector `\"\n              + selector.getHash()\n              + \"`, but got: \"\n              + selectorFileContents);\n    }\n  }\n}\n","sourceCodeStart":240,"sourceCodeEnd":269,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/cache/CacheStorageReader.java#L240-L269","documentation":"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.","triggerScenarios":"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.","commonSituations":"JVM or machine crash mid-write of the selector file, disk corruption, manual editing, or cache manipulation by external scripts.","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)"],"exampleFix":"// before: selector file contains \"\" or \"sha256:abc\"\n// after: remove it; Jib rewrites it\nrm \"$(echo $HOME)/.cache/google-cloud-tools-java/jib/selectors/<selector>\"","handlingStrategy":"try-catch","validationCode":"String s = Files.readString(selectorFile).trim();\nif (!s.matches(\"[0-9a-f]{64}\")) Files.deleteIfExists(selectorFile);","typeGuard":"boolean isValidDigest(String s) {\n  return s != null && s.matches(\"[0-9a-f]{64}\");\n}","tryCatchPattern":"try {\n  build();\n} catch (CacheCorruptedException e) {\n  if (e.getMessage().contains(\"selector file\")) {\n    Files.deleteIfExists(selectorPathFrom(e.getMessage()));\n    build();\n  }\n}","preventionTips":["Never edit selector files manually","Ensure graceful shutdown of builds (avoid SIGKILL)","Monitor disks for corruption (fsck/SMART)"],"tags":["cache","digest","corruption"],"backgroundTag":"invalid-identifier-format","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}