{"record":{"id":"fbedcc322070377f","repo":"apache/flink","slug":"error-parsing-arguments-s-on-s-please-prefi","errorCode":null,"errorMessage":"Error parsing arguments '%s' on '%s'. Please prefix keys with -- or -.","messagePattern":"Error parsing arguments '(.+?)' on '(.+?)'\\. Please prefix keys with -- or -\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/Utils.java","lineNumber":354,"sourceCode":"        return Optional.ofNullable(factory);\n    }\n\n    /**\n     * Get the key from the given args. Keys have to start with '-' or '--'. For example, --key1\n     * value1 -key2 value2.\n     *\n     * @param args all given args.\n     * @param index the index of args to be parsed.\n     * @return the key of the given arg.\n     */\n    public static String getKeyFromArgs(String[] args, int index) {\n        String key;\n        if (args[index].startsWith(\"--\")) {\n            key = args[index].substring(2);\n        } else if (args[index].startsWith(\"-\")) {\n            key = args[index].substring(1);\n        } else {\n            throw new IllegalArgumentException(\n                    String.format(\n                            \"Error parsing arguments '%s' on '%s'. Please prefix keys with -- or -.\",\n                            Arrays.toString(args), args[index]));\n        }\n\n        if (key.isEmpty()) {\n            throw new IllegalArgumentException(\n                    \"The input \" + Arrays.toString(args) + \" contains an empty argument\");\n        }\n\n        return key;\n    }\n\n    /** Private constructor to prevent instantiation. */\n    private Utils() {\n        throw new RuntimeException();\n    }\n}","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/Utils.java#L336-L372","documentation":"Utils.getKeyFromArgs expects every CLI-style key token to start with '--' (long) or '-' (short). A token at the given index that starts with neither is rejected with this IllegalArgumentException showing the full args array and the offending token, since the parser cannot tell where the key ends and a value begins.","triggerScenarios":"Calling getKeyFromArgs(args, i) where args[i] is a bare word like \"input\" instead of \"--input\", or a value token reached while the parser expected a key (option value consumed and next token is unprefixed).","commonSituations":"Wrong argument order in bin/flink CLI invocations (value before key), shell scripts dropping the leading dashes, options that take no value followed by another unprefixed token, programmatic use of the utility with unnormalized args.","solutions":["Add the '--' prefix to the offending key token shown in the message.","Check argument order: '-k value' not 'value -k'; ensure options declared as flag-only are not followed by an expected value token.","Escape/quote dashes in shell scripts so they are not swallowed as options."],"exampleFix":"# before\nflink run app.jar input /data\n\n# after\nflink run app.jar --input /data","handlingStrategy":"validation","validationCode":"static boolean isKeyToken(String s) { return s.startsWith(\"--\") && s.length() > 2 || s.startsWith(\"-\") && s.length() > 1; }\nfor (String a : args) if (needsPrefix(a) && !isKeyToken(a)) throw new IllegalArgumentException(\"Missing -- prefix: \" + a);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always prefix keys with '--' and place values after keys.","Validate CLI arg shape before parsing in programmatic entry points.","Quote args in shell scripts to keep dashes intact."],"tags":["cli","arguments","parsing","validation"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}