-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gracefully degrade application failure error when deserializing (#103)
- Loading branch information
1 parent
71355c8
commit cccf233
Showing
3 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'temporal/concerns/payloads' | ||
class TestDeserializer | ||
include Temporal::Concerns::Payloads | ||
end | ||
# Simulates Temporal::Connection::Serializer::Failure | ||
Fabricator(:api_application_failure, from: Temporal::Api::Failure::V1::Failure) do | ||
transient :error_class, :backtrace | ||
message { |attrs| attrs[:message] } | ||
stack_trace { |attrs| attrs[:backtrace].join("\n") } | ||
application_failure_info do |attrs| | ||
Temporal::Api::Failure::V1::ApplicationFailureInfo.new( | ||
type: attrs[:error_class], | ||
details: TestDeserializer.new.to_details_payloads(attrs[:message]), | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
require 'temporal/workflow/errors' | ||
|
||
class ErrorWithTwoArgs < StandardError | ||
def initialize(message, another_argument); end | ||
end | ||
|
||
class SomeError < StandardError; end | ||
|
||
describe Temporal::Workflow::Errors do | ||
describe '.generate_error' do | ||
it "instantiates properly when the client has the error" do | ||
message = "An error message" | ||
stack_trace = ["a fake backtrace"] | ||
failure = Fabricate( | ||
:api_application_failure, | ||
message: message, | ||
backtrace: stack_trace, | ||
error_class: SomeError.to_s | ||
) | ||
|
||
e = Temporal::Workflow::Errors.generate_error(failure) | ||
expect(e).to be_a(SomeError) | ||
expect(e.message).to eq(message) | ||
expect(e.backtrace).to eq(stack_trace) | ||
|
||
end | ||
|
||
it "falls back to StandardError when the client doesn't have the error class" do | ||
allow(Temporal.logger).to receive(:error) | ||
|
||
message = "An error message" | ||
stack_trace = ["a fake backtrace"] | ||
failure = Fabricate( | ||
:api_application_failure, | ||
message: message, | ||
backtrace: stack_trace, | ||
error_class: 'NonexistentError', | ||
) | ||
|
||
e = Temporal::Workflow::Errors.generate_error(failure) | ||
expect(e).to be_a(StandardError) | ||
expect(e.message).to eq("NonexistentError: An error message") | ||
expect(e.backtrace).to eq(stack_trace) | ||
expect(Temporal.logger) | ||
.to have_received(:error) | ||
.with( | ||
'Could not find original error class. Defaulting to StandardError.', | ||
{original_error: "NonexistentError"}, | ||
) | ||
|
||
end | ||
|
||
|
||
it "falls back to StandardError when the client can't initialize the error class" do | ||
allow(Temporal.logger).to receive(:error) | ||
|
||
message = "An error message" | ||
stack_trace = ["a fake backtrace"] | ||
failure = Fabricate( | ||
:api_application_failure, | ||
message: message, | ||
backtrace: stack_trace, | ||
error_class: ErrorWithTwoArgs.to_s, | ||
) | ||
|
||
e = Temporal::Workflow::Errors.generate_error(failure) | ||
expect(e).to be_a(StandardError) | ||
expect(e.message).to eq("ErrorWithTwoArgs: An error message") | ||
expect(e.backtrace).to eq(stack_trace) | ||
expect(Temporal.logger) | ||
.to have_received(:error) | ||
.with( | ||
'Could not instantiate original error. Defaulting to StandardError.', | ||
{ | ||
original_error: "ErrorWithTwoArgs", | ||
instantiation_error_message: "wrong number of arguments (given 1, expected 2)", | ||
}, | ||
) | ||
end | ||
|
||
end | ||
end |