Skip to content

chore: merge dev to main - core foundation complete - #6

Closed
martyy-code wants to merge 32 commits into
mainfrom
dev
Closed

chore: merge dev to main - core foundation complete#6
martyy-code wants to merge 32 commits into
mainfrom
dev

Conversation

@martyy-code

Copy link
Copy Markdown
Contributor

Summary

Merge dev to main for v1.0.0 core foundation release.

Features merged:

  • Task 01: error() factory with message templates
  • Task 02: raise() function
  • Task 03: is() type checking with DFS inheritance
  • Task 04: inherits option
  • Task 05: .from() method for exception chaining
  • Task 06: causes() function
  • Task 07: message templates (:upper, :lower, :json)
  • Task 08: instance properties guaranteed

Also included:

  • Runnable examples in examples/ directory
  • 78+ tests covering all features

Test plan

  • All tests pass
  • TypeScript strict mode passes
  • ESLint passes

🤖 Generated with Claude Code

martyy-codeand others added 30 commits May 29, 2026 08:49
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>
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>
martyy-codeand others added 2 commits May 29, 2026 11:25
- 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>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@martyy-code@codewizdave