aborted destroy turned into JSONAPI::Exceptions::ValidationErrors without error message
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
Research direction
Start with the JR processor's process method and lib/jsonapi/resource.rb around lines 224-231, which the issue identifies as related to model error messages. Reproduce a Rails destroy callback that throws :abort, then trace how empty errors reach ValidationErrors. Done means the aborted destroy produces a usable validation error instead of the NoMethodError caused by a missing code.
Written by the indexing model from the issue text.
Description
This issue is a (choose one):
- Problem/bug report.
- Feature request.
- Request for support. Note: Please try to avoid submitting issues for support requests. Use Gitter instead.
Checklist before submitting:
- I've searched for an existing issue.
- I've asked my question on Gitter and have not received a satisfactory answer.
- I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
- The feature I'm asking for is compliant with the JSON:API spec.
Description
Choose one section below and delete the other:
Bug reports:
JR version 0.9.3
- Given a record with
before_destroy :something_that_may_abort - Define
def something_that_may_abort; throw :abort if condition?; end - POST a
DELETEby id to the corresponding resource - Get
NoMethodError: undefined method `code' for nil:NilClass
The problem stems from the JR processor
def process
run_callbacks :operation do
run_callbacks operation_type do
@result = send(operation_type)
end
end
rescue JSONAPI::Exceptions::Error => e
@result = JSONAPI::ErrorsOperationResult.new(e.errors[0].code, e.errors)
end
Where the rescued JSONAPI::Exceptions::Error is a JSONAPI::Exceptions::ValidationErrors and the error_messages attribute is an empty hash. This can be observed in Rails code as
record.destroy
=> false
record.errors.messages
=> {}
I suspect this isn't an altogether unusual case. Until this is addressed in JR, I'm looking at handling this by adding validation errors to the model before throwing the abort
Proposal
I wonder if there may be a place in JR to add a default validation error message to JSONAPI::Exceptions::ValidationErrors when none are given (i.e. when resource.model_error_messages is empty
https://github.com/cerebris/jsonapi-resources/blob/v0.9.7/lib/jsonapi/resource.rb#L224-L231
- Dominant language
- Ruby
- Stars
- 2.3k
- Forks
- 546
- PR merge metrics
- No merged PRs in 30d
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JSONAPI-Resources/jsonapi-resources
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 3/5 1-2 days Newbie friendliness 50/100
JSONAPI-Resources/jsonapi-resources#1488 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
JSONAPI-Resources/jsonapi-resources#1479 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
JSONAPI-Resources/jsonapi-resources#1477 · 3 comments · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
All issues in JSONAPI-Resources/jsonapi-resources
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
solana-foundation/pay-kit#341 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
TheOdinProject/curriculum#31427 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
cyclestreets/cyclescape#1107 · 1 reaction ·
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 1 day