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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [#2683](https://github.com/ruby-grape/grape/pull/2683): Introduce `Grape::Util::Lazy::Base` for unified lazy-type dispatch - [@ericproulx](https://github.com/ericproulx).
* [#2685](https://github.com/ruby-grape/grape/pull/2685): Skip `run_filters` and `endpoint_run_filters.grape` instrumentation when the filter list is empty - [@ericproulx](https://github.com/ericproulx).
* [#2684](https://github.com/ruby-grape/grape/pull/2684): Readability refactors: case/when, guard clauses, small cleanups - [@ericproulx](https://github.com/ericproulx).
* [#2687](https://github.com/ruby-grape/grape/pull/2687): Skip backtrace capture on internal validation exceptions - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

#### Fixes
Expand Down
6 changes: 6 additions & 0 deletions lib/grape/exceptions/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Grape
module Exceptions
class Validation < Base
EMPTY_BACKTRACE = [].freeze

attr_reader :params, :message_key

def initialize(params:, message: nil, status: nil, headers: nil)
Expand All @@ -16,6 +18,10 @@ def initialize(params:, message: nil, status: nil, headers: nil)
end

super(status:, message:, headers:)
# Pre-seed the backtrace so Ruby's raise skips capture. Validation errors are
# a hot path (raised per bad attribute) and end up as 400 Bad Request responses;
# backtraces here point into Grape internals and have no diagnostic value.
set_backtrace(EMPTY_BACKTRACE)
end

# Remove all the unnecessary stuff from Grape::Exceptions::Base like status
Expand Down
4 changes: 4 additions & 0 deletions lib/grape/exceptions/validation_array_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
module Grape
module Exceptions
class ValidationArrayErrors < Base
EMPTY_BACKTRACE = [].freeze

attr_reader :errors

def initialize(errors)
super()
@errors = errors
# Skip backtrace capture — see Grape::Exceptions::Validation for rationale.
set_backtrace(EMPTY_BACKTRACE)
end
end
end
Expand Down
Loading