{"record":{"id":"dbd05d2562a61571","repo":"elastic/elasticsearch","slug":"failed-to-read-oci-image-layout-index-indexjson","errorCode":null,"errorMessage":"Failed to read OCI image layout index [{indexJson}]","messagePattern":"Failed to read OCI image layout index \\[(.+?)\\]","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/docker/DockerBuildTask.java","lineNumber":349,"sourceCode":"         * manifest digest from {@code index.json} is the most robust way to reference the\n         * (single-image) layouts we export.\n         */\n        private static String resolveBuildContext(String value) {\n            String prefix = \"oci-layout://\";\n            if (value.startsWith(prefix) == false || value.contains(\"@\")) {\n                return value;\n            }\n            Path indexJson = Path.of(value.substring(prefix.length()), \"index.json\");\n            try {\n                // The exported layouts contain a single manifest, so plucking the first digest is\n                // sufficient and avoids a JSON parser dependency in this worker action.\n                Matcher matcher = Pattern.compile(\"sha256:[a-f0-9]{64}\").matcher(Files.readString(indexJson));\n                if (matcher.find() == false) {\n                    throw new GradleException(\"No manifest digest found in OCI image layout index [\" + indexJson + \"]\");\n                }\n                return value + \"@\" + matcher.group();\n            } catch (IOException e) {\n                throw new UncheckedIOException(\"Failed to read OCI image layout index [\" + indexJson + \"]\", e);\n            }\n        }\n\n        private boolean isCrossPlatform() {\n            return getParameters().getPlatforms()\n                .get()\n                .stream()\n                .anyMatch(any -> any.equals(Architecture.current().dockerPlatform) == false);\n        }\n\n        private String getImageChecksum(String imageTag) {\n            final ByteArrayOutputStream stdout = new ByteArrayOutputStream();\n            String docker = getParameters().getDockerExecutable().get();\n\n            execOperations.exec(spec -> {\n                spec.setCommandLine(docker, \"inspect\", \"--format\", \"{{ .Id }}\", imageTag);\n                spec.setStandardOutput(stdout);\n                spec.setIgnoreExitValue(false);","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/docker/DockerBuildTask.java#L331-L367","documentation":"Thrown by DockerBuildTask.resolveBuildContext() when reading the OCI layout's index.json throws an IOException (the digest-search step from error 218 proceeds only after a successful read). The IOException is wrapped in an UncheckedIOException naming the index.json path. This is the I/O-level failure counterpart to error 218's content-level failure.","triggerScenarios":"Files.readString(indexJson) throws IOException while resolving an `oci-layout://` build context. Causes: index.json does not exist (the layout directory is missing or incomplete); it is a directory rather than a file; permission denied; filesystem/mount error; the path resolved from the `oci-layout://` prefix is invalid.","commonSituations":"The OCI layout export task did not run or failed, so the directory/index.json is absent; a path typo in the `oci-layout://` value points at a non-existent directory; running on a CI worker where the layout artifact was not materialized; permissions mismatch.","solutions":["Confirm the index.json at the reported path exists and is readable: `ls -l <indexJson>`.","Re-run the task that produces/exports the OCI layout so the directory and index.json are created.","Check the `oci-layout://<path>` value in the build config for typos or stale paths.","Verify filesystem permissions for the build user."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before building, assert index.json exists and is readable:\n// if (!Files.isReadable(indexJson)) fail(\"unreadable OCI index: \" + indexJson);","typeGuard":null,"tryCatchPattern":"// try { String json = Files.readString(indexJson); /* search digest */ }\n// catch (IOException e) { throw new UncheckedIOException(\"Failed to read OCI image layout index [\" + indexJson + \"]\", e); }","preventionTips":["Make the OCI layout export task a declared dependency of the Docker build task.","Confirm the `oci-layout://` path resolves to a real, populated directory.","Verify filesystem permissions for the build user before building."],"tags":["docker","build","oci","io"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}