A TypeScript library for standardized, localizable, and traceable error handling by design, using the Result pattern (no exceptions), with observability built-in.
Use PureTrace if you want:
- Explicit error handling instead of scattered
try/catch - Typed outcomes with the Result pattern
- End-to-end traceability carried by the Result itself
- i18n-ready errors (codes + structured data)
- One mental model for sync and async flows
- Seamless Zod integration for schema validation
PureTrace is designed for applications where errors are part of the domain, not just technical failures.
npm install @gilles-coudert/pure-traceimport {
Success,
Failure,
generateFailure,
generateMessage,
Result,
} from '@gilles-coudert/pure-trace';
function parseAge(input: string): Result<number> {
const age = Number(input);
if (Number.isNaN(age) || age < 0) {
return generateFailure({
type: 'processError',
code: 'invalidAge',
data: { input },
});
}
return new Success(age);
}
const result = parseAge('42').tapSuccess((success) => {
success.addTraces(
generateMessage({
kind: 'information',
type: 'information',
code: 'ageValidated',
data: { age: success.value },
}),
);
});
if (result.isSuccess()) {
const traces = result.getTraces();
// traces contain validation success information (PureMessage)
// result.value contains: 42
} else {
const errors = result.getErrors();
// errors contain structured error information (PureError)
}This example demonstrates explicit error handling, typed outcomes, and traceability. See the API documentation for advanced usage.
Contributions are welcome.
Branch prefixes are required and define the semantic impact of the change:
upgrade/→ breaking changes (major version)us/→ new features (minor version)fix/→ bug fixes (patch version)
Versioning information belongs to the branch, not individual commits.
Branches express intent and scope.
Commits should stay frequent, descriptive, and free of artificial prefixes that often degrade into wip: or chore: without semantic value.
This project is licensed under the Mozilla Public License 2.0 (MPL-2.0).
Gilles Coudert
- Email: pure.framework@gmail.com
- GitHub: https://github.com/GillesCoudert