[RCBC-95] Server's helpful error about map.js errors gets replaced by a generic http 400 happened while uploading design document Created: 23/Nov/12  Updated: 08/Feb/13  Resolved: 29/Nov/12

Status: Closed
Project: Couchbase Ruby client library
Component/s: library
Affects Version/s: 1.2.0.z.beta4
Fix Version/s: 1.2.0
Security Level: Public

Type: Bug Priority: Major
Reporter: Piotr Banasik Assignee: Sergey Avseyev
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment: Mountain Lion


 Description   
Repro:

Create a new model, use the genrator to create a view
add the view line to the model
start the app (rails console)

The default map.js with all the comments in and examples will cause the error already.

/Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/couchbase-1.2.0.z.beta4/lib/couchbase/bucket.rb:165:in `continue': failed to execute HTTP request (key="_design/clocking", status="400" (Bad Request), error=0x00) (Couchbase::Error::HTTP)
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/couchbase-1.2.0.z.beta4/lib/couchbase/bucket.rb:165:in `save_design_doc'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/couchbase-model-0.5.0/lib/couchbase/model.rb:260:in `ensure_design_document!'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/couchbase-model-0.5.0/lib/couchbase/railtie.rb:120:in `block (3 levels) in <class:Railtie>'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/couchbase-model-0.5.0/lib/couchbase/railtie.rb:119:in `each'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/couchbase-model-0.5.0/lib/couchbase/railtie.rb:119:in `block (2 levels) in <class:Railtie>'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:418:in `_run__3328634455356380055__prepare__3132553472985099836__callbacks'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:405:in `__run_callback'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/actionpack-3.2.9/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/actionpack-3.2.9/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/railties-3.2.9/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `run'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/railties-3.2.9/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `each'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/railties-3.2.9/lib/rails/application.rb:136:in `initialize!'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/railties-3.2.9/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/piotr/Work/git/ph_time/config/environment.rb:5:in `<top (required)>'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/railties-3.2.9/lib/rails/application.rb:103:in `require'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/railties-3.2.9/lib/rails/application.rb:103:in `require_environment!'
from /Users/piotr/.rvm/gems/ruby-1.9.3-p327@time/gems/railties-3.2.9/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

Now after a bit of tinkering .. I just added an else to the if block_given? in there .. to reveal the error ..
        if block_given?
          if res.success? && val['error']
            res.error = Error::View.new("save_design_doc", val['error'])
          end
          yield(res)
        else
          unless res.success?
            if val['error'] && val['reason']
              raise Couchbase::Error::View.new(val['error'], val['reason'])
            end
          end
        end

And that returned a much more civil error:

SERVER: invalid_design_document: Syntax error in the map function of the view `by_date': SyntaxError: Unexpected end of input (Couchbase::Error::View)


 Comments   
Comment by Piotr Banasik [ 23/Nov/12 ]
Not sure if you want to keep that error code in there .. or perhaps tweak how the res.error stuff works in the block given section and call this better in the client lib perhaps? Not sure .. maybe tweak it on both ends really ..
Comment by Sergey Avseyev [ 29/Nov/12 ]
Fix http://review.couchbase.org/22894
Generated at Fri Oct 31 10:06:45 CDT 2014 using JIRA 5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9.