Skip to content

A platform for community discussion. Free, open, simple.

DEV: Show parameters on a service contract failure

Loïc Guitautc790c5741552
diff --git a/app/services/service/base.rb b/app/services/service/base.rb
index 6c8f608b7fe..531169f44cd 100644
--- a/app/services/service/base.rb
+++ b/app/services/service/base.rb
@@ -177,7 +177,7 @@ module Service
context[contract_name] = contract
context[result_key] = Context.build
if contract.invalid?
- context[result_key].fail(errors: contract.errors)
+ context[result_key].fail(errors: contract.errors, parameters: contract.raw_attributes)
context.fail!
end
end
@@ -218,6 +218,10 @@ module Service
include ActiveModel::Attributes
include ActiveModel::AttributeMethods
include ActiveModel::Validations::Callbacks
+
+ def raw_attributes
+ @attributes.values_before_type_cast
+ end
end
end
diff --git a/lib/steps_inspector.rb b/lib/steps_inspector.rb
index 80b5438563d..61f71a830d5 100644
--- a/lib/steps_inspector.rb
+++ b/lib/steps_inspector.rb
@@ -73,7 +73,7 @@ class StepsInspector
# @!visibility private
class Contract < Step
def error
- step_result.errors.inspect
+ "#{step_result.errors.inspect}\n\nProvided parameters: #{step_result.parameters.pretty_inspect}"
end
end
diff --git a/spec/lib/steps_inspector_spec.rb b/spec/lib/steps_inspector_spec.rb
index 534d0356140..38227239a7d 100644
--- a/spec/lib/steps_inspector_spec.rb
+++ b/spec/lib/steps_inspector_spec.rb
@@ -219,6 +219,10 @@ RSpec.describe StepsInspector do
it "returns an error related to the contract" do
expect(error).to match(/ActiveModel::Error attribute=parameter, type=blank, options={}/)
end
+
+ it "returns the provided paramaters" do
+ expect(error).to match(/{"parameter"=>nil}/)
+ end
end
context "when the policy step is failing" do