Lemline documentation Help

Defining and using custom errors

Workflow errors carry a URI identifying the error type and a numeric status. Optional fields include title, detail and instance.

Define and raise a named error

Put reusable errors under use.errors. Reference a named definition with raise.error.

Complete the SQLite setup and keep its worker running. Run the commands from a second terminal in the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline. The HTTP examples call the tutorial shop; start it from the root of the Lemline source checkout:

docker compose -f examples/tutorial-services/compose.yaml up -d
document: dsl: '1.0.3' namespace: examples name: typed-error version: '1.0.0' use: errors: invalidOrder: type: https://errors.example.com/invalid-order status: 422 title: Invalid order do: - validateOrder: if: ${ (.orderId // "") == "" } raise: error: invalidOrder - acceptOrder: set: status: accepted

Save it as typed-error.yaml:

bin/lemline definition post -f typed-error.yaml bin/lemline instance start examples typed-error --input '{"orderId":"ORD-905"}' bin/lemline instance start examples typed-error

The first instance completes with {"status":"accepted"}. The second faults with the named error: type https://errors.example.com/invalid-order, status 422, title Invalid order.

Construct an error with dynamic details

Use an inline error object when fields depend on the current task input.

document: dsl: '1.0.3' namespace: examples name: raise-order-error version: '1.0.0' do: - checkStock: if: ${ .stock < .quantity } raise: error: type: https://errors.example.com/out-of-stock status: 409 title: Insufficient stock detail: '${ "Requested \(.quantity); available \(.stock)" }'

Save it as raise-order-error.yaml:

bin/lemline definition post -f raise-order-error.yaml bin/lemline instance start examples raise-order-error --input '{"stock":1,"quantity":3}' bin/lemline instance start examples raise-order-error --input '{"stock":5,"quantity":3}'

The first instance faults with status 409, title Insufficient stock and detail Requested 3; available 1. The second has enough stock: the if skips the raise and the instance completes with its input.

Read or map a caught error

Inside catch.do, read the error variable when constructing a fallback result. To handle only one error type, add catch.errors.with.type to the catch.

document: dsl: '1.0.3' namespace: examples name: format-error-result version: '1.0.0' do: - submitOrder: try: - submit: call: http with: method: post endpoint: http://127.0.0.1:8787/reservations body: ${ . } catch: as: orderError do: - formatFailure: set: success: false status: ${ $orderError.status } errorType: ${ $orderError.type } reason: ${ $orderError.title }

Save it as format-error-result.yaml. Send one valid reservation and two the shop refuses:

bin/lemline definition post -f format-error-result.yaml bin/lemline instance start examples format-error-result --input '{"orderId":"ORD-901","items":[{"id":"SKU-1","quantity":1}]}' bin/lemline instance start examples format-error-result --input '{"orderId":"ORD-902","items":[{"id":"SKU-9","quantity":1}]}' bin/lemline instance start examples format-error-result --input '{"orderId":"ORD-903","items":[{"id":"SKU-1","quantity":500}]}'

The first instance returns the reservation. The shop answers HTTP 400 to the second and HTTP 409 to the third; both complete with success: false, the communication error type, the HTTP status (400, then 409) and a reason that starts with HTTP 400: {"error":"Invalid items" and HTTP 409: {"error":"Out of stock" respectively.

Stop the shop when you are done:

docker compose -f examples/tutorial-services/compose.yaml down

See Error Handling with Try-Catch for filtering and retries.

25 November 2026