Skip to content

Commit

Permalink
include more details in OperationFailed#message
Browse files Browse the repository at this point in the history
  • Loading branch information
Azdaroth committed Oct 9, 2024
1 parent 2511b2a commit fc97c78
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 14 additions & 0 deletions lib/operations/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions spec/operations/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit fc97c78

Please sign in to comment.