languagetool-org/languagetool · error

Unknown mode:

Error message

Unknown mode: 

What it means

FrequencyIndexCreator.main accepts only 'text' or 'lucene' as its first CLI argument, mapping to the Mode enum. Any other first argument throws this RuntimeException. This is strict argument validation for the dev indexing tool.

Source

Thrown at languagetool-dev/src/main/java/org/languagetool/dev/bigdata/FrequencyIndexCreator.java:369

      writer.close();
    }
  }

  public static void main(String[] args) throws Exception {
    if (args.length != 3) {
      System.out.println("Usage: " + FrequencyIndexCreator.class.getSimpleName() + " <text|lucene> <inputDir> <outputDir>");
      System.out.println("    <text|lucene> 'text' will write plain text files, 'lucene' will write Lucene indexes");
      System.out.println("    <inputDir> is the Google ngram data, optionally already aggregated by Hive (lucene mode),");
      System.out.println("               please see https://dev.languagetool.org/finding-errors-using-n-gram-data");
      System.exit(1);
    }
    Mode mode;
    if (args[0].equals("text")) {
      mode = Mode.PlainText;
    } else if (args[0].equals("lucene")) {
      mode = Mode.Lucene;
    } else {
      throw new RuntimeException("Unknown mode: " + args[0]);
    }
    FrequencyIndexCreator creator = new FrequencyIndexCreator(mode);
    System.out.println("Mode: " + mode);
    System.out.println("Minimum year: " + MIN_YEAR);
    System.out.println("Ignore POS tags: " + IGNORE_POS);
    creator.run(new File(args[1]), new File(args[2]));
  }
}

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Use exactly 'text' for plain text input or 'lucene' for Lucene input as the first argument
  2. Ensure the mode string is lowercase
  3. Check the invocation has the full form: <mode> <inputDir> <indexBaseDir>

Example fix

// before
java FrequencyIndexCreator plain /data/input /data/index
// after
java FrequencyIndexCreator text /data/input /data/index
Defensive patterns

Strategy: validation

Validate before calling

String mode = args.length > 0 ? args[0] : "";
if (!mode.equals("text") && !mode.equals("lucene")) {
  throw new IllegalArgumentException("mode must be 'text' or 'lucene', got: " + mode);
}

Try / catch

try {
  FrequencyIndexCreator.main(args);
} catch (RuntimeException e) {
  if (e.getMessage().startsWith("Unknown mode")) {
    System.err.println("Usage: FrequencyIndexCreator <text|lucene> <inputDir> <indexBaseDir>");
  }
}

Prevention

When it happens

Trigger: Passing a mode string other than 'text' or 'lucene' (e.g. 'plain', 'Text' with capital letter, 'google') as args[0]; passing fewer than 3 args causing wrong element use.

Common situations: Following outdated documentation that used different mode names; case-sensitivity mistakes; copy-pasting an invocation for a different tool.

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 languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/7e53ab73a58114c9. Report an issue: GitHub.