errors.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright (c) 2013 - Max Persson <max@looplab.se>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsm
  15. // InvalidEventError is returned by FSM.Event() when the event cannot be called
  16. // in the current state.
  17. type InvalidEventError struct {
  18. Event string
  19. State string
  20. }
  21. func (e InvalidEventError) Error() string {
  22. return "event " + e.Event + " inappropriate in current state " + e.State
  23. }
  24. // UnknownEventError is returned by FSM.Event() when the event is not defined.
  25. type UnknownEventError struct {
  26. Event string
  27. }
  28. func (e UnknownEventError) Error() string {
  29. return "event " + e.Event + " does not exist"
  30. }
  31. // InTransitionError is returned by FSM.Event() when an asynchronous transition
  32. // is already in progress.
  33. type InTransitionError struct {
  34. Event string
  35. }
  36. func (e InTransitionError) Error() string {
  37. return "event " + e.Event + " inappropriate because previous transition did not complete"
  38. }
  39. // NotInTransitionError is returned by FSM.Transition() when an asynchronous
  40. // transition is not in progress.
  41. type NotInTransitionError struct{}
  42. func (e NotInTransitionError) Error() string {
  43. return "transition inappropriate because no state change in progress"
  44. }
  45. // NoTransitionError is returned by FSM.Event() when no transition have happened,
  46. // for example if the source and destination states are the same.
  47. type NoTransitionError struct {
  48. Err error
  49. }
  50. func (e NoTransitionError) Error() string {
  51. if e.Err != nil {
  52. return "no transition with error: " + e.Err.Error()
  53. }
  54. return "no transition"
  55. }
  56. // CanceledError is returned by FSM.Event() when a callback have canceled a
  57. // transition.
  58. type CanceledError struct {
  59. Err error
  60. }
  61. func (e CanceledError) Error() string {
  62. if e.Err != nil {
  63. return "transition canceled with error: " + e.Err.Error()
  64. }
  65. return "transition canceled"
  66. }
  67. // AsyncError is returned by FSM.Event() when a callback have initiated an
  68. // asynchronous state transition.
  69. type AsyncError struct {
  70. Err error
  71. }
  72. func (e AsyncError) Error() string {
  73. if e.Err != nil {
  74. return "async started with error: " + e.Err.Error()
  75. }
  76. return "async started"
  77. }
  78. // InternalError is returned by FSM.Event() and should never occur. It is a
  79. // probably because of a bug.
  80. type InternalError struct{}
  81. func (e InternalError) Error() string {
  82. return "internal error on state transition"
  83. }