Skip to content

refactor(core): convert edit.ts to Result returns#280

Open
galligan wants to merge 1 commit into
outfitter/v2-outputfrom
outfitter/v2-core-results
Open

refactor(core): convert edit.ts to Result returns#280
galligan wants to merge 1 commit into
outfitter/v2-outputfrom
outfitter/v2-core-results

Conversation

@galligan

@galligan galligan commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Replace all 11 throw statements in editWaymark() and its internal
helpers with typed Result returns using ValidationError, NotFoundError,
and InternalError from @outfitter/contracts.

  • editWaymark() now returns Promise<WaymarkResult>
  • Zod .parse() replaced with .safeParse() to avoid exceptions
  • resolveTarget, resolveRecordContext, assertIdMatches, resolveType,
    resolveUpdatedRecord, updateIdIndex all return WaymarkResult
  • Split editWaymark into resolveEditContext + applyEdit to stay
    under cognitive complexity limit of 15
  • Tests updated to unwrap Results via .isOk()/.value
  • Added 2 new error-path tests (missing file, invalid spec)
  • Fixed stale @outfitter/contracts@0.2.0 in core workspace

WAY-106

Greptile Summary

Successfully converted editWaymark() from exception-based to Result-based error handling. All 11 throw statements replaced with typed errors (ValidationError, NotFoundError, InternalError).

Key changes:

  • Split editWaymark into resolveEditContext + applyEdit to maintain cognitive complexity under 15
  • Replaced Zod .parse() with .safeParse() to avoid exceptions
  • Updated return signature to Promise<WaymarkResult<EditResult>>
  • All internal helpers (resolveTarget, resolveRecordContext, assertIdMatches, resolveType, resolveUpdatedRecord, updateIdIndex) now return WaymarkResult
  • Updated @outfitter/contracts from 0.2.0 to 0.4.1
  • Tests updated with proper Result unwrapping via .isOk() checks
  • Added error-path coverage for missing files and invalid specs

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • The refactor is systematic and complete with no logic changes. All error paths properly typed, test coverage updated appropriately, and the split of editWaymark maintains the same behavior while improving maintainability.
  • No files require special attention

Important Files Changed

Filename Overview
packages/core/src/edit.ts Converted 11 throw statements to Result returns with proper error types. Split editWaymark into resolveEditContext and applyEdit to stay under complexity limit. All error paths properly typed.
packages/core/src/edit.test.ts Updated all tests to unwrap Results via .isOk()/.value pattern. Added 2 new error-path tests for missing file and invalid spec. All tests properly handle the new Result return type.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[editWaymark] --> B[resolveEditContext]
    B --> C{safeParse EditSpec}
    C -->|Error| D[Return ValidationError]
    C -->|Success| E[resolveTarget]
    E -->|Error| D
    E -->|Success| F[loadFileSnapshot]
    F -->|Not Found| G[Return NotFoundError]
    F -->|Success| H[resolveRecordContext]
    H -->|Error| G
    H -->|Success| I[assertIdMatches]
    I -->|Error| D
    I -->|Success| J[resolveType]
    J -->|Error| D
    J -->|Success| K[Return EditContext]
    
    A --> L[applyEdit]
    K --> L
    L --> M[buildDraftLines]
    M --> N[applyDraftEdits]
    N --> O[resolveUpdatedRecord]
    O -->|Error| P[Return InternalError]
    O -->|Success| Q{ID exists?}
    Q -->|Yes| R[updateIdIndex]
    Q -->|No| S[Return EditResult]
    R -->|Error| P
    R -->|Success| S
Loading

Last reviewed commit: 8eb153a

galligan commented Feb 22, 2026

Copy link
Copy Markdown
Contributor Author

Replace all 11 throw statements in editWaymark() and its internal
helpers with typed Result returns using ValidationError, NotFoundError,
and InternalError from @outfitter/contracts.

- editWaymark() now returns Promise<WaymarkResult<EditResult>>
- Zod .parse() replaced with .safeParse() to avoid exceptions
- resolveTarget, resolveRecordContext, assertIdMatches, resolveType,
  resolveUpdatedRecord, updateIdIndex all return WaymarkResult
- Split editWaymark into resolveEditContext + applyEdit to stay
  under cognitive complexity limit of 15
- Tests updated to unwrap Results via .isOk()/.value
- Added 2 new error-path tests (missing file, invalid spec)
- Fixed stale @outfitter/contracts@0.2.0 in core workspace

WAY-106
@galligan galligan force-pushed the outfitter/v2-output branch from 37ae890 to 427478a Compare February 22, 2026 03:42
@galligan galligan force-pushed the outfitter/v2-core-results branch from 8a4de2f to 8eb153a Compare February 22, 2026 03:42
@galligan galligan marked this pull request as ready for review February 22, 2026 04:07
Sign up for free to 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.

1 participant