Skip to content

Commit

Permalink
merge ConfigurationError and RegisterMapError
Browse files Browse the repository at this point in the history
  • Loading branch information
taichi-ishitani committed Jan 22, 2025
1 parent 82e85d9 commit 0b9f83e
Show file tree
Hide file tree
Showing 31 changed files with 65 additions and 202 deletions.
2 changes: 0 additions & 2 deletions lib/rggen/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
require_relative 'core/input_base/hash_list_parser'
require_relative 'core/input_base/feature_factory'

require_relative 'core/configuration/error'
require_relative 'core/configuration/input_data'
require_relative 'core/configuration/component'
require_relative 'core/configuration/component_factory'
Expand All @@ -75,7 +74,6 @@
require_relative 'core/configuration/yaml_loader'
require_relative 'core/configuration'

require_relative 'core/register_map/error'
require_relative 'core/register_map/input_data'
require_relative 'core/register_map/component'
require_relative 'core/register_map/component_factory'
Expand Down
20 changes: 0 additions & 20 deletions lib/rggen/core/configuration/error.rb

This file was deleted.

2 changes: 0 additions & 2 deletions lib/rggen/core/configuration/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module RgGen
module Core
module Configuration
class Feature < InputBase::Feature
include RaiseError

alias_method :configuration, :component
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/rggen/core/configuration/feature_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module RgGen
module Core
module Configuration
class FeatureFactory < InputBase::FeatureFactory
include RaiseError
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/rggen/core/configuration/input_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module RgGen
module Core
module Configuration
class InputData < InputBase::InputData
include RaiseError

def initialize(valid_value_lists, &)
super(nil, valid_value_lists, &)
end
Expand Down
1 change: 0 additions & 1 deletion lib/rggen/core/configuration/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module RgGen
module Core
module Configuration
class Loader < InputBase::Loader
include RaiseError
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/rggen/core/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class BuilderError < RgGenError
class PluginError < RgGenError
end

class RuntimeError < RgGenError
class LoadError < RgGenError
end

class LoadError < Core::RuntimeError
class SourceError < RgGenError
end

class GeneratorError < Core::RuntimeError
class GeneratorError < RgGenError
end
end
end
2 changes: 2 additions & 0 deletions lib/rggen/core/input_base/component_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module RgGen
module Core
module InputBase
class ComponentFactory < Base::ComponentFactory
include RaiseError

class << self
def enable_no_children_error
@enable_no_children_error = true
Expand Down
2 changes: 1 addition & 1 deletion lib/rggen/core/input_base/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module RaiseError

def error(message, position = nil)
pos = extract_error_position(position)
raise error_exception.new(message, pos)
raise SourceError.new(message, pos)
end

def extract_error_position(position)
Expand Down
1 change: 1 addition & 0 deletions lib/rggen/core/input_base/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module InputBase
class Feature < Base::Feature
include Utility::RegexpPatterns
include Utility::TypeChecker
include RaiseError
include ConversionUtility

class << self
Expand Down
3 changes: 2 additions & 1 deletion lib/rggen/core/input_base/feature_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Core
module InputBase
class FeatureFactory < Base::FeatureFactory
include Utility::TypeChecker
include RaiseError

class << self
def convert_value(&block)
Expand Down Expand Up @@ -66,7 +67,7 @@ def process_active_input_value(input_value)

def parse_input_value(input_value, value_format)
format, options = value_format
VALUE_PARSERS[format].new(error_exception, **options).parse(input_value)
VALUE_PARSERS[format].new(**options).parse(input_value)
end

def override_input_value(input_value, parsed_value, options)
Expand Down
2 changes: 2 additions & 0 deletions lib/rggen/core/input_base/input_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module RgGen
module Core
module InputBase
class InputData
include RaiseError

def initialize(layer, valid_value_lists, *_args)
@layer = layer
@valid_value_lists = valid_value_lists
Expand Down
14 changes: 2 additions & 12 deletions lib/rggen/core/input_base/input_vaue_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,16 @@ module Core
module InputBase
class InputValueParser
include Utility::TypeChecker
include RaiseError

def initialize(exception, **_option)
@exception = exception
def initialize(**_options)
end

private

def split_string(string, separator, limit)
string&.split(separator, limit)&.map(&:strip)
end

def error(message, position_or_input_value = nil)
position =
if position_or_input_value.respond_to?(:position)
position_or_input_value.position
else
position_or_input_value
end
raise @exception.new(message, position)
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/rggen/core/input_base/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module RgGen
module Core
module InputBase
class Loader
include RaiseError

def self.support_types(types = nil)
types && (@support_types ||= []).concat(types.map(&:to_sym))
@support_types
Expand Down
2 changes: 1 addition & 1 deletion lib/rggen/core/input_base/option_hash_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module RgGen
module Core
module InputBase
class OptionHashParser < InputValueParser
def initialize(exception, allowed_options: nil, multiple_values: false)
def initialize(allowed_options: nil, multiple_values: false)
super
@allowed_options = allowed_options
@multiple_values = multiple_values
Expand Down
2 changes: 0 additions & 2 deletions lib/rggen/core/register_map/component_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module RgGen
module Core
module RegisterMap
class ComponentFactory < InputBase::ComponentFactory
include RaiseError

private

def select_actual_sources(configuration, *_)
Expand Down
20 changes: 0 additions & 20 deletions lib/rggen/core/register_map/error.rb

This file was deleted.

1 change: 0 additions & 1 deletion lib/rggen/core/register_map/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Core
module RegisterMap
class Feature < InputBase::Feature
include Base::FeatureLayerExtension
include RaiseError

private

Expand Down
1 change: 0 additions & 1 deletion lib/rggen/core/register_map/feature_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module RgGen
module Core
module RegisterMap
class FeatureFactory < InputBase::FeatureFactory
include RaiseError
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/rggen/core/register_map/input_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module RgGen
module Core
module RegisterMap
class InputData < InputBase::InputData
include RaiseError

module Root
def register_block(value_list = nil, &)
child(:register_block, value_list, &)
Expand Down
14 changes: 5 additions & 9 deletions spec/rggen/core/configuration/input_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@ def input_value(value)
RgGen::Core::InputBase::InputValue.new(value, position)
end

def raise_configuration_error(message)
raise_error RgGen::Core::Configuration::ConfigurationError, message
end

context '入力値名が入力値リスト上にない場合' do
it 'ConfigurationErrorを起こす' do
it 'SourceErrorを起こす' do
expect { input_data.value(:baz, input_value(0)) }
.to raise_configuration_error 'unknown configuration field is given: baz'
.to raise_source_error 'unknown configuration field is given: baz'
expect { input_data.value('baz', input_value(0)) }
.to raise_configuration_error 'unknown configuration field is given: baz'
.to raise_source_error 'unknown configuration field is given: baz'

expect { input_data[:baz] = input_value(0) }
.to raise_configuration_error 'unknown configuration field is given: baz'
.to raise_source_error 'unknown configuration field is given: baz'

expect { input_data['baz'] = input_value(0) }
.to raise_configuration_error 'unknown configuration field is given: baz'
.to raise_source_error 'unknown configuration field is given: baz'

expect { input_data.value(:foo, input_value(0)) }
.not_to raise_error
Expand Down
20 changes: 0 additions & 20 deletions spec/rggen/core/configuration/raise_error_spec.rb

This file was deleted.

16 changes: 3 additions & 13 deletions spec/rggen/core/input_base/conversion_utility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,12 @@
Struct.new(:x, :y).new(1, 2)
end

let(:exception) do
RgGen::Core::RuntimeError
end

let(:object) do
klass = Class.new do
include RgGen::Core::InputBase::RaiseError
include RgGen::Core::InputBase::ConversionUtility

def initialize(error_exception)
@error_exception = error_exception
end

attr_reader :error_exception
end
klass.new(exception)
klass.new
end

def input_value(value)
Expand Down Expand Up @@ -67,11 +57,11 @@ def to_int(*argv, &b)
[nil, true, false, '', 'foo', '0x1gh', :foo, Object.new].each do |value|
expect {
to_int(value, position, &block)
}.to raise_error exception, "cannot convert #{value.inspect} into integer -- #{position}"
}.to raise_source_error "cannot convert #{value.inspect} into integer", position

expect {
to_int(input_value(value), &block)
}.to raise_error exception, "cannot convert #{value.inspect} into integer -- #{position}"
}.to raise_source_error "cannot convert #{value.inspect} into integer", position
end
end
end
Expand Down
11 changes: 2 additions & 9 deletions spec/rggen/core/input_base/feature_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@
Class.new(RgGen::Core::InputBase::Feature)
end

let(:exception) do
Class.new(RgGen::Core::RgGenError)
end

let(:feature_factory) do
e = exception
Class.new(described_class) do
define_method(:error_exception) { e }
end
Class.new(described_class)
end

describe '#create' do
Expand Down Expand Up @@ -354,7 +347,7 @@ def factory(**options)

expect {
factory(allowed_options: allowed_options).create(component, create_input_value([0, baz: 1, qux: 2]))
}.to raise_error exception
}.to raise_source_error
end
end

Expand Down
10 changes: 3 additions & 7 deletions spec/rggen/core/input_base/hash_list_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

RSpec.describe RgGen::Core::InputBase::HashListParser do
let(:parser) do
described_class.new(exception)
end

let(:exception) do
RgGen::Core::RuntimeError
described_class.new
end

let(:position) do
Expand Down Expand Up @@ -83,11 +79,11 @@ def match_result(value)
['foo', 'foo 1', 'foo: 1, bar', 1, true, false, Object.new].each do |value|
expect {
parse(value)
}.to raise_error exception, "cannot convert #{value.inspect} into hash -- #{position}"
}.to raise_source_error "cannot convert #{value.inspect} into hash", position

expect {
parse([value])
}.to raise_error exception, "cannot convert #{value.inspect} into hash -- #{position}"
}.to raise_source_error "cannot convert #{value.inspect} into hash", position
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/rggen/core/input_base/option_array_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe RgGen::Core::InputBase::OptionArrayParser do
let(:parser) do
described_class.new(RgGen::Core::RuntimeError)
described_class.new
end

let(:position) do
Expand Down
Loading

0 comments on commit 0b9f83e

Please sign in to comment.