Uh oh!
There was an error while loading. Please reload this page.
chore: merge dev to main - core foundation complete - #6
Closed
martyy-code wants to merge 32 commits into
Closed
Conversation
Add the core error() factory that creates typed, structured errors following
the Standard Schema specification for field definitions.
Features:
- Accept config with name, fields (Standard Schema), inherits, message, httpStatus
- Support single and multiple inheritance via ErrorFactory references
- Message templates with {field} placeholders and :upper/:lower/:json modifiers
- Full ErrorInstance with name, message, stack, fields, notes, cause, causes,
context, httpStatus
- Type inference for fields via Standard Schema
- Factory metadata (name, inherits, schema, template, httpStatus)
Tests:
- 36 unit tests covering all acceptance criteria
- Basic usage, ErrorInstance properties, inherits option, message templates,
httpStatus, Standard Schema support, type inference, factory identity, stack traces
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>Restructure project to follow best practices: - Types: packages/errors/src/types/index.ts - Implementation: packages/errors/src/error.ts - Tests: packages/errors/tests/error.test.ts - Public API: packages/errors/src/index.ts Tests now in separate 'tests' directory with its own vitest include pattern. ESLint config updated to ignore vars starting with underscore. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Critical fixes: - Move @types/node to devDependencies (was incorrectly in dependencies) - Fix template formatting: now checks for placeholder existence, not field values - Fix regex reuse bug that caused :upper/:lower/:json modifiers to fail Refactoring: - Rename _inherits to inherits for consistency with ErrorFactory - Add TODO comments for unimplemented methods (addNote, from, context) - Add hasTemplatePlaceholders() helper to avoid regex state issues - Use early returns and inverse ifs to reduce indentation Tests: - Update tests to use new 'inherits' property name - Add test for template formatting with no fields Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Convert all function declarations to arrow functions with const - Convert all interface declarations to type aliases - Re-create src/index.ts which was missing Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
httpStatus will be handled differently in a future implementation. Removing from: - Types (ErrorFactory, ErrorInstance, ErrorConfig) - Implementation (error function) - Tests (removed httpStatus test suite) - Test assertions (removed httpStatus checks) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
New structure: - src/error/error.ts - error factory implementation - src/error/types/index.ts - type definitions - src/index.ts - public API exports Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- src/error/types.ts (not in subfolder) - Updated imports accordingly Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- src/error/capture.ts - stack capture utility - src/error/error.ts - imports capture from capture.js Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- src/error/constants.ts - shared regex patterns - src/error/format.ts - message template formatting - src/error/capture.ts - now imports from constants - src/error/error.ts - main error factory Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
on ErrorFactory for clarity Co-Authored-By: Claude Opus 4.[^1] <noreply@anthropic.com>
Renamed fields to data and added proper generic constraints to formatTemplate for better type safety following senior TypeScript patterns. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Use TEMPLATE_PLACEHOLDER_REGEX from constants instead of inline regex. Also use proper generic key access with data[fieldName as keyof T]. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add ExtractKeys type that extracts placeholder keys from template string at compile-time. Data objects now validated against actual template keys, catching missing properties before runtime. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Keep string-based stack filtering approach for cross-environment compatiblity. Memory updated with stack capture patterns from Senior to Expert level. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
feat: implement error() factory function
Implement raise() function that throws ErrorInstance errors: - Returns never type for type safety - Throws the provided error instance - Works with native throw syntax - Exported from main module Files: - src/error/raise.ts - raise() implementation - tests/raise.test.ts - 9 unit tests Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- src/error/raise/raise.ts Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
feat: implement raise() function
Add is() function for checking error type with inheritance support: - Symbol-based factory identity (prevents name collision issues) - Proper native error handling via instanceof - Inheritance chain walking for parent type checks - Full instanceof compatibility (errors extend native Error) Key fixes after review: - Use Symbol.for() for factory identity instead of string names - Leverage instanceof for native errors instead of hardcoded list - Store factory reference via Symbol on error instances - Errors now properly extend Error class for native compatibility Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Key fixes: - DFS algorithm with stack for proper multiple inheritance support - Proper type inference: ExtractFields<T> for accurate type narrowing - Cyclic protection with seen Set - No array allocation per iteration (reuse stack) - Instance points to factory, factory holds inheritance metadata Type safety improvements: - is(err, SyntaxError) now returns error is SyntaxError - is(err, CustomError) returns error is ErrorInstance<CustomFields> Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
feat: implement is() type checking function
The inherits option was implemented in Task 01 and tested via Task 03. All acceptance criteria are met. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add .from(cause) method to ErrorInstance: - Sets the cause property on the error - Maintains full cause chain in causes array - Supports method chaining (err.from(a).from(b)) - Works with native errors and custom error factories - Preserves nested cause chains Implementation: - Added .from() method to ErrorInstance type - Method returns instance for chaining - Causes array maintains chronological order: newest first Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
feat: implement .from() method for exception chaining
Add causes(error) function that returns the causes array from an error: - Returns array from most recent to root cause - Handles errors with no cause (returns empty array) - Works through multiple chaining levels - Works with native errors in chain The causes property (err.causes) already works as per Task 05. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
causes() function implemented and tested. All acceptance criteria met. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
feat: implement causes() function for cause chain traversal
Message templates were implemented in Task 01 with format.ts. All acceptance criteria met. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Task 04: inherits option implemented with Task 01 - Task 07: message templates implemented with Task 01 - Task 08: instance properties fully initialized per design Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Examples organized by category:
- basics/ - error factory basics
- inheritance/ - single and multiple inheritance
- chaining/ - .from() and causes() usage
- type-checking/ - is() function
- templates/ - message placeholders and modifiers
- real-world/ - validation and network error handling
Run with: npx tsx examples/{category}/{file}.ts
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This was referenced Aug 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Merge dev to main for v1.0.0 core foundation release.
Features merged:
Also included:
examples/directoryTest plan
🤖 Generated with Claude Code