apache/flink · error · CliArgsException

Missing JobId

Error message

Missing JobId

What it means

Thrown by CliFrontend.parseJobId (CliFrontend.java:1161) when the jobId string argument is null for commands that require a job ID (cancel, stop, savepoint dispose, trigger checkpoint). The parse() method at CliFrontendParser.java:696 wraps commons-cli ParseException messages into CliArgsException, but the specific 'Missing JobId' message originates from parseJobId checking for a null jobIdString. Flink needs a valid JobID hex string to target the specific job for the operation.

Source

Thrown at flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java:696

            return SavepointRestoreSettings.forPath(
                    savepointPath, allowNonRestoredState, recoveryClaimMode);
        } else {
            return SavepointRestoreSettings.none();
        }
    }

    // --------------------------------------------------------------------------------------------
    //  Line Parsing
    // --------------------------------------------------------------------------------------------

    public static CommandLine parse(Options options, String[] args, boolean stopAtNonOptions)
            throws CliArgsException {
        final DefaultParser parser = new DefaultParser();

        try {
            return parser.parse(options, args, stopAtNonOptions);
        } catch (ParseException e) {
            throw new CliArgsException(e.getMessage());
        }
    }

    /**
     * Merges the given {@link Options} into a new Options object.
     *
     * @param optionsA options to merge, can be null if none
     * @param optionsB options to merge, can be null if none
     * @return
     */
    public static Options mergeOptions(@Nullable Options optionsA, @Nullable Options optionsB) {
        final Options resultOptions = new Options();
        if (optionsA != null) {
            for (Option option : optionsA.getOptions()) {
                resultOptions.addOption(option);
            }
        }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Provide the JobID as a positional argument: `flink cancel <32-hex-char-jobId>`
  2. Get the JobID from `flink list` output first, then pass it to cancel/stop
  3. In scripts, validate the jobId variable is non-empty before invoking the command

Example fix

# before
flink cancel

# after
flink cancel a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4
Defensive patterns

Strategy: validation

Validate before calling

if (jobIdString == null || jobIdString.isBlank()) {
    throw new IllegalArgumentException(
        "JobId is required. Run 'flink list' to find the job ID.");
}
JobID jobId = JobID.fromHexString(jobIdString); // validate format

Try / catch

try {
    JobID jobId = cliFrontend.parseJobId(jobIdArg);
} catch (CliArgsException e) {
    if (e.getMessage().contains("Missing JobId")) {
        System.err.println("Usage: flink cancel <jobId>");
    }
    throw e;
}

Prevention

When it happens

Trigger: Running `flink cancel` or `flink stop` with no positional jobId argument; providing the jobId via the wrong flag so the positional parser receives nothing; the jobId positional argument is consumed by an earlier option that stole it.

Common situations: User runs `flink cancel` expecting a prompt but gets an immediate error; user passes --jobId (wrong flag) instead of a bare positional argument; shell scripting that conditionally appends the jobId but the variable evaluates to empty.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/b82187d7c0bdc23d. Report an issue: GitHub.