You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/08/04 00:13:53 UTC
[GitHub] jaydoane opened a new pull request #1486: Expose document update
errors to client
jaydoane opened a new pull request #1486: Expose document update errors to client
URL: https://github.com/apache/couchdb/pull/1486
<!-- Thank you for your contribution!
Please file this form by replacing the Markdown comments
with your text. If a section needs no action - remove it.
Also remember, that CouchDB uses the Review-Then-Commit (RTC) model
of code collaboration. Positive feedback is represented +1 from committers
and negative is a -1. The -1 also means veto, and needs to be addressed
to proceed. Once there are no objections, the PR can be merged by a
CouchDB committer.
See: http://couchdb.apache.org/bylaws.html#decisions for more info. -->
## Overview
<!-- Please give a short brief for the pull request,
what problem it solves or how it makes things better. -->
While debugging `mix test --trace test/security_validation_test.exs:136`,
I discovered errors like these in the log
```
[error] 2018-07-31T05:18:16.203697Z node1@127.0.0.1 <0.9041.197> 84010d6053 req_err(1170928471) case_clause : {ok,{error,[{{doc,<<"test_doc">>,
{1,
[<<229,11,252,202,233,186,17,46,190,235,53,42,253,193,160,
226>>]},
{[{<<"foo">>,1},{<<"author">>,<<"jerry">>}]},
[],false,
[{ref,#Ref<0.1861500748.325844996.171030>}]},
conflict}]}}
[<<"chttpd_db:update_doc/4 L1052">>,<<"chttpd_db:send_updated_doc/6 L1015">>,<<"chttpd:handle_req_after_auth/2 L309">>,<<"chttpd:process_request/1 L291">>,<<"chttpd:handle_request_int/1 L231">>,<<"mochiweb_http:headers/6 L124">>,<<"proc_lib:init_p_do_apply/3 L247">>]
[error] 2018-07-31T05:33:06.794904Z node1@127.0.0.1 <0.20975.197> 82607a8c12 req_err(1170928471) case_clause : {ok,{error,[{{doc,<<"test_doc">>,
{3,
[<<5,68,252,180,43,161,216,223,26,119,71,219,212,229,159,
113>>]},
{[]},
[],true,
[{ref,#Ref<0.1861500748.325582853.36729>}]},
{unauthorized,<<"You are 'jerry', not the author 'tom' of this document. You jerk.">>}}]}}
[<<"chttpd_db:update_doc/4 L1052">>,<<"chttpd_db:send_updated_doc/6 L1015">>,<<"chttpd:handle_req_after_auth/2 L309">>,<<"chttpd:process_request/1 L291">>,<<"chttpd:handle_request_int/1 L231">>,<<"mochiweb_http:headers/6 L124">>,<<"proc_lib:init_p_do_apply/3 L247">>]
```
which resulted in 500s for the client:
```
[notice] 2018-07-31T05:18:16.203892Z node1@127.0.0.1 <0.9041.197> 84010d6053 localhost:15984 127.0.0.1 tom PUT /random-test-db--576460751101953000--576460752303423487/test_doc 500 ok 15
[notice] 2018-07-31T05:33:06.795225Z node1@127.0.0.1 <0.20975.197> 82607a8c12 localhost:15984 127.0.0.1 jerry DELETE /random-test-db--576460751061548000--576460752303423487/test_doc?rev=3-0544fcb42ba1d8df1a7747dbd4e59f71 500 ok 50
```
The case in question is in [`fabric:update_doc/3`](https://github.com/apache/couchdb/blob/master/src/fabric/src/fabric.erl#L238-L252), since that clause cannot match the above form.
This changes the guard in `fabric_doc_update:go/3` to allow `Health =:=
error`, and also adds new case clauses to both `fabric:udpate_docs/3` and `fabric:udpate_doc/3` to correctly handle that shape of error.
Instead of 500s, clients will see (transient) errors like:
```
409 {"error": "conflict", "reason": "Document update conflict."}
401 {"unauthorized": "You are 'jerry', not the author 'tom' of this document. You jerk."}
```
## Testing recommendations
`make eunit apps=fabric suites=fabric`
<!-- Describe how we can test your changes.
Does it provides any behaviour that the end users
could notice? -->
## Related Issues or Pull Requests
None that I could find.
<!-- If your changes affects multiple components in different
repositories please put links to those issues or pull requests here. -->
## Checklist
- [X] Code is written and works correctly;
- [X] Changes are covered by tests;
- [ ] Documentation reflects the changes;
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services