Skip to content

refactor: Remove FlowError and move noTasksToExecute to StoreError#16

Merged
takeshishimada merged 2 commits intomainfrom
refactor/move-no-tasks-error-to-store-error
Oct 31, 2025
Merged

refactor: Remove FlowError and move noTasksToExecute to StoreError#16
takeshishimada merged 2 commits intomainfrom
refactor/move-no-tasks-error-to-store-error

Conversation

@takeshishimada
Copy link
Copy Markdown
Contributor

Summary

Removes FlowError entirely and moves noTasksToExecute to StoreError, clarifying the separation between framework-level and application-level errors.

Problem

FlowError violated separation of concerns by mixing:

  • Framework errors: noTasksToExecute (API misuse detection)
  • Application errors: validationFailed, networkError, stateError (domain logic)

This design forced applications to use framework-defined error types instead of defining their own domain-specific errors.

Solution

1. Removed FlowError completely

Application-domain errors (validationFailed, networkError, stateError, etc.) should be defined by each application, not by the framework.

2. Created dedicated StoreError.swift

Moved noTasksToExecute from FlowError to StoreError. StoreError now contains only framework-level errors:

  • deallocated: Store lifecycle error
  • cancelled: Task cancellation
  • noTasksToExecute: API misuse detection

3. Updated Examples with custom error types

Demonstrates proper application error design:

  • RetryNetworkFeature: RetryError (maxRetriesExceeded, networkFailure)
  • MultiStepWizardFeature: WizardError (validationFailed, submissionFailed)
  • PaginatedListFeature: PaginationError (fetchFailed)

4. Updated documentation

  • Examples/AdvancedPatterns/README.md now shows custom error type patterns
  • Removed all FlowError references

Changes

Deleted

  • Sources/Flow/Store/FlowError.swift
  • Tests/UnitTests/Store/FlowErrorTests.swift

Added

  • Sources/Flow/Store/StoreError.swift with comprehensive documentation

Modified

  • 📝 Sources/Flow/Store/ActionTask.swift - Updated documentation references
  • 📝 Sources/Flow/Store/Store.swift - Removed inline StoreError definition, updated comments
  • 📝 Examples/AdvancedPatterns/NetworkingWithRetry/RetryNetworkFeature.swift - Added RetryError
  • 📝 Examples/AdvancedPatterns/MultiStepWizard/MultiStepWizardFeature.swift - Added WizardError
  • 📝 Examples/AdvancedPatterns/PaginatedList/PaginatedListFeature.swift - Added PaginationError
  • 📝 Examples/AdvancedPatterns/README.md - Updated best practices section

Benefits

Clear separation of concerns: Framework errors vs Application errors
Better flexibility: Applications define their own domain-specific errors
Follows single responsibility principle: StoreError focuses on framework concerns only
Improved examples: Demonstrates proper application error design patterns

Migration Guide

Applications using FlowError should define their own error types:

// Before
@Observable
final class State {
    var error: FlowError?
}

// After
enum MyError: Error, LocalizedError {
    case validationFailed(String)
    case networkError(Error)
    
    var errorDescription: String? {
        switch self {
        case .validationFailed(let reason):
            return "Validation failed: \(reason)"
        case .networkError(let underlying):
            return "Network error: \(underlying.localizedDescription)"
        }
    }
}

@Observable
final class State {
    var error: MyError?
}

Testing

  • ✅ All tests passing (289/289)
  • ✅ Build successful
  • ✅ No FlowError references remaining in codebase

Breaking Changes

⚠️ BREAKING: FlowError has been removed. Applications must define their own error types.

🤖 Generated with Claude Code

takeshishimada and others added 2 commits October 31, 2025 16:58
FlowError contained a mix of framework-level and application-level
errors, violating separation of concerns. This refactoring clarifies
the responsibility boundaries:

**Changes:**

1. **Removed FlowError entirely**
   - validationFailed, networkError, stateError etc. are
     application-domain concerns
   - Framework should not dictate application error types
   - Applications should define their own domain-specific errors

2. **Created dedicated StoreError.swift**
   - Moved noTasksToExecute from FlowError to StoreError
   - StoreError now contains only framework-level errors:
     * deallocated: Store lifecycle error
     * cancelled: Task cancellation
     * noTasksToExecute: API misuse detection

3. **Updated Examples to use custom error types**
   - RetryNetworkFeature: RetryError
   - MultiStepWizardFeature: WizardError
   - PaginatedListFeature: PaginationError
   - Demonstrates proper application error design

4. **Updated documentation**
   - README examples now show custom error type patterns
   - Removed FlowError references throughout

**Rationale:**

- Framework errors (StoreError) vs Application errors (custom enums)
- Better separation of concerns
- More flexible for application developers
- Follows single responsibility principle

All tests passing. No breaking changes to public API except removal
of FlowError (which should be replaced with app-specific errors).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixed a missed reference to FlowError in the .loadFailed action handler
that was not caught by the previous refactoring.

Changed:
- vfError -> paginationError
- .networkError -> .fetchFailed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@takeshishimada takeshishimada merged commit 78782c3 into main Oct 31, 2025
9 checks passed
@takeshishimada takeshishimada self-assigned this Oct 31, 2025
@takeshishimada takeshishimada deleted the refactor/move-no-tasks-error-to-store-error branch October 31, 2025 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant