Exception: ConvenientService::Exception

Inherits:
StandardError
  • Object
show all
Defined in:
lib/convenient_service/exception.rb

Overview

Base class for all ‘ConvenientService` exceptions.

Examples:

Can be used as a catch-all solution.


begin
  any_service.result
rescue ConvenientService::Exception => exception
  puts exception.message
end

Direct Known Subclasses

Common::Plugins::CanHaveCallbacks::Exceptions::AroundCallbackChainIsNotContinued, Common::Plugins::CanHaveUserProvidedEntity::Exceptions::ProtoEntityHasNoConcern, Common::Plugins::CanHaveUserProvidedEntity::Exceptions::ProtoEntityHasNoName, Config::Exceptions::OptionCanNotBeNormalized, Core::Entities::Config::Exceptions::ConfigIsCommitted, Core::Entities::Config::Exceptions::TooManyCommitsFromMethodMissing, Feature::Plugins::CanHaveEntries::Exceptions::NotDefinedEntryMethod, RSpec::Helpers::Classes::IgnoringException::Exceptions::IgnoredExceptionIsNotRaised, RSpec::Helpers::Classes::WrapMethod::Exceptions::ChainAttributePreliminaryAccess, RSpec::Matchers::Classes::DelegateTo::Exceptions::ArgumentsChainingIsAlreadySet, RSpec::Matchers::Classes::DelegateTo::Exceptions::CallOriginalChainingIsAlreadySet, RSpec::Matchers::Classes::DelegateTo::Exceptions::ReturnCustomValueChainingInvalidArguments, RSpec::Matchers::Classes::DelegateTo::Exceptions::ReturnValueChainingIsAlreadySet, RSpec::Matchers::Classes::Results::Base::Exceptions::InvalidStep, RSpec::Matchers::Classes::Results::Base::Exceptions::InvalidStepIndex, RSpec::Matchers::Results::BeResult::Exceptions::InvalidStatus, Service::Plugins::CanHaveConnectedSteps::Exceptions::ElseIfAfterElse, Service::Plugins::CanHaveConnectedSteps::Exceptions::ElseWithoutIf, Service::Plugins::CanHaveConnectedSteps::Exceptions::EmptyExpressionHasNoOrganizer, Service::Plugins::CanHaveConnectedSteps::Exceptions::EmptyExpressionHasNoResult, Service::Plugins::CanHaveConnectedSteps::Exceptions::EmptyExpressionHasNoStatus, Service::Plugins::CanHaveConnectedSteps::Exceptions::FirstConditionalGroupStepIsNotSet, Service::Plugins::CanHaveConnectedSteps::Exceptions::FirstGroupStepIsNotSet, Service::Plugins::CanHaveConnectedSteps::Exceptions::FirstStepIsNotSet, Service::Plugins::CanHaveConnectedSteps::Exceptions::ServiceHasNoSteps, Service::Plugins::CanHaveFallbacks::Exceptions::FallbackResultIsNotOverridden, Service::Plugins::CanHaveFallbacks::Exceptions::ServiceFallbackReturnValueNotSuccess, Service::Plugins::CanHaveStepAwareEnumerables::Exceptions::AlreadyUsedTerminalChaining, Service::Plugins::CanHaveStepAwareEnumerables::Exceptions::InvalidEvaluateByValue, Service::Plugins::CanHaveStepAwareEnumerables::Exceptions::ObjectIsNotEnumerable, Service::Plugins::CanHaveStepAwareEnumerables::Exceptions::ObjectIsNotEnumerator, Service::Plugins::CanHaveSteps::Entities::Method::Exceptions::MethodHasNoOrganizer, Service::Plugins::CanHaveSteps::Entities::Method::Exceptions::MethodIsNotOutputMethod, Service::Plugins::CanHaveSteps::Entities::Method::Exceptions::OutMethodStepIsNotCompleted, Service::Plugins::CanHaveSteps::Entities::Step::Exceptions::StepHasNoOrganizer, Service::Plugins::CanHaveSteps::Entities::Step::Exceptions::StepResultDataNotExistingAttribute, Service::Plugins::CanHaveSteps::Entities::Step::Plugins::CanBeMethodStep::Exceptions::MethodForStepIsNotDefined, Service::Plugins::CanHaveSteps::Entities::Step::Plugins::CanBeMethodStep::Exceptions::StepIsNotMethodStep, Service::Plugins::CanHaveSteps::Entities::Step::Plugins::CanBeServiceStep::Exceptions::StepIsNotServiceStep, Service::Plugins::CanHaveSteps::Entities::Step::Plugins::CanHaveFallbacks::Exceptions::FallbackResultIsNotOverridden, Service::Plugins::CanHaveSteps::Entities::Step::Plugins::CanHaveFallbacks::Exceptions::MethodStepCanNotHaveFallback, Service::Plugins::CanHaveSteps::Entities::Step::Plugins::HasResult::Exceptions::StepHasUnknownType, Service::Plugins::CanHaveSteps::Entities::Step::Plugins::RaisesOnNotResultReturnValue::Exceptions::ReturnValueNotKindOfResult, Service::Plugins::CanNotBeInherited::Exceptions::ServiceIsInherited, Service::Plugins::ForbidsConvenientServiceEntitiesAsConstructorArguments::Exceptions::ResultPassedAsConstructorArgument, Service::Plugins::ForbidsConvenientServiceEntitiesAsConstructorArguments::Exceptions::ServicePassedAsConstructorArgument, Service::Plugins::ForbidsConvenientServiceEntitiesAsConstructorArguments::Exceptions::StepPassedAsConstructorArgument, Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanBeCalled::Exceptions::ErrorResultIsCalled, Service::Plugins::HasJSendResult::Entities::Result::Plugins::CanHaveFallbacks::Exceptions::FallbackResultIsNotOverridden, Service::Plugins::HasJSendResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Exceptions::NotExistingAttribute, Service::Plugins::HasJSendResult::Entities::Result::Plugins::HelpsToLearnSimilaritiesWithCommonObjects::Exceptions::ErrorHasNoOtherTypeRepresentation, Service::Plugins::HasJSendResult::Entities::Result::Plugins::RaisesOnNotCheckedResultStatus::Exceptions::StatusIsNotChecked, Service::Plugins::HasJSendResultShortSyntax::Exceptions::BothArgsAndKwargsArePassed, Service::Plugins::HasJSendResultShortSyntax::Exceptions::KwargsContainJSendAndExtraKeys, Service::Plugins::HasJSendResultShortSyntax::Exceptions::MoreThanTwoArgsArePassed, Service::Plugins::HasNegatedResult::Exceptions::NegatedResultIsNotOverridden, Service::Plugins::HasResult::Exceptions::ResultIsNotOverridden, Service::Plugins::RaisesOnDoubleResult::Exceptions::DoubleResult, Service::Plugins::RaisesOnNotResultReturnValue::Exceptions::ReturnValueNotKindOfResult, Support::AbstractMethod::Exceptions::AbstractMethodNotOverridden, Support::Arguments::Exceptions::InvalidKeyType, Support::Cache::Exceptions::NotSupportedBackend, Support::Castable::Exceptions::FailedToCast, Support::Command::Exceptions::CallIsNotOverridden, Support::Counter::Exceptions::ValueAfterDecrementIsLowerThanMinValue, Support::Counter::Exceptions::ValueAfterIncrementIsGreaterThanMaxValue, Support::DependencyContainer::Exceptions::InvalidScope, Support::DependencyContainer::Exceptions::NotExportableModule, Support::DependencyContainer::Exceptions::NotExportedMethod, Support::DependencyContainer::Exceptions::NotModule, Support::FiniteLoop::Exceptions::MaxIterationCountExceeded, Support::FiniteLoop::Exceptions::NoBlockGiven, Support::Middleware::StackBuilder::Entities::Builders::Custom::Exceptions::MissingMiddleware, Support::Middleware::StackBuilder::Exceptions::NotSupportedBackend, Support::NeverReachHere, Utils::Array::Exceptions::NonIntegerIndex, Utils::Module::Exceptions::NestingUnderAnonymousNamespace

Class Method Summary collapse

Class Method Details

.newConvenientService::Exception .new(message) ⇒ ConvenientService::Exception .new(**kwargs) ⇒ ConvenientService::Exception

Note:

‘initialize_with_kwargs` or `initialize_without_arguments` must call `initialize(message)`, otherwise exception instance won’t be properly set up.

Creates ‘ConvenientService` exception instance. In contract to `StandardError.new`, may accept `kwargs`. In such a case the descendant must implement `initialize_with_kwargs` to specify the logic of how to generate a `message`. Without arguments behavior is also changed, it calls `initialize_without_arguments` instead of immediately setting `nil` as `message`.

Overloads:

  • .newConvenientService::Exception

    This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

    Calls ‘initialize_without_arguments` under the hood to generate the exception message.

    Examples:

    Usage.

    module Exceptions
      class Foo < ::ConvenientService::Exception
        def initialize_without_arguments
          # message = ...
          initialize(message)
        end
      end
    end
    
    ::ConvenientService.raise Foo.new
    

    Returns:

  • .new(message) ⇒ ConvenientService::Exception

    This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

    Calls ‘initialize(message)` under the hood to set the exception message.

    Examples:

    Usage.

    module Exceptions
      class Foo < ::ConvenientService::Exception
      end
    end
    
    ::ConvenientService.raise Foo.new("some message")
    

    Parameters:

    • message (String)

    Returns:

  • .new(**kwargs) ⇒ ConvenientService::Exception

    This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

    Calls ‘initialize_with_kwargs(**kwargs)` under the hood to generate the exception message.

    Examples:

    Usage.

    module Exceptions
      class Foo < ::ConvenientService::Exception
        def initialize_with_kwargs(**kwargs)
          # message = ...
          initialize(message)
        end
      end
    end
    
    ::ConvenientService.raise Foo.new(foo: :bar, baz: :qux)
    

    Parameters:

    • kwargs (Hash{Symbol => Object})

    Returns:



86
87
88
89
90
91
92
93
94
# File 'lib/convenient_service/exception.rb', line 86

def new(message = nil, **kwargs)
  if message
    super(message)
  elsif kwargs.any?
    allocate.tap { |exception| exception.initialize_with_kwargs(**kwargs) }
  else
    allocate.tap(&:initialize_without_arguments)
  end
end