apache/cassandra · error

Error running tool.

Error message

Error running tool.

What it means

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.

Solutions

  1. Read the full stack trace logged under 'Error running tool.' - it names the actual cause.
  2. Validate CLI arguments: RF must be a positive integer, racks definition must match node count (see getRacks parsing).
  3. Fix the racks/token arguments so racks divide evenly across nodes for the given RF.
  4. Re-run the tool with correct arguments; exit code 1 is expected on any failure.

Example fix

// before java -cp ... GenerateTokens 16 3 notanumber // after java -cp ... GenerateTokens 16 3 1,1,1
Defensive patterns

Strategy: validation

Validate before calling

// 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");

Prevention

When it happens

Trigger: Running generate_tokens with an invalid replication factor, malformed racks definition string, unknown partitioner, or when OfflineTokenAllocator.allocate throws for the requested topology.

Common situations: 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.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/32ac7b25fa94dede. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/tools/GenerateTokens.java:110

        catch (AssertionError | ConfigurationException | ParseException t)
        {
            System.err.println(t.getMessage());
            System.out.println();
            printUsage(options);
            System.exit(1);
        }

        try
        {
            logger.output(String.format("Generating tokens for %d nodes with %d vnodes each for replication factor %d and partitioner %s",
                                             nodes, tokens, rf, partitioner.getClass().getSimpleName()));

            for (OfflineTokenAllocator.FakeNode node : OfflineTokenAllocator.allocate(rf, tokens, racksDef, logger, partitioner))
                logger.output(String.format("Node %d rack %d: %s", node.nodeId(), node.rackId(), node.tokens().toString()));
        }
        catch (Throwable t)
        {
            logger.warn(t, "Error running tool.");
            System.exit(1);
        }
    }

    private static int[] getRacks(String racksDef)
    {
        return Arrays.stream(racksDef.split(",")).mapToInt(Integer::parseInt).toArray();
    }

    private static CommandLine parseCommandLine(String[] args, Options options) throws ParseException
    {
        return new GnuParser().parse(options, args, false);
    }

    private static Options getOptions()
    {
        Options options = new Options();
        options.addOption(requiredOption("n", NODES, true, "Number of nodes."));

View on GitHub (pinned to 88fd0f6a0e)