Lemline documentation Help

Understanding Error Handling in Lemline

This document explains how errors are managed, propagated, and handled throughout the Lemline workflow system.

Error Handling Philosophy

Lemline's error handling is designed around a few key principles:

  1. Structured errors: All errors have a consistent structure with rich metadata

  2. Typed exceptions: Errors are categorized by type for precise handling

  3. Hierarchical propagation: Errors bubble up through the workflow structure

  4. Recovery mechanisms: Multiple strategies for handling and recovering from failures

  5. Transparent reporting: Clear error information for debugging and monitoring

Error Structure

Lemline implements the RFC 7807 Problem Details specification for consistent error representation:

{ "type": "https://open-workflow-specification.org/spec/1.0.0/errors/validation", "status": 400, "instance": "/do/0/validateInput", "title": "Input Validation Failed", "detail": "The 'amount' field must be a positive number" }

This structure provides:

  • type: URI identifier for the error category

  • status: Numeric code similar to HTTP status codes

  • instance: JSON pointer to the location in the workflow where the error occurred

  • title: Short human-readable error summary

  • detail: Detailed explanation specific to this occurrence

Error Type Hierarchy

Lemline organizes errors into a hierarchy:

WorkflowError ├── Configuration (400) │ └── Schema validation errors, invalid workflow definition ├── Validation (400) │ └── Input/output data validation failures ├── Expression (400) │ └── JQ expression evaluation errors ├── Authentication (401) │ └── Authentication failures ├── Authorization (403) │ └── Permission/access denied errors ├── Timeout (408) │ └── Execution timeout errors ├── Communication (500) │ └── External service communication failures └── Runtime (500) └── General runtime execution errors

Each error type has:

  • A unique URI identifier (e.g., https://open-workflow-specification.org/spec/1.0.0/errors/timeout)

  • A default status code

  • Specific handling semantics

Error Sources

Errors can originate from multiple sources:

1. System-Generated Errors

The Lemline runtime automatically generates errors for common failure scenarios:

  • Schema Validation: When input/output doesn't match the schema

    document: dsl: '1.0.3' namespace: examples name: validate-and-route-order version: '1.0.0' input: schema: format: json document: type: object required: [orderId, total] properties: orderId: type: string total: type: number minimum: 0 do: - routeOrder: switch: - largeOrder: when: ${ .total >= 1000 } then: requestReview - automatic: then: acceptOrder - requestReview: set: status: needs-review then: exit - acceptOrder: set: status: accepted output: as: '${ { orderId: $workflow.input.orderId, status: .status } }'
  • Expression Evaluation: When JQ expressions fail

    document: dsl: '1.0.3' namespace: examples name: 1-system-generated-errors version: '1.0.0' do: - example: set: total: ${ [.items[].price] | add } # If .items isn't an array, the expression raises an expression error
  • HTTP Communication: When API calls fail

    document: dsl: '1.0.3' namespace: examples name: check-stock version: '0.1.0' title: Check the shop stock do: - getStock: call: http with: method: get endpoint: http://127.0.0.1:8787/stock
  • Timeout Violations: When operations exceed their timeouts

    document: dsl: 1.0.3 namespace: examples name: 1-system-generated-errors-2 version: 1.0.0 do: - example: wait: PT30S timeout: after: PT1M

2. Explicitly Raised Errors

Workflows can explicitly raise errors using the raise task:

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

This allows for domain-specific error conditions.

3. External System Errors

Errors from external systems are translated to Lemline's error model:

  • HTTP Status Codes: Mapped to appropriate error types

    • 400-499: Typically ValidationError or related types

    • 500-599: Typically CommunicationError or RuntimeError

  • Database Errors: Wrapped as SystemErrors with appropriate context

  • Messaging System Errors: Wrapped as CommunicationErrors

Error Propagation

When an error occurs, it follows a defined propagation path:

┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ │ Error │ │ Check │ │ Search for │ │ Workflow │ │ Occurs │ ──> │ Local Try │ ──> │ Parent Try │ ──> │ Fails │ │ at Node │ │ Blocks │ │ Blocks │ │ (if not │ └────────────┘ └────────────┘ └────────────┘ │ caught) │ └────────────┘
  1. The error occurs at a specific node

  2. Lemline checks if the node is within a try block with a matching catch

  3. If not caught, the error propagates up to any parent try blocks

  4. If no matching handler is found, the workflow execution fails

Error Handling Mechanisms

Lemline provides several mechanisms for handling errors:

1. Try-Catch Blocks

The primary error handling mechanism:

document: dsl: '1.0.3' namespace: examples name: 1-try-catch-blocks version: '1.0.0' do: - processPayment: try: - chargeCard: call: http with: method: post endpoint: http://127.0.0.1:8787/charges?fail=503 body: orderId: ${ .orderId } catch: errors: with: type: https://open-workflow-specification.org/spec/1.0.0/errors/communication status: 503 as: paymentError do: - logError: set: errorMessage: '${ "Payment service unavailable: \($paymentError.title)" }'

Key components:

  • try: Contains tasks that might fail

  • catch: Defines how to handle specific errors

  • errors.with: Criteria for matching errors

  • as: Variable name to store the caught error

  • do: Compensation logic when an error is caught

2. Retry Policies

Automated retry for transient failures:

document: dsl: '1.0.3' namespace: examples name: 2-retry-policies version: '1.0.0' do: - readStock: try: - requestStock: call: http with: method: get endpoint: '${ "http://127.0.0.1:8787/stock?fail=503&failTimes=2&key=\($workflow.id)" }' catch: retry: delay: seconds: 1 backoff: exponential: {} limit: attempt: count: 3

When an error occurs:

  1. The error is caught

  2. The retry policy is evaluated

  3. If retries remain, the system waits according to the backoff strategy

  4. The entire try block is re-executed

3. Fallback Patterns

Define explicit fallback behavior:

document: dsl: '1.0.3' namespace: examples name: 3-fallback-patterns version: '1.0.0' do: - getCustomerProfile: try: - fetchFromApi: call: http with: endpoint: '${ "http://127.0.0.1:8787/customers/\(.customerId)" + (if .apiDown then "?fail=503" else "" end) }' method: get catch: do: - useCachedData: call: http with: endpoint: ${ "http://127.0.0.1:8787/customers/\($workflow.input.customerId)" } method: get - markStale: set: name: ${ .name } dataSource: cache isFresh: false

This pattern allows graceful degradation when preferred data sources fail.

4. Dead Letter Queues

Dead letter queues are a runner feature, not a workflow setting. When a runner cannot process a message from the broker, the message goes to a dead-letter destination (for Kafka, <source-topic>.dlq; for RabbitMQ and PGMQ, the configured or derived DLQ queue). Messages received for a namespace that no runner serves are parked in the failures table and can be re-sent with lemline failures replay.

Designing Error-Resilient Workflows

Best practices for error-resilient workflows:

1. Define Expected Errors

Explicitly define expected error conditions:

document: dsl: '1.0.3' namespace: examples name: 1-define-expected-errors version: '1.0.0' use: errors: paymentDeclined: type: https://example.com/errors/payment-declined status: 400 title: Payment Method Declined insufficientInventory: type: https://example.com/errors/insufficient-inventory status: 409 title: Insufficient Inventory do: - readStock: call: http with: method: get endpoint: http://127.0.0.1:8787/stock - checkInventory: if: ${ .available < $workflow.input.quantity } raise: error: insufficientInventory - accept: set: accepted: ${ $workflow.input.quantity }

2. Implement Structured Error Handling

Structure your workflow with proper error handling:

document: dsl: '1.0.3' namespace: examples name: 2-implement-structured-error-handling version: '1.0.0' do: - mainFlow: try: - validateInput: set: orderId: ${ .orderId } token: ${ .token } - processOrder: try: - reserveInventory: set: reserved: true - processPayment: if: ${ $workflow.input.token == "declined" } raise: error: type: https://example.com/errors/payment-declined status: 400 title: Payment declined catch: errors: with: type: https://example.com/errors/payment-declined do: - handleError: set: paymentDeclined: true - fulfillOrder: set: fulfilled: ${ (.paymentDeclined // false) | not } catch: {}

3. Use Appropriate Retry Strategies

Choose retry strategies based on error types:

  • Immediate retry: For race conditions

  • Constant delay: For brief outages

  • Exponential backoff: For congested services

  • Exponential backoff with jitter: For distributed systems

4. Implement Graceful Degradation

Design workflows to handle partial failures:

document: dsl: '1.0.3' namespace: examples name: 4-implement-graceful-degradation version: '1.0.0' do: - customerDashboard: fork: branches: - loadProfile: try: - fetchCustomerProfile: call: http with: method: get endpoint: '${ "http://127.0.0.1:8787/customers/\(.customerId)" + (if .profileDown then "?fail=503" else "" end) }' output: as: '${ { profile: .name } }' catch: do: - setDefaultProfile: set: profile: Guest - loadRecommendations: try: - fetchRecommendations: call: http with: method: get endpoint: '${ "http://127.0.0.1:8787/products?category=garden" + (if .recommendationsDown then "&fail=503" else "" end) }' output: as: '${ { recommendations: [.items[].id] } }' catch: do: - setEmptyRecommendations: set: recommendations: []

5. Provide Comprehensive Error Context

Ensure errors contain useful diagnostic information:

document: dsl: 1.0.3 namespace: examples name: 5-provide-comprehensive-error-context version: 1.0.0 do: - processRecord: raise: error: type: https://example.com/errors/validation status: 400 title: Invalid Record Type detail: ${ "Record ID \(.recordId) has invalid type '\(.recordType)'" } if: '${ .recordType == "invalid" }'

Debugging and Monitoring Errors

Lemline provides tools for error analysis:

Error Logging

Detailed contextual logging:

Every runner log line is prefixed with the workflow namespace, name, version and instance id, for example:

2023-06-15 14:32:45.123 ERROR [acme/order-processing:1.0.0] [123e4567-e89b-12d3-a456-426614174000] [c.l.c.p.AbstractProcessor] ...

Error Metrics

Runners expose processing metrics at /q/metrics, including failure counters per channel such as lemline_messaging_commands_processing_failed_total, tagged by reason, workflow name and version. Faulted instances and retried tasks are visible through the workflow.faulted, task.faulted and task.retried lifecycle events.

Error Tracing

The workflow.faulted and task.faulted lifecycle events of an instance carry the full error (type, status, title, instance, detail), where instance is the position of the failing task in the workflow. They are visible in the dashboard and, with lifecycle analytics enabled, stored in the analytics database.

Run the Examples

Every example on this page is a complete workflow. Complete the SQLite setup, save each example under the file name used below, and run the commands from the setup directory. With the JAR, substitute java -jar lemline.jar for bin/lemline.

Start the tutorial shop from the root of the Lemline source checkout:

docker compose -f examples/tutorial-services/compose.yaml up -d

Keep the setup worker running and use a second terminal in the setup directory.

bin/lemline definition post -f validate-and-route-order.yaml bin/lemline instance start examples validate-and-route-order --input '{"orderId":"ORD-303","total":-1}' bin/lemline definition post -f 1-system-generated-errors.yaml bin/lemline instance start examples 1-system-generated-errors --input '{"items":"none"}' bin/lemline definition post -f connect-to-http-services.yaml bin/lemline instance start examples check-stock bin/lemline definition post -f 1-system-generated-errors-2.yaml bin/lemline instance start examples 1-system-generated-errors-2 bin/lemline definition post -f typed-error.yaml bin/lemline instance start examples typed-error bin/lemline definition post -f 1-try-catch-blocks.yaml bin/lemline instance start examples 1-try-catch-blocks --input '{"orderId":"ORD-1802"}' bin/lemline definition post -f 2-retry-policies.yaml bin/lemline instance start examples 2-retry-policies bin/lemline definition post -f 3-fallback-patterns.yaml bin/lemline instance start examples 3-fallback-patterns --input '{"customerId":"C-100","apiDown":true}' bin/lemline definition post -f 1-define-expected-errors.yaml bin/lemline instance start examples 1-define-expected-errors --input '{"quantity":500}' bin/lemline definition post -f 2-implement-structured-error-handling.yaml bin/lemline instance start examples 2-implement-structured-error-handling --input '{"orderId":"ORD-1803","token":"approved"}' bin/lemline instance start examples 2-implement-structured-error-handling --input '{"orderId":"ORD-1804","token":"declined"}' bin/lemline definition post -f 4-implement-graceful-degradation.yaml bin/lemline instance start examples 4-implement-graceful-degradation --input '{"customerId":"C-100","recommendationsDown":true}' bin/lemline definition post -f 5-provide-comprehensive-error-context.yaml bin/lemline instance start examples 5-provide-comprehensive-error-context --input '{"recordId":"R-9","recordType":"invalid"}'

Example

Expected result

validate-and-route-order with a negative total

Refused by instance start: the total must be at least 0

1-system-generated-errors

Faults with an expression error: items is not an array

check-stock

The stock

1-system-generated-errors-2

Completes after 30 to 40 seconds

typed-error

Faults with invalid-order, status 422

1-try-catch-blocks

{"errorMessage":"Payment service unavailable: HTTP 503: …"}

2-retry-policies

The stock after two retries

3-fallback-patterns

{"name":"Ada Lovelace","dataSource":"cache","isFresh":false}

1-define-expected-errors

Faults with insufficient-inventory, status 409, title Insufficient Inventory

2-implement-structured-error-handling

{"fulfilled":true} for ORD-1803, {"fulfilled":false} for ORD-1804

4-implement-graceful-degradation

[{"profile":"Ada Lovelace"},{"recommendations":[]}]

5-provide-comprehensive-error-context

Faults with Invalid Record Type and detail Record ID R-9 has invalid type 'invalid'

Stop the shop when you are done:

docker compose -f examples/tutorial-services/compose.yaml down
25 November 2026