postmortem
Learn what went wrong—all at once.
A validation library that accumulates all validation errors instead of short-circuiting on the first failure.
Why "postmortem"?
In software, a postmortem is what you do after something breaks—gathering all the evidence to understand what went wrong. Traditional validation libraries give you the frustrating experience of fixing one error only to discover another:
Validation failed: email is required
# fix email...
Validation failed: age must be >= 18
# fix age...
Validation failed: password too short
postmortem gives you the complete picture upfront:
Validation errors (3):
$.email: missing required field
$.age: value 15 must be >= 18
$.password: length 5 is less than minimum 8
One validation run. All errors. Complete feedback for fixing what went wrong.
Features
- Accumulate all errors — Never stop at the first problem
- Composable schemas — Build complex validators from simple primitives
- Type-safe — Leverage Rust's type system
- JSON path tracking — Know exactly which field failed (e.g.,
users[0].email) - Schema registry — Define reusable schemas with references
- Cross-field validation — Validate relationships between fields
- Recursive schemas — Support for self-referential data structures
Quick Start
use ;
use json;
// Build a validation schema
let user_schema = object
.required
.required
.required;
// Validate data - accumulates ALL errors
let data = json!;
let result = user_schema.validate;
// Handle accumulated errors
match result
Installation
[]
= "0.1"
Core Concepts
Schema Types
Build validation schemas using a fluent API:
// String validation
let name = string
.min_len
.max_len
.pattern;
// Integer validation
let age = integer
.min
.max;
// Array validation
let tags = array
.min_items
.max_items
.items;
// Object validation
let user = object
.required
.optional;
Schema Combinators
Combine schemas for complex validation logic:
// One of multiple schemas
let id = one_of;
// All schemas must pass
let strict_string = all_of;
// Exactly one schema must pass (XOR)
let payment = exactly_one_of;
Schema Registry and References
Define reusable schemas with references:
use SchemaRegistry;
let mut registry = new;
// Define a reusable schema
registry.define;
// Reference it in other schemas
let person = object
.required
.required
.required;
// Validate with the registry
let result = registry.validate;
JSON Path Tracking
Every error includes the exact path to the failing field:
let data = json!;
let schema = array.items;
let result = schema.validate;
// Errors at: users[1].email and users[3].email
Cross-Field Validation
Validate relationships between fields:
let schema = object
.required
.required
.custom;
Effect Integration
For advanced use cases requiring dependency injection, async validation, or schema loading from external sources, postmortem provides Effect integration:
use ;
use ;
use fs;
// 1. Implement FileSystem for your storage backend
;
// 2. Implement SchemaEnv to provide environment dependencies
// 3. Load schemas from a directory
let env = AppEnv ;
let schemas_dir = new;
let registry = load_schemas_from_dir?;
// 4. Use the loaded schemas for validation
let user_data = json!;
let result = registry.validate;
// 5. For async validation with environment dependencies
use StringSchemaExt;
let email_schema = string
.min_len
.validate_with_env;
let db_env = DatabaseEnv ;
let result = email_schema.validate_with_env;
This Effect-based approach provides:
- Dependency injection — Pass environment dependencies explicitly
- Testability — Mock filesystems and databases in tests
- Flexibility — Support different storage backends and async operations
- Error accumulation — All validation errors collected, even across I/O operations
Note: The Effect integration uses a simplified API compatible with stillwater 0.12. Instead of returning Effect<E, Er, R> types, functions accept environment parameters directly and return Result or Validation types. This provides the same dependency injection benefits with a more straightforward API.
Design Philosophy
postmortem is built on functional programming principles:
- Pure validation — Schemas are immutable, validation has no side effects
- Composition — Build complex validators from simple primitives
- Error accumulation — Uses applicative functors (stillwater's
Validationtype) to collect all errors
This design makes schemas:
- Easy to test in isolation
- Safe to use concurrently (schemas are
Send + Sync) - Simple to compose and reuse
Documentation
Full API documentation is available at docs.rs/postmortem.
License
MIT — Glen Baker iepathos@gmail.com