refactor: improve result pattern responses - #40
Merged
Conversation
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
force-pushed
the
bruno/refactor/improve-result-pattern-responses
branch
from
September 9, 2026 17:01
0501b63 to
f0d4dd6
Compare
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 free
to 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
BrowserWindowFeature/NullBrowserWindowFeature) that decouples browser features from the globalwindowobject.LocalStorageCacheImplnow takesBrowserWindowas an injected dependency instead of checkingtypeof windowdirectly.create()returnsResult<void, DirectoryCreateError>instead ofvoid. NewcreateOrThrow()throws on failure. Internal callers (copy,copyOrThrow) andFileToolupdated accordingly.writeFile()returnsResult<void, FileWriteError>,copy()returnsResult<void, FileCopyError>. Cascaded intoJsonFileTool.writeJsonandPackageJsonFileTool.writewhich now propagate the Result.DirectoryCreateError,FileWriteError,FileCopyErrorwith structured data payloads.Test plan
BrowserWindow— real impl exposeswindow.localStorage, null impl returnsnull, both via DI and factory functionsLocalStorageCache— updated to registerBrowserWindowdependency, all existing tests passDirectoryTool.create— returnsResult.ok()on success,Result.fail(DirectoryCreateError)on blocked permissionsDirectoryTool.createOrThrow— throwsDirectoryCreateErroron failureDirectoryTool.copy/copyOrThrow— handlescreateResult internallyFileTool.writeFile— returnsResult.ok()on success,Result.fail(FileWriteError)when directory cannot be createdFileTool.copy— returnsResult.fail(FileCopyError)for missing source and blocked directoriesJsonFileTool.writeJson— propagatesResult<void, FileWriteError>, failure test includedPackageJsonFileTool.write— propagatesResult<void, FileWriteError>, failure test included🤖 Generated with Claude Code