Watch
2
0
Fork
You've already forked seltzer
0
Structured error logging API types.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Mark Raynsford 45394c8231
Some checks are pending
main-RHEL10-x86_64-jdk25 / Build (push) Waiting to run
main-RHEL10-x86_64-jdk26 / Build (push) Waiting to run
main-RHEL9-x86_64-jdk25 / Build (push) Waiting to run
main-RHEL9-x86_64-jdk26 / Build (push) Waiting to run
Update workflows.
2026-07-31 18:42:59 +01:00
.forgejo Update workflows. 2026-07-31 18:42:59 +01:00
com.io7m.seltzer.api Begin next development iteration. 2026-01-04 10:01:06 +00:00
com.io7m.seltzer.bom Begin next development iteration. 2026-01-04 10:01:06 +00:00
com.io7m.seltzer.io Begin next development iteration. 2026-01-04 10:01:06 +00:00
com.io7m.seltzer.slf4j Begin next development iteration. 2026-01-04 10:01:06 +00:00
com.io7m.seltzer.tests Begin next development iteration. 2026-01-04 10:01:06 +00:00
src/site/resources Update site metadata. 2025-08-09 15:07:15 +00:00
.gitignore Update .gitignore. 2024-05-07 16:01:47 +00:00
checkstyle-filter.xml Initial version 2023-04-23 14:37:14 +00:00
checkstyle-suppressions-1.0.dtd Initial version 2023-04-23 14:37:14 +00:00
doc7m-books.json Add doc7m-books.json 2026-07-31 18:36:50 +01:00
pom.xml Update primogenitor. 2026-06-26 20:48:40 +01:00
README-CHANGES.xml Mark release 1.3.0 2026-01-04 10:00:55 +00:00
README-LICENSE.txt Update LICENSE 2023-08-13 21:16:13 +00:00
README.in Update readme, metadata, etc. 2026-06-26 20:46:39 +01:00
README.md Update readme, metadata, etc. 2026-06-26 20:46:39 +01:00

seltzer

Maven Central Maven Central (snapshot) Java Version

com.io7m.seltzer

seltzer

A specification for structured, user-facing error message values.

Features

  • Simple interfaces for exposing error information in a structured manner.
  • Convenient builders for structured error values.
  • Written in pure Java 17.
  • OSGi ready.
  • JPMS ready.
  • ISC license.
  • High-coverage automated test suite.

Motivation

Many applications and command-line tools need to produce error messages for humans to read. Command-line tools will produce an error message as plain text on the terminal, whilst graphical applications will probably produce some sort of more complex error message dialog.

If a command-line application wants to include useful values along with the error message such as the names of missing files, request IDs, and so on, the only option it really has is to encode this information directly into the error message. A GUI application, on the other hand, could display a basic error message along with a graphical table of useful values. Library code wanting to support both use-cases will typically bake some kind of structured error type into the API. The seltzer package is an attempt to provide a set of simple, structured API types so that io7m packages do not have to endlessly specify these kinds of structured error types over and over.

Note: This is not a machine-readable structured error logging API. For that, use OpenTelemetry.

Building

$ mvn clean verify

Usage

Application-specific structured error types can implement the SStructuredErrorType interface. Application-specific exception types can implement the SStructuredErrorExceptionType which contains some useful default methods.

A structured error consists of the following:

Item Type Description
Message String A basic error message, such as "File not found".
Attributes Map<String,String> A key/value map containing attributes such as ("File", "file.txt").
Remediating Action Optional<String> An optional, suggested remediating action such as "Specify a file that actually exists."
Error Code T An error code that uniquely identifies the type of error, such as error-file-not-found
Exception Optional<Throwable> An optional exception.

Structured error values are indexed by an error code type T to allow for applications to strictly control error codes (and not have random error codes proliferate through codebases).

The API contains an immutable SStructuredError type that applications can use if they don't want to implement the interfaces themselves.

var error =
  SStructuredError.builder("error-file-not-found", "File not found.")
    .withAttribute("File", file.toString())
    .withRemediatingAction("Use a file that exists.")
    .withException(ex)
    .build();

Applications catching exceptions can check if an Exception is a structured error and display a more detailed error message if so:

try {
  run();
} catch (Exception e) {
  if (e instanceof SStructuredErrorType s) {
    showDetailedError(s);
  } else {
    showBasicError(e);
  }
}