name: fantasia-neverthrow description: >- Use the neverthrow Result / ResultAsync pattern instead of try/catch for recoverable failures. Apply when touching error paths, IPC wrappers, parsers, or refactors around thrown errors.
Neverthrow error handling
When to follow
- Anticipated failures: IPC, parse edge cases, cancellation, clipboard, optional APIs
- Refactoring legacy
try/catchor swallowed.catch
See neverthrow.mdc.
Core API (Neverthrow v8)
ok(value),err(error)Result.fromThrowable(fn, mapError)ResultAsync.fromPromise(promise, mapError);fromSafePromisewhen rejection unexpectedmatch,unwrapOr,map,mapErr,andThen,orElsesafeTry: generatoryield* resultfor sequential steps
Prefer finally on Promise chains for cleanup-only side effects.
Preload exclusion
src-electron/contentBridgeAPIs/** — sandboxed preload bundle. No neverthrow import. Use Promise.then/.catch, URL.canParse, early returns. src-electron/shared/** reachable from preload: same rule. Renderer, main, helpers/ still prefer Result / ResultAsync.