CSC/ECE 517 Fall 2017/E1773 Investigate and Fix Expertiza Production Version Runtime Exceptions.rb

From Expertiza_Wiki
Jump to navigation Jump to search

Introduction

Background

Expertizais a open-source ruby-on-rails project on github. It constructs a peer-review system by enabling interactions among users and instructors. Students can sign up for a class, view assignments, submit assignments and give peer reviews using expertiza. Instructors can publish assignments, surveys, and reviews, view statistical results and make announcements. The website is created and currently maintained mainly by the students and faculties from NCSU.

Motivation

Airbrake is a online debugging tool for rails projects that is currently incorporated in Expertiza. Thus, Expertiza production errors at run time are tracked and reported statistically to Airbrake for reviewing and debugging. Our goal for this OSS project is to fix the top 10 run time exceptions ranked by occurrences reported to Airbrake. You can check the 10 most ranked exceptions by click on the previous hyperlink.

Airbrake Run-time Exceptions and Fixes

By investigating into the top 10 errors from airbrake, we can divide them into different categories by the root of their causes.

1. NoMethodError: undefined method for nil:NilClass (4 out of 10)
2. AbstractController::ActionNotFound (4 out of 10)
3. ActionController::InvalidAuthenticityToken (1 out of 10)
4. ActiveRecord::RecordNotFound: Couldn't find Participant without an ID (1 out of 10)

As we have discovered, the same fix can be used to fix each and every different category, which is how we categorized these exceptions initially.

Files Modified

/config/routes.rb

Exception 1. NoMethodError: undefined method 'call' for nil:NilClass

From the Airbrake issue page, we could find out that the problem is actually caused by a gem called passenger.
Although we couldn't find any sign of passenger gem in the recent master branch, but there is a clear sign we found during our review of other errors that some developers had used passenger.
The gem might be under the production path `/home/rails/.rvm/gems/ruby-2.1.5/gems/passenger-5.0.16/' So the solution might be just to remove the gem passenger from production environment.
For more information, please check here

NoMethodError: undefined method 'role' for nil:NilClass is one similar error that occurs during run-time

pic1

pic2



   After investigating this error by going to the error causing url,as shown in pic1, given by airbrake under development environment, 
 http://localhost:3000/response/view?id=91251, the error is verified does not appear again. The last time this error occurred was 5
 months ago.
   Note, the link is only accessible to super admin account. As you may have noticed, the picture on the right shows the passenger gem
 is called and traced, which we couldn't find such a gem installed in the current gemfile.

NoMethodError: undefined method 'uniq' for nil:NilClass is one similar error that occurs during run-time

   Similarly, by going to the error cause url(https://expertiza.ncsu.edu/sign_up_sheet/set_priority) again under development environment, there is no such page exist.


Exception 2. AbstractController::ActionNotFound

In most of the cases, the error is caused by an abusive use of RESTful routing provided in rails. In the middle of somewhere of the app, an index or show action is considered "called" when the redirect url matches such an action which is undefined in the controller.

By thoroughly investigating the controller in trouble and its routes, we came up with a solution that to either reroute the url to an effective url or abort the RESTful route.

For one example, in app/controllers/auth_controller, we found no show/index action defined or needed, but in /config/routes.rb, we have the following:

 =begin
 resources :auth , :except=>[:show,:index,:create,:destroy,:update,:edit,:new] do
   collection do
     post :login
     post :logout
   end
 end
 =end

By using resources:auth, rails actually creates index and show actions by default. Somewhere in the app, a redirect is performed to an index or show view page which does not exist. Thus, in order to save the trouble finding the redirect, we simply redirect anything points to those invalid pages to a valid page, which is the root.The modified code is below:

 post   '/auth/login'  ,to:"auth#login"
 post    '/auth/logout' ,to:"auth#logout"
 get '/auth/*path', to: redirect('/')