elastic/elasticsearch · error · UncheckedIOException

Failed to read branches.json from {path}

Error message

Failed to read branches.json from {path}

What it means

Wrapped as UncheckedIOException from UpdateBranchesJsonTask.readBranches() when branches.json exists but Files.readAllBytes or branchesFileParser.parse throws IOException — most commonly a malformed JSON file.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/release/UpdateBranchesJsonTask.java:173

            updatedBranches.add(objectNode);
        }
        ((ObjectNode) jsonNode).replace("branches", updatedBranches);

        DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
        prettyPrinter.indentArraysWith(new DefaultIndenter("  ", DefaultIndenter.SYS_LF));
        objectMapper.writer(prettyPrinter).writeValue(branchesFile, jsonNode);
    }

    private List<DevelopmentBranch> readBranches(File branchesFile) {
        if (branchesFile.isFile() == false) {
            throw new InvalidUserDataException("File branches.json has not been found in " + branchesFile.getAbsolutePath());
        }

        try {
            byte[] branchesBytes = Files.readAllBytes(branchesFile.toPath());
            return branchesFileParser.parse(branchesBytes);
        } catch (IOException e) {
            throw new UncheckedIOException("Failed to read branches.json from " + branchesFile.getPath(), e);
        }
    }
}

View on GitHub (pinned to db6a809a66)

Solutions

  1. Validate branches.json with a JSON linter; fix any syntax errors or conflict markers.
  2. Restore the last known-good version from git and re-apply intended changes atomically.
  3. Ensure the file is an array of objects with branch (string) and version (string) fields.
Defensive patterns

Strategy: try-catch

Validate before calling

// Smoke-test that branches.json parses before invoking the task
try {
    new ObjectMapper().readTree(branchesFile);
} catch (IOException e) {
    throw new GradleException("branches.json is not valid JSON: " + e.getMessage(), e);
}

Try / catch

try { task.executeTask(); } catch (UncheckedIOException e) { log.error("branches.json unreadable at {}: {}", branchesFile, e.getMessage()); throw e; }

Prevention

When it happens

Trigger: branches.json is present but is not valid JSON, or does not conform to the shape expected by branchesFileParser (array of {branch, version} objects).

Common situations: A manual edit broke the JSON; a merge conflict left conflict markers in the file; an earlier failed write truncated it.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/26ea95958bf6bcbb. Report an issue: GitHub.