This page covers the result system built on the solid-result gem, which provides structured representations of business process outcomes through Solid::Success and Solid::Failure objects. Results enable explicit error handling, type-safe outcome checking, and standardized data access patterns.
All process executions return either a Solid::Success or Solid::Failure instance, never nil or exceptions. This makes control flow explicit and eliminates ambiguity about operation outcomes.
Related pages: Process Lifecycle and Caller Module for result generation, Pattern Matching and Result Inspection for Ruby 3.1+ pattern matching, Steps DSL and Composition for result chaining.
Results are instances of either Solid::Success or Solid::Failure, both inheriting from Solid::Result. Every result has a type (Symbol) and a value (Hash) that contain operation-specific data.
Dynamic Type Predicates: Both Solid::Success and Solid::Failure respond to predicate methods based on their type. For example, a result with type: :user_created responds to .user_created? returning true.
Sources: test/solid/process/result_test.rb28-35 test/solid/process/dependencies/result_test.rb24-31 test/solid/process/result_test.rb86-100
Results contain a value hash with symbolic keys. The keys and content vary based on the result type and context:
| Result Class | Result Type | Value Keys | Content |
|---|---|---|---|
Solid::Success | :user_created | :user | Created User model instance |
Solid::Success | :account_created | :account | Created Account model instance |
Solid::Failure | :invalid_input | :input | Solid::Input instance with .errors |
Solid::Failure | :invalid_dependencies | :dependencies | Dependencies instance with .errors |
Solid::Failure | :email_already_taken | Varies | Domain-specific error context |
Sources: test/solid/process/result_test.rb37-45 test/solid/process/result_test.rb61-69 test/solid/process/dependencies/result_test.rb33-39 test/solid/process/dependencies/result_test.rb60-66
Processes return results using the Success() and Failure() methods, which construct result objects with a type and data payload.
The type symbol (first argument) becomes the result's type identifier. The remaining keyword arguments populate the result's value hash.
Sources: README.md122-129
Solid::Success instances represent completed operations and contain the created or modified domain objects in their value hash.
Sources: test/solid/process/result_test.rb21-45 test/solid/process/dependencies/result_test.rb42-68
Success results provide multiple methods for checking the result type:
Sources: test/solid/process/result_test.rb31-35 test/solid/process/dependencies/result_test.rb54-58
Success results provide three patterns for accessing data:
Sources: test/solid/process/result_test.rb37-45 test/solid/process/dependencies/result_test.rb60-66
Solid::Failure instances represent operations that could not complete, containing error information and invalid objects for inspection and debugging.
The framework automatically generates two failure types during process execution:
| Failure Type | Generated When | Value Contents |
|---|---|---|
:invalid_input | Input validation fails | {input: Solid::Input} with .errors |
:invalid_dependencies | Dependency validation fails | {dependencies: Dependencies} with .errors |
Sources: test/solid/process/result_test.rb48-70 test/solid/process/dependencies/result_test.rb21-40
Processes define custom failure types for domain-specific error conditions:
Sources: test/solid/process/result_test.rb72-84 test/solid/process/dependencies/result_test.rb96-110
Failure results use the same type checking interface as success results:
Sources: test/solid/process/result_test.rb56-60 test/solid/process/dependencies/result_test.rb27-31
Failure results contain invalid objects with ActiveModel validation errors:
Sources: test/solid/process/result_test.rb61-70 test/solid/process/dependencies/result_test.rb33-40 test/solid/process/dependencies/result_test.rb96-110
Result objects respond to predicate methods based on their type through Ruby's method_missing mechanism. The method must end with ? to be handled dynamically.
Sources: test/solid/process/result_test.rb86-100
The dynamic predicate method returns true if the result's type matches the method name (minus the ?), false if it's a valid predicate format but doesn't match, and raises NoMethodError for invalid method calls.
Sources: test/solid/process/result_test.rb86-100
Results are automatically generated by the process execution system based on operation outcomes.
Sources: test/solid/process/result_test.rb21-84 test/solid/process/dependencies/result_test.rb21-110
The framework automatically assigns result types based on the execution context:
| Execution Stage | Failure Condition | Result Type |
|---|---|---|
| Input validation | Invalid attributes | :invalid_input |
| Dependency validation | Invalid dependencies | :invalid_dependencies |
| Business logic | Domain-specific errors | Custom types (e.g., :email_already_taken) |
| Successful completion | Operation completed | Custom success types (e.g., :user_created) |
Sources: test/solid/process/result_test.rb48-84 test/solid/process/dependencies/result_test.rb21-110
Refresh this wiki