Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def to_failure(error, converter)
)
else
failure.application_failure_info = Api::Failure::V1::ApplicationFailureInfo.new(
type: error.class.name
type: error.class.name.to_s.split('::').last
)
end

Expand Down
16 changes: 9 additions & 7 deletions temporalio/test/converters/failure_converter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

module Converters
class FailureConverterTest < Test
class CustomError < StandardError; end

def test_failure_with_causes
# Make multiple nested errors
orig_err = assert_raises do
begin
begin
raise 'Unset error class'
raise CustomError, 'Custom error class'
rescue StandardError
raise Temporalio::Error::ApplicationError, 'Application error no details'
end
Expand Down Expand Up @@ -45,8 +47,8 @@ def test_failure_with_causes
assert_instance_of Temporalio::Error::ApplicationError, orig_err.cause.cause
assert_equal 'Application error no details', orig_err.cause.cause.message
assert_empty orig_err.cause.cause.details
assert_instance_of RuntimeError, orig_err.cause.cause.cause
assert_equal 'Unset error class', orig_err.cause.cause.cause.message
assert_instance_of CustomError, orig_err.cause.cause.cause
assert_equal 'Custom error class', orig_err.cause.cause.cause.message

# Confirm serialized as expected
failure = Temporalio::Converters::DataConverter.default.to_failure(orig_err)
Expand All @@ -63,8 +65,8 @@ def test_failure_with_causes
refute_nil failure.cause.application_failure_info.details
assert_equal 'Application error no details', failure.cause.cause.message
assert_empty failure.cause.cause.application_failure_info.details.payloads
assert_equal 'Unset error class', failure.cause.cause.cause.message
assert_equal 'RuntimeError', failure.cause.cause.cause.application_failure_info.type
assert_equal 'Custom error class', failure.cause.cause.cause.message
assert_equal 'CustomError', failure.cause.cause.cause.application_failure_info.type

# Confirm deserialized as expected
new_err = Temporalio::Converters::DataConverter.default.from_failure(failure) #: untyped
Expand All @@ -83,8 +85,8 @@ def test_failure_with_causes
assert_empty new_err.cause.cause.details
assert_instance_of Temporalio::Error::ApplicationError, new_err.cause.cause.cause
assert_equal orig_err.cause.cause.cause.backtrace, new_err.cause.cause.cause.backtrace
assert_equal 'Unset error class', new_err.cause.cause.cause.message
assert_equal 'RuntimeError', new_err.cause.cause.cause.type
assert_equal 'Custom error class', new_err.cause.cause.cause.message
assert_equal 'CustomError', new_err.cause.cause.cause.type
end

# TODO(cretz): Test with encoded
Expand Down
10 changes: 5 additions & 5 deletions temporalio/test/worker_workflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,12 @@ def test_timer
err = assert_raises(Temporalio::Error::WorkflowFailedError) { execute_workflow(TimerWorkflow, :timeout_stdlib) }
assert_instance_of Temporalio::Error::ApplicationError, err.cause
assert_equal 'execution expired', err.cause.message
assert_equal 'Timeout::Error', err.cause.type
assert_equal 'Error', err.cause.type

err = assert_raises(Temporalio::Error::WorkflowFailedError) { execute_workflow(TimerWorkflow, :timeout_workflow) }
assert_instance_of Temporalio::Error::ApplicationError, err.cause
assert_equal 'execution expired', err.cause.message
assert_equal 'Timeout::Error', err.cause.type
assert_equal 'Error', err.cause.type

err = assert_raises(Temporalio::Error::WorkflowFailedError) do
execute_workflow(TimerWorkflow, :timeout_custom_info)
Expand Down Expand Up @@ -707,15 +707,15 @@ def test_task_failure
execute_workflow(TaskFailureWorkflow, 1, workflow_failure_exception_types: [TaskFailureError1])
end
assert_equal 'one', err.cause.message
assert_equal 'WorkerWorkflowTest::TaskFailureError1', err.cause.type
assert_equal 'TaskFailureError1', err.cause.type

# Fails workflow when configured on workflow, including inherited
err = assert_raises(Temporalio::Error::WorkflowFailedError) { execute_workflow(TaskFailureWorkflow, 2) }
assert_equal 'two', err.cause.message
assert_equal 'WorkerWorkflowTest::TaskFailureError2', err.cause.type
assert_equal 'TaskFailureError2', err.cause.type
err = assert_raises(Temporalio::Error::WorkflowFailedError) { execute_workflow(TaskFailureWorkflow, 4) }
assert_equal 'four', err.cause.message
assert_equal 'WorkerWorkflowTest::TaskFailureError4', err.cause.type
assert_equal 'TaskFailureError4', err.cause.type

# Also supports stdlib errors
err = assert_raises(Temporalio::Error::WorkflowFailedError) do
Expand Down
Loading