Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of current state when persisted state is invalid #20

Open
pascal-za opened this issue Aug 18, 2011 · 1 comment
Open

Handling of current state when persisted state is invalid #20

pascal-za opened this issue Aug 18, 2011 · 1 comment

Comments

@pascal-za
Copy link

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.

@cgriego
Copy link

cgriego commented Sep 28, 2011

I ran into this today. An unpersisted model was set with an invalid state to prove that the validations would not allow it and I later added an :if => :my_state? validation conditional and then validating the invalid model raised an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants