Skip to content

Handling of current state when persisted state is invalid #20

Description

@pascal-za

Given

class Robot
  include Stateflow

  stateflow do
    state :red, :green
  end
end

robot = Robot.new
def robot.load_from_persistence
  :some_invalid_state
end
> robot.green?
NoMethodError: undefined method `name' for nil:NilClass
    from .../stateflow-0.4.2/lib/stateflow.rb:25:in `new?'

The error isn't immediately obvious to the user/developer.

Possible solutions:

  • Revert to initial state if the persisted state is invalid
  • Raise a specific exception in current_state specifically informing the user of the invalid state

Let me know what direction you want to go with this and I'll submit a patch.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions