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);
}
}
Releases & Development Snapshots
Releases
You can subscribe to the atom feed to be notified of project releases.
The most recently released version of the package is 1.2.0.
1.2.0 Release (2025-05-06Z)
- Update org.junit:junit-bom:5.10.3 → 5.11.0.
- Update org.junit:junit-bom:5.11.0 → 5.11.1.
- Update jqwik.version:1.9.0 → 1.9.1.
- Update org.junit:junit-bom:5.11.1 → 5.11.2.
- Update org.junit:junit-bom:5.11.2 → 5.11.3.
- Update jqwik.version:1.9.1 → 1.9.2.
- Update org.junit:junit-bom:5.11.3 → 5.11.4.
- Update codecov/codecov-action:5.1.2 → 5.3.1.
- Update org.junit:junit-bom:5.11.4 → 5.12.1.
- Update org.junit:junit-bom:5.12.1 → 5.12.2.
- Publish a com.io7m.seltzer.bom module.
- Add convenient SLF4J logging.
The compiled artifacts for the release (and all previous releases) are available on Maven Central.
Maven Modules
<dependency> <group>com.io7m.seltzer</group> <artifactId>com.io7m.seltzer.api</artifactId> <version>1.2.0</version> </dependency><dependency> <group>com.io7m.seltzer</group> <artifactId>com.io7m.seltzer.bom</artifactId> <version>1.2.0</version> </dependency><dependency> <group>com.io7m.seltzer</group> <artifactId>com.io7m.seltzer.io</artifactId> <version>1.2.0</version> </dependency><dependency> <group>com.io7m.seltzer</group> <artifactId>com.io7m.seltzer.slf4j</artifactId> <version>1.2.0</version> </dependency><dependency> <group>com.io7m.seltzer</group> <artifactId>com.io7m.seltzer.tests</artifactId> <version>1.2.0</version> </dependency>
Previous Releases
The changelogs for the most recent previous releases are as follows:
1.1.0 Release (2024-08-04Z)
- Update jqwik.version:1.8.4 → 1.8.5.
- Update junit.version:5.10.2 → 5.10.3.
- Update jqwik.version:1.8.5 → 1.9.0.
- Add com.io7m.seltzer.io module.
1.0.1 Release (2024-05-08Z)
- Update jqwik.version:1.8.2 → 1.8.4.
- Update ch.qos.logback:logback-classic:1.4.14 → 1.5.6.
- Update org.slf4j:slf4j-api:2.0.10 → 2.0.13.
- Update junit.version:5.10.1 → 5.10.2.
- Update com.io7m.lanark:com.io7m.lanark.core:1.1.0 → 1.2.0.
- Update com.io7m.jdeferthrow:com.io7m.jdeferthrow.core:1.2.0 → 1.3.0.
1.0.0 Release (2024-05-08Z)
- Initial major release.
Development Snapshots
At the time of writing, the current unstable development version of the package is 1.3.0-SNAPSHOT.
Development snapshots may be available in the Central Portal Snapshots repository. Snapshots are published to this repository every time the project is built by the project's continuous integration system, but snapshots do expire after around ninety days and so may or may not be available depending on when a build of the package was last triggered.
Manual
This project does not have any user manuals or other documentation beyond what might be present on the page above.
Sources
This project uses Git to manage source code.
Repository: https://www.github.com/io7m-com/seltzer
$ git clone --recursive https://www.github.com/io7m-com/seltzer
Issues
This project uses GitHub Issues to track issues.
License
Copyright © 2023 Mark Raynsford <code@io7m.com> https://www.io7m.com Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.