toml API GitHub

Positions and errors

Positions of keys and values

A parsed TomlDocument tells where each key and value is written, as a TomlPosition: a line and a column, both from 1. Tools that check a document beyond its syntax use them to report a problem where it is.

TomlDocument document = Toml.parse(file);
TomlTable server = document.root().getTable("server");
TomlPosition port = document.positions().value(server, "port");

TomlPositions has the position of a key (key), of its value (value), and of an element of an array (element).

Syntax errors

A document that is not valid TOML throws a TomlParseException. Its message starts with the line and column of the error, and states what was expected and what was found; position() returns the position alone.

These are the positions TomlPositions reports. Any other error is where the parser found it.

Binding errors

A value that does not bind to a record throws a TomlMappingException, whose path() tells where the value is: its keys separated by dots, with the index of each element of an array in brackets, as in endpoints[0].methods[1]: expected a string, found an integer. See Binding to records.