Exception: Synthra::Errors::SimulatedFailure

Inherits:
SimulatedBehaviorError show all
Defined in:
lib/synthra/errors.rb

Overview

Simulated failure (service unavailable)

Raised by the @failure behavior to simulate a service being unavailable. Useful for testing retry logic and error handling.

Examples:

DSL usage

# API:
#   @failure 10%  <- 10% chance of SimulatedFailure
#   id: uuid

Constant Summary collapse

ERROR_CODE =
"SIMULATED_FAILURE"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(probability: nil) ⇒ SimulatedFailure

Create a new SimulatedFailure

Parameters:

  • probability (Integer, nil) (defaults to: nil)

    the probability percentage if configured



1027
1028
1029
1030
1031
1032
# File 'lib/synthra/errors.rb', line 1027

def initialize(probability: nil)
  @probability = probability
  message = "Simulated failure"
  message += " (#{probability}% probability)" if probability
  super(message)
end

Instance Attribute Details

#probabilityInteger? (readonly)

Returns the configured failure probability percentage.

Returns:

  • (Integer, nil)

    the configured failure probability percentage



1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
# File 'lib/synthra/errors.rb', line 1017

class SimulatedFailure < SimulatedBehaviorError
  ERROR_CODE = "SIMULATED_FAILURE"
  attr_reader :probability


  # Create a new SimulatedFailure
  #
  # @param probability [Integer, nil] the probability percentage if configured
  #

  def initialize(probability: nil)
    @probability = probability
    message = "Simulated failure"
    message += " (#{probability}% probability)" if probability
    super(message)
  end
end