The type of entity being created
A function that creates the entity
The created entity
This utility function provides consistent error handling across all entity factories. It catches Zod validation errors and converts them to domain-specific error types.
const article = createEntityWithErrorHandling(() =>
Object.freeze({
id: makeId(),
title: makeArticleTitle(rawTitle),
// ... other fields
})
);
Wraps entity creation with standardized error handling.