projectlombok/lombok · error · InvalidFormatOptionException

Format keys need to be 2 values separated with a colon.

Error message

Format keys need to be 2 values separated with a colon.

What it means

Delombok.formatOptionsToMap converts --format key:value pairs into a format-preferences map, with 'pretty' allowed as a bare flag. If a format option contains no colon and is not the special 'pretty' token, it throws InvalidFormatOptionException("Format keys need to be 2 values separated with a colon.").

Solutions

  1. Use key:value syntax, e.g. -f indent:4 -f suppresswarnings:skip
  2. If you only want the shortcut, pass exactly -f pretty with no extra text
  3. List valid keys with delombok --help or FormatPreferences.getKeysAndDescriptions() and pick one to pair with a value

Example fix

// before
delombok src -d out -f sortmembers
// after
delombok src -d out -f sortmembers:true
Defensive patterns

Strategy: validation

Validate before calling

boolean validFormatOption(String opt) {
    if (opt.equalsIgnoreCase("pretty")) return true;
    return opt.indexOf(':') != -1 && !opt.endsWith(":");
}

Try / catch

try { delombok.formatOptionsToMap(opts); } catch (InvalidFormatOptionException e) { System.err.println(e.getMessage() + " Use -f key:value or -f pretty"); System.exit(2); }

Prevention

When it happens

Trigger: Running delombok with --format (or -f) passing a value without a colon, e.g. -f sortmembers or -f pretty:extra where the intended syntax was key:value; only the exact token 'pretty' is permitted without a colon.

Common situations: Guessing CLI syntax (passing just a key name instead of key:value), forgetting the value after the colon (e.g. -f indent:), or copying a '-f pretty' example and appending extra words.

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 projectlombok/lombok@6d6a3e9fec (2026-09-07). Data as JSON: /api/errors/2c2724fbc8000e11. Report an issue: GitHub.

Appendix: source

Thrown at src/delombok/lombok/delombok/Delombok.java:469

	}
	
	public static class InvalidFormatOptionException extends Exception {
		public InvalidFormatOptionException(String msg) {
			super(msg);
		}
	}
	
	public static Map<String, String> formatOptionsToMap(List<String> formatOptions) throws InvalidFormatOptionException {
		boolean prettyEnabled = false;
		Map<String, String> formatPrefs = new HashMap<String, String>();
		for (String format : formatOptions) {
			int idx = format.indexOf(':');
			if (idx == -1) {
				if (format.equalsIgnoreCase("pretty")) {
					prettyEnabled = true;
					continue;
				} else {
					throw new InvalidFormatOptionException("Format keys need to be 2 values separated with a colon.");
				}
			}
			String key = format.substring(0, idx);
			String value = format.substring(idx + 1);
			boolean valid = false;
			for (String k : FormatPreferences.getKeysAndDescriptions().keySet()) {
				if (k.equalsIgnoreCase(key)) {
					valid = true;
					break;
				}
			}
			if (!valid) throw new InvalidFormatOptionException("Unknown format key: '" + key + "'.");
			formatPrefs.put(key.toLowerCase(), value);
		}
		
		if (prettyEnabled) {
			if (!formatPrefs.containsKey("suppresswarnings")) formatPrefs.put("suppresswarnings", "skip");
			if (!formatPrefs.containsKey("generated")) formatPrefs.put("generated", "skip");

View on GitHub (pinned to 6d6a3e9fec)