NoMethodError when pushing errors from JS client.
krasio opened this issue · 1 comments
krasio commented
I'm seeing NoMethodError on the server side when trying to use the JS client.
Here's a test reproducing the issue:
diff --git a/spec/lib/workers/occurrences_worker_spec.rb b/spec/lib/workers/occurrences_worker_spec.rb
index 20d5e77..a45e5b6 100644
--- a/spec/lib/workers/occurrences_worker_spec.rb
+++ b/spec/lib/workers/occurrences_worker_spec.rb
@@ -106,6 +106,49 @@ describe OccurrencesWorker do
end
context "[attributes]" do
+ it "works for js:hosted types" do
+ js_params = @params.merge({
+ "client" => "javascript",
+ "class_name" => "ReferenceError",
+ "message" => "foo is not defined",
+ "backtraces" => [
+ {
+ "name" => "Active Thread",
+ "faulted" => true,
+ "backtrace" => [
+ {
+ "url" => "http://localhost:3000/assets/vendor.js",
+ "line" => 11671,
+ "symbol" => "?",
+ "context" => nil,
+ "type" => "js:hosted"
+ }
+ ]
+ }
+ ],
+ "capture_method" => "onerror",
+ "occurred_at" => "2014-05-26T22:43:31Z",
+ "schema" => "http",
+ "host" => "localhost",
+ "port" => "3000",
+ "path" => "/admin",
+ "query" => "",
+ "user_agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:28.0) Gecko/20100101 Firefox/28.0",
+ "screen_width" => 1920,
+ "screen_height" => 1200,
+ "window_width" => 1870,
+ "window_height" => 767,
+ "color_depth" => 24
+ })
+
+ occ = OccurrencesWorker.new(js_params).perform
+ expect(occ).to be_kind_of(Occurrence)
+
+ expect(occ.client).to eql('javascript')
+ expect(occ.bug.environment.name).to eql('production')
+ expect(occ.bug.client).to eql('javascript')
+ end
+
it "should create an occurrence with the given attributes" do
occ = OccurrencesWorker.new(@params).perform
expect(occ).to be_kind_of(Occurrence)
This fails with
Failures:
1) OccurrencesWorker#perform [attributes] works for js:hosted types
Failure/Error: occ = OccurrencesWorker.new(js_params).perform
NoMethodError:
undefined method `environment' for nil:NilClass
# ./app/models/occurrence.rb:738:in `sourcemap'
# ./lib/workers/occurrences_worker.rb:158:in `build_occurrence'
# ./lib/workers/occurrences_worker.rb:79:in `perform'
# ./spec/lib/workers/occurrences_worker_spec.rb:144:in `(root)'
I think the reason is in https://github.com/SquareSquash/web/blob/master/app/models/occurrence.rb#L799, but not sure why are 'js:hosted' types treated in a different way.
RISCfuture commented
Thanks for the diff, fixed!