elastic/elasticsearch · error · GradleException

Process '%s %s' finished with non-zero exit value %d

Error message

Process '%s %s' finished with non-zero exit value %d

What it means

LoggedExec.run() throws this after a process exits with non-zero status, but only when the logger is NOT at info level (the info-level path lets Gradle's own exec error handling surface). The task first dumps the captured stdout/stderr via outputLogger, then throws this GradleException with the executable, args, and exit code so the build fails with actionable context.

Source

Thrown at build-tools/src/main/java/org/elasticsearch/gradle/LoggedExec.java:186

                execSpec.setStandardInput(new ByteArrayInputStream(getStandardInput().get().getBytes(StandardCharsets.UTF_8)));
            }
        });
        int exitValue = execResult.getExitValue();

        if (exitValue == 0 && getCaptureOutput().get()) {
            output = byteStreamToString(out);
        }
        if (getLogger().isInfoEnabled() == false) {
            if (exitValue != 0) {
                try {
                    if (getIndentingConsoleOutput().isPresent() == false) {
                        getLogger().error("Output for " + getExecutable().get() + ":");
                    }
                    outputLogger.accept(getLogger());
                } catch (Exception e) {
                    throw new GradleException("Failed to read exec output", e);
                }
                throw new GradleException(
                    String.format("Process '%s %s' finished with non-zero exit value %d", getExecutable().get(), getArgs().get(), exitValue)
                );
            }
        }

    }

    private String byteStreamToString(OutputStream out) {
        return ((ByteArrayOutputStream) out).toString(StandardCharsets.UTF_8);
    }

    public static ExecResult exec(ExecOperations execOperations, Action<ExecSpec> action) {
        return genericExec(execOperations::exec, action);
    }

    public static ExecResult javaexec(ExecOperations project, Action<JavaExecSpec> action) {
        return genericExec(project::javaexec, action);
    }

View on GitHub (pinned to db6a809a66)

Solutions

  1. Read the 'Output for <executable>:' block logged just before this exception — it contains the process's stderr/stdout explaining the real failure.
  2. Re-run with --info to get Gradle's native exec error with full streaming output.
  3. Verify the executable path and args via commandLine()/args(); check the tool exists on PATH and is executable.
  4. If the failure is expected in some contexts, set ignoreExitValue via a custom subclass (LoggedExec hardcodes setIgnoreExitValue(true) internally, so you must handle exitValue yourself in a subclass).
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify the command exists and args are correct before execution
File exe = new File(loggedExec.getExecutable().get());
if (!exe.exists() && !onPath(exe.getName())) throw new IllegalStateException("Missing executable: " + exe);

Try / catch

try { task.exec(); } catch (GradleException e) { /* message contains executable, args, exit code — surface to build failure */ throw e; }

Prevention

When it happens

Trigger: Any LoggedExec task whose executed command returns a non-zero exit code while the build logger is above info level. The message includes the executable path, the args list, and the numeric exit value.

Common situations: A wrapped native tool (e.g., a code generator, formatter, or build helper) failing; missing executable on PATH; incorrect arguments passed via commandLine() or args(); the underlying command genuinely fails (test failures, missing input files).

Related errors


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