From fc97c78016f122583f8ce9e54f94fc80fa69770f Mon Sep 17 00:00:00 2001 From: Karol Galanciak Date: Wed, 9 Oct 2024 10:55:06 +0200 Subject: [PATCH] include more details in OperationFailed#message --- CHANGELOG.md | 3 +++ lib/operations/command.rb | 14 ++++++++++++++ spec/operations/command_spec.rb | 6 +++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5e6bc1..09b9cdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## [main](https://github.com/BookingSync/operations/tree/main) +### Changes +- Changed `Operations::Command::OperationFailed#message` to include detailed error messages + ### Changes - Rename Operations::Form#model_name parameter to param_key and make it public preserving backwards compatibility. [\#52](https://github.com/BookingSync/operations/pull/52) ([pyromaniac](https://github.com/pyromaniac)) diff --git a/lib/operations/command.rb b/lib/operations/command.rb index d6abee7..f548b49 100644 --- a/lib/operations/command.rb +++ b/lib/operations/command.rb @@ -148,6 +148,20 @@ def initialize(operation_result) def sentry_context operation_result.as_json(include_command: true) end + + def message + [super, error_details].join("\n") + end + + private + + def error_details + operation_result + .errors + .messages + .map { |error| [[error.path, error.text].join(" - "), error.meta.to_a.join(": :")] } + .join("\n") + end end param :operation, Operations::Types.Interface(:call) diff --git a/spec/operations/command_spec.rb b/spec/operations/command_spec.rb index 1c432d4..52b9357 100644 --- a/spec/operations/command_spec.rb +++ b/spec/operations/command_spec.rb @@ -532,7 +532,7 @@ def build(**kwargs) specify do expect { call! }.to raise_error do |error| expect(error).to be_a(Operations::Command::OperationFailed) - expect(error.message).to eq("Proc failed on contract") + expect(error.message).to eq("Proc failed on contract\nname - is missing\n") expect(error.sentry_context).to include(errors: { name: ["name is missing"] }) end end @@ -553,7 +553,7 @@ def build(**kwargs) specify do expect { try_call! }.to raise_error do |error| expect(error).to be_a(Operations::Command::OperationFailed) - expect(error.message).to eq("Proc failed on contract") + expect(error.message).to eq("Proc failed on contract\nname - is missing\n") expect(error.sentry_context).to include(errors: { name: ["name is missing"] }) end end @@ -577,7 +577,7 @@ def build(**kwargs) specify do expect { try_call! }.to raise_error do |error| expect(error).to be_a(Operations::Command::OperationFailed) - expect(error.message).to eq("Proc failed on operation") + expect(error.message).to eq("Proc failed on operation\n - Runtime error\n") expect(error.sentry_context).to include(errors: { nil => ["Runtime error"] }) end end