{"record":{"id":"d9d3c38fcd76b98a","repo":"elastic/elasticsearch","slug":"usage-d9d3c3","errorCode":"USAGE","errorMessage":"too many arguments, expected one service id","messagePattern":"too many arguments, expected one service id","errorType":"validation","errorClass":"UserException","httpStatus":null,"severity":"error","filePath":"distribution/tools/windows-service-cli/src/main/java/org/elasticsearch/windows/service/ProcrunCommand.java","lineNumber":99,"sourceCode":"        Process process = startProcess(processBuilder);\n        int ret = process.waitFor();\n        if (ret != ExitCodes.OK) {\n            throw new UserException(ret, getFailureMessage(serviceId));\n        } else {\n            terminal.println(getSuccessMessage(serviceId));\n        }\n    }\n\n    /** Quotes the given String. */\n    static String quote(String s) {\n        return '\"' + s + '\"';\n    }\n\n    /** Determines the service id for the Elasticsearch service that should be used */\n    private static String getServiceId(OptionSet options, Map<String, String> env) throws UserException {\n        List<?> args = options.nonOptionArguments();\n        if (args.size() > 1) {\n            throw new UserException(ExitCodes.USAGE, \"too many arguments, expected one service id\");\n        }\n        final String serviceId;\n        if (args.size() > 0) {\n            serviceId = args.get(0).toString();\n        } else {\n            serviceId = env.getOrDefault(\"SERVICE_ID\", \"elasticsearch-service-x64\");\n        }\n        return serviceId;\n    }\n\n    /** Determines the logging arguments that should be passed to the procrun command */\n    private static String getLogArgs(String serviceId, Path esHome, Map<String, String> env) {\n        String logArgs = env.get(\"LOG_OPTS\");\n        if (logArgs != null && logArgs.isBlank() == false) {\n            return logArgs;\n        }\n        String logsDir = env.get(\"SERVICE_LOG_DIR\");\n        if (logsDir == null || logsDir.isBlank()) {","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/distribution/tools/windows-service-cli/src/main/java/org/elasticsearch/windows/service/ProcrunCommand.java#L81-L117","documentation":"Thrown by ProcrunCommand.getServiceId when more than one non-option argument is passed on the command line. The Windows service commands accept at most one positional argument, interpreted as the service id; anything beyond that is ambiguous and rejected with exit code USAGE. The check fires before the service id is resolved, so it does not depend on whether SERVICE_ID env var is set.","triggerScenarios":"Running `elasticsearch-service.bat install foo bar` (two positional args). Passing extra flags without their leading dash so they are parsed as positional. Copy-paste errors adding a stray token.","commonSituations":"Operators assume the command takes a service name plus an action. Misuse of quoting that splits a single value into two tokens.","solutions":["Pass at most one positional argument (the service id), or none to use the SERVICE_ID env var / default.","Quote any value containing spaces: `elasticsearch-service.bat install \"my service\"`.","Run `elasticsearch-service.bat help` to confirm the expected argument shape."],"exampleFix":"REM before\nbin\\elasticsearch-service.bat install es-9 es-prod\nREM after\nset SERVICE_ID=es-9\nbin\\elasticsearch-service.bat install","handlingStrategy":"validation","validationCode":"List<String> positional = options.nonOptionArguments().stream().map(String::valueOf).toList();\nif (positional.size() > 1) {\n    throw new IllegalArgumentException(\"Expected at most one service id; got \" + positional);\n}","typeGuard":"static boolean atMostOnePositional(List<?> args) {\n    return args != null && args.size() <= 1;\n}","tryCatchPattern":"try {\n    String sid = ProcrunCommand.getServiceId(options, env);\n} catch (UserException e) {\n    if (e.exitCode == ExitCodes.USAGE && e.getMessage().contains(\"too many arguments\")) {\n        // re-print help and exit\n    } else throw e;\n}","preventionTips":["Quote any service id containing spaces.","Prefer setting SERVICE_ID env var over passing it positionally in scripts.","Print usage on argument parse errors in wrappers around the bat file."],"tags":["windows","service","procrun","cli","usage","arguments"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}