{"record":{"id":"32ac7b25fa94dede","repo":"apache/cassandra","slug":"error-running-tool","errorCode":null,"errorMessage":"Error running tool.","messagePattern":"Error running tool\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tools/GenerateTokens.java","lineNumber":110,"sourceCode":"        catch (AssertionError | ConfigurationException | ParseException t)\n        {\n            System.err.println(t.getMessage());\n            System.out.println();\n            printUsage(options);\n            System.exit(1);\n        }\n\n        try\n        {\n            logger.output(String.format(\"Generating tokens for %d nodes with %d vnodes each for replication factor %d and partitioner %s\",\n                                             nodes, tokens, rf, partitioner.getClass().getSimpleName()));\n\n            for (OfflineTokenAllocator.FakeNode node : OfflineTokenAllocator.allocate(rf, tokens, racksDef, logger, partitioner))\n                logger.output(String.format(\"Node %d rack %d: %s\", node.nodeId(), node.rackId(), node.tokens().toString()));\n        }\n        catch (Throwable t)\n        {\n            logger.warn(t, \"Error running tool.\");\n            System.exit(1);\n        }\n    }\n\n    private static int[] getRacks(String racksDef)\n    {\n        return Arrays.stream(racksDef.split(\",\")).mapToInt(Integer::parseInt).toArray();\n    }\n\n    private static CommandLine parseCommandLine(String[] args, Options options) throws ParseException\n    {\n        return new GnuParser().parse(options, args, false);\n    }\n\n    private static Options getOptions()\n    {\n        Options options = new Options();\n        options.addOption(requiredOption(\"n\", NODES, true, \"Number of nodes.\"));","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tools/GenerateTokens.java#L92-L128","documentation":"GenerateTokens is an offline CLI tool that computes token assignments for a cluster. If any Throwable escapes while generating tokens (bad arguments, allocation failure, invalid racks definition), main() logs 'Error running tool.' with the cause and exits with status 1. The logged exception is the real error; this message is only a wrapper.","triggerScenarios":"Running generate_tokens with an invalid replication factor, malformed racks definition string, unknown partitioner, or when OfflineTokenAllocator.allocate throws for the requested topology.","commonSituations":"Passing a racks definition that is non-numeric or does not sum to node count; RF smaller than racks count; typos in command-line options; running the tool without the proper classpath.","solutions":["Read the full stack trace logged under 'Error running tool.' - it names the actual cause.","Validate CLI arguments: RF must be a positive integer, racks definition must match node count (see getRacks parsing).","Fix the racks/token arguments so racks divide evenly across nodes for the given RF.","Re-run the tool with correct arguments; exit code 1 is expected on any failure."],"exampleFix":"// before java -cp ... GenerateTokens 16 3 notanumber // after java -cp ... GenerateTokens 16 3 1,1,1","handlingStrategy":"validation","validationCode":"// validate args before invoking the tool: int rf = Integer.parseInt(args[0]); if (rf <= 0) throw new IllegalArgumentException(\"RF must be positive\"); int[] racks = getRacks(args[2]); if (racks.length != rf) throw new IllegalArgumentException(\"racks mismatch RF\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate RF/racks arguments against the tool's documented format before running.","Test generate_tokens output on a scratch node count before applying to production tokens.","Check exit code (1) and read the logged stack trace, not just the wrapper message.","Run the tool with the exact classpath provided by the Cassandra distribution."],"tags":["cli","tokens","offline-allocator"],"backgroundTag":"invalid-cli-argument","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}