Skip to content

Commit

Permalink
add specific exception class
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammjammjamm committed Oct 23, 2024
1 parent 8664285 commit 439c8b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/inferno/dsl/runnable.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require_relative 'configurable'
require_relative 'input_output_handling'
require_relative 'resume_test_route'
require_relative '../exceptions'
require_relative '../utils/markdown_formatter'

module Inferno
Expand Down Expand Up @@ -202,7 +203,7 @@ def id(new_id = nil)

final_id = "#{prefix}#{@base_id}"

raise StandardError, "ID '#{final_id}' exceeds the maximum id length of 255 characters" if final_id.length > 255
raise Exceptions::InvalidRunnableIdException, final_id if final_id.length > 255

@id = final_id
end
Expand Down
6 changes: 6 additions & 0 deletions lib/inferno/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,11 @@ def initialize(name, expected_class_names, actual_class)
super("Expected '#{name}' to be a #{expected_class_names}, but found a #{actual_class.name}.")
end
end

class InvalidRunnableIdException < StandardError
def initialize(id)
super("ID '#{id}' exceeds the maximum id length of 255 characters")
end
end
end
end
4 changes: 3 additions & 1 deletion spec/inferno/dsl/runnable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@

describe '.id' do
it 'raises an error if the id is longer than 255 characters' do
expect { Class.new(Inferno::Test).id('a' * 256) }.to raise_error(StandardError, /length of 255 characters/)
expect do
Class.new(Inferno::Test).id('a' * 256)
end.to raise_error(Inferno::Exceptions::InvalidRunnableIdException, /length of 255 characters/)
end
end
end

0 comments on commit 439c8b2

Please sign in to comment.