Skip to content

refactor: improve result pattern responses - #40

Merged
brunozoric merged 3 commits into
mainfrom
bruno/refactor/improve-result-pattern-responses
Sep 9, 2026
Merged

refactor: improve result pattern responses#40
brunozoric merged 3 commits into
mainfrom
bruno/refactor/improve-result-pattern-responses

Conversation

@brunozoric

@brunozoric brunozoric commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • BrowserWindow abstraction — new DI feature (BrowserWindowFeature / NullBrowserWindowFeature) that decouples browser features from the global window object. LocalStorageCacheImpl now takes BrowserWindow as an injected dependency instead of checking typeof window directly.
  • Result pattern for DirectoryToolcreate() returns Result<void, DirectoryCreateError> instead of void. New createOrThrow() throws on failure. Internal callers (copy, copyOrThrow) and FileTool updated accordingly.
  • Result pattern for FileToolwriteFile() returns Result<void, FileWriteError>, copy() returns Result<void, FileCopyError>. Cascaded into JsonFileTool.writeJson and PackageJsonFileTool.write which now propagate the Result.
  • New typed errorsDirectoryCreateError, FileWriteError, FileCopyError with structured data payloads.

Test plan

  • BrowserWindow — real impl exposes window.localStorage, null impl returns null, both via DI and factory functions
  • LocalStorageCache — updated to register BrowserWindow dependency, all existing tests pass
  • DirectoryTool.create — returns Result.ok() on success, Result.fail(DirectoryCreateError) on blocked permissions
  • DirectoryTool.createOrThrow — throws DirectoryCreateError on failure
  • DirectoryTool.copy/copyOrThrow — handles create Result internally
  • FileTool.writeFile — returns Result.ok() on success, Result.fail(FileWriteError) when directory cannot be created
  • FileTool.copy — returns Result.fail(FileCopyError) for missing source and blocked directories
  • JsonFileTool.writeJson — propagates Result<void, FileWriteError>, failure test included
  • PackageJsonFileTool.write — propagates Result<void, FileWriteError>, failure test included
  • All 519 tests pass, coverage thresholds met

🤖 Generated with Claude Code

brunozoric and others added 3 commits September 8, 2026 14:17
Replace silent void returns with Result<void, Error> across
DirectoryTool.create, FileTool.writeFile/copy, and their downstream
callers (JsonFileTool.writeJson, PackageJsonFileTool.write). Each
tool now exposes typed errors (DirectoryCreateError, FileWriteError,
FileCopyError) so callers can handle failures explicitly. OrThrow
variants throw the same errors.

Add BrowserWindow abstraction to decouple browser features from the
global window object. Real implementation captures from the live
window; null implementation returns null for all APIs (SSR/testing).
LocalStorageCacheImpl now takes BrowserWindow as an injected dependency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@brunozoric
brunozoric force-pushed the bruno/refactor/improve-result-pattern-responses branch from 0501b63 to f0d4dd6 Compare September 9, 2026 17:01
@brunozoric brunozoric self-assigned this Sep 9, 2026
@brunozoric
brunozoric merged commit f2b1bf6 into main Sep 9, 2026
16 checks passed
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