SlideShare une entreprise Scribd logo
1  sur  15
Debugging Rails




Michael Denomy
Boston Ruby Project Night
March 5, 2013
Agenda
• Introduction to Rails Debugging
 - Role of testing
 - Examining the log files
 - Interpreting the stack trace
 - The better_errors gem
 - Rails console
 - Using pry gem to debug
Testing
• First line of defense
   - Avoid defects in the first place
• Since adopting TDD, time spent
     ‣ using a debugger
     ‣ writing log messages
     ‣ triaging defects

have all dropped significantly
• Find a defect?
   - First step: write a test to reproduce it
General Debugging Tips
• Reproduce the problem
 - Under what conditions does it occur
   ‣ data, configuration, environment

 - Write a unit/integration test if possible
• Divide and Conquer
 - Reduce the places you have to look
   ‣ Logging statements
   ‣ Simplest conditions to reproduce
   ‣ Any recent changes?
General Debugging Tips
• Pay attention to the data
 - Don’t jump to conclusions
 - Avoid “that can’t be the problem”
• Be methodical
 - Talk the problem out
   ‣ Use “rubber ducky debugging” if solo

 - Change one thing at a time
 - Keep track of changes/ideas you’ve tried out
 - Periodically circle back and re-evaluate
Rails Log Files
• Rails keeps log file for each environment
  - e.g. development.log, production.log
• Log messages have severity levels
  - :debug, :info, :warn, :error, :fatal
  - config.log.level filters what gets logged
• Writing your own log messages
Asset Pipeline Log Messages
• Lots of messages related to asset pipeline
• quiet_assets gem
  - suppresses asset pipeline messages
  - should be used in development only
• thin web server
  - fixes a problem with message that shows up
    with quiet_assets gem and WEBrick

• Gemfile
Reading A Stack Trace
The better_errors gem
• Richer error page
   ‣ Full stack trace
   ‣ Source code inspection for all stack frames
   ‣ Local and instance variable inspection
   ‣ Live REPL on every stack frame

• Advanced features requires
  ‘binding_of_caller’ gem
• Gemfile - Development only!
Using the Rails Console
• Great playground to experiment
  - Especially handy for model access
• Danger!!!
  - Good idea to run in sandbox to prevent
    changing data
      rails console --sandbox
pry gem
• pry is an IRB replacement
  - live help
  - syntax highlighting
  - navigate scope
  - and much, much, more
• pry also supports plugins...lots of them
  - check out www.rubygems.org for full list
• pry-debugger gem
  - step, next, continue
Debug Using an IDE
• If you come from a background where
  you have used an IDE, e.g. Java or C#, an
  IDE is an option
• RubyMine has an integrated debugger
  - Does not play well with pry-debug or other
    debuggers
Summary
• Divide and Conquer Strategy
• Be methodical
• Check the logs for clues
• Testing is the best defense
• Questions?
References
http://gipsysoft.com/articles/debug-rules/
http://pryrepl.org/screencasts.html
http://railscasts.com/episodes/86-logging-variables
http://railscasts.com/episodes/24-the-stack-trace
http://railscasts.com/episodes/280-pry-with-rails
http://samuelmullen.com/2012/07/getting-more-out-of-the-rails-console/
Debugging Rails




Michael Denomy
Boston Ruby Project Night
March 5, 2013

Contenu connexe

Tendances

Git hooks For PHP Developers
Git hooks For PHP DevelopersGit hooks For PHP Developers
Git hooks For PHP DevelopersUmut IŞIK
 
BAM experiences in large scale deployments
BAM experiences in large scale deploymentsBAM experiences in large scale deployments
BAM experiences in large scale deploymentsAIMS Innovation
 
6 reasons you should program in go
6 reasons you should program in go6 reasons you should program in go
6 reasons you should program in goMichael Banzon
 
Saving Time By Testing With Jest
Saving Time By Testing With JestSaving Time By Testing With Jest
Saving Time By Testing With JestBen McCormick
 
JRuby Hot Topics 2008-12-12
JRuby Hot Topics 2008-12-12JRuby Hot Topics 2008-12-12
JRuby Hot Topics 2008-12-12Koichiro Ohba
 
Wordpress -> Middleman: Lesson learned in the 2-years since migrating
Wordpress -> Middleman: Lesson learned in the 2-years since migratingWordpress -> Middleman: Lesson learned in the 2-years since migrating
Wordpress -> Middleman: Lesson learned in the 2-years since migratingJames Stone
 
Unit Testing in JavaScript
Unit Testing in JavaScriptUnit Testing in JavaScript
Unit Testing in JavaScriptRob Scaduto
 
Php|tek '12 It's More Than Just Style
Php|tek '12  It's More Than Just StylePhp|tek '12  It's More Than Just Style
Php|tek '12 It's More Than Just StyleLB Denker
 
CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014brian d foy
 
JRuby deployments
JRuby deploymentsJRuby deployments
JRuby deploymentsberninme
 
Indexing BackPAN
Indexing BackPANIndexing BackPAN
Indexing BackPANbrian d foy
 
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...PHP Conference Argentina
 
Webforms
WebformsWebforms
Webformsrustd
 
What python can learn from java
What python can learn from javaWhat python can learn from java
What python can learn from javajbellis
 
JSFoo-2017 Takeaways
JSFoo-2017 TakeawaysJSFoo-2017 Takeaways
JSFoo-2017 TakeawaysMir Ali
 
Ruby Midwest 2010 jRuby by Charles Nutter
Ruby Midwest 2010 jRuby by Charles NutterRuby Midwest 2010 jRuby by Charles Nutter
Ruby Midwest 2010 jRuby by Charles NutterSteven Chau
 
Realtime MVC with Sails.js
Realtime MVC with Sails.jsRealtime MVC with Sails.js
Realtime MVC with Sails.jsSerdar Dogruyol
 

Tendances (20)

Git hooks For PHP Developers
Git hooks For PHP DevelopersGit hooks For PHP Developers
Git hooks For PHP Developers
 
BAM experiences in large scale deployments
BAM experiences in large scale deploymentsBAM experiences in large scale deployments
BAM experiences in large scale deployments
 
6 reasons you should program in go
6 reasons you should program in go6 reasons you should program in go
6 reasons you should program in go
 
Saving Time By Testing With Jest
Saving Time By Testing With JestSaving Time By Testing With Jest
Saving Time By Testing With Jest
 
JRuby Hot Topics 2008-12-12
JRuby Hot Topics 2008-12-12JRuby Hot Topics 2008-12-12
JRuby Hot Topics 2008-12-12
 
Wordpress -> Middleman: Lesson learned in the 2-years since migrating
Wordpress -> Middleman: Lesson learned in the 2-years since migratingWordpress -> Middleman: Lesson learned in the 2-years since migrating
Wordpress -> Middleman: Lesson learned in the 2-years since migrating
 
Unit Testing in JavaScript
Unit Testing in JavaScriptUnit Testing in JavaScript
Unit Testing in JavaScript
 
Php|tek '12 It's More Than Just Style
Php|tek '12  It's More Than Just StylePhp|tek '12  It's More Than Just Style
Php|tek '12 It's More Than Just Style
 
CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014
 
JRuby deployments
JRuby deploymentsJRuby deployments
JRuby deployments
 
Indexing BackPAN
Indexing BackPANIndexing BackPAN
Indexing BackPAN
 
Reason React
Reason ReactReason React
Reason React
 
Upgrading to rails3
Upgrading to rails3Upgrading to rails3
Upgrading to rails3
 
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
 
Webforms
WebformsWebforms
Webforms
 
What python can learn from java
What python can learn from javaWhat python can learn from java
What python can learn from java
 
Presentacion minitest
Presentacion minitestPresentacion minitest
Presentacion minitest
 
JSFoo-2017 Takeaways
JSFoo-2017 TakeawaysJSFoo-2017 Takeaways
JSFoo-2017 Takeaways
 
Ruby Midwest 2010 jRuby by Charles Nutter
Ruby Midwest 2010 jRuby by Charles NutterRuby Midwest 2010 jRuby by Charles Nutter
Ruby Midwest 2010 jRuby by Charles Nutter
 
Realtime MVC with Sails.js
Realtime MVC with Sails.jsRealtime MVC with Sails.js
Realtime MVC with Sails.js
 

En vedette

Managing the logs of your (Rails) applications - RailsWayCon 2011
Managing the logs of your (Rails) applications - RailsWayCon 2011Managing the logs of your (Rails) applications - RailsWayCon 2011
Managing the logs of your (Rails) applications - RailsWayCon 2011lennartkoopmann
 
Final project report format
Final project report formatFinal project report format
Final project report formatMasud Sarkar
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentationadamcookeuk
 

En vedette (6)

Managing the logs of your (Rails) applications - RailsWayCon 2011
Managing the logs of your (Rails) applications - RailsWayCon 2011Managing the logs of your (Rails) applications - RailsWayCon 2011
Managing the logs of your (Rails) applications - RailsWayCon 2011
 
Scala vs Ruby
Scala vs RubyScala vs Ruby
Scala vs Ruby
 
Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
 
Final project report format
Final project report formatFinal project report format
Final project report format
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Project Report Format
Project Report FormatProject Report Format
Project Report Format
 

Similaire à Debugging rails

Debugging Rails 3 Applications
Debugging Rails 3 ApplicationsDebugging Rails 3 Applications
Debugging Rails 3 ApplicationsNathan Broadbent
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLBarry Jones
 
Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009pratiknaik
 
Performance optimization - JavaScript
Performance optimization - JavaScriptPerformance optimization - JavaScript
Performance optimization - JavaScriptFilip Mares
 
Ruby performance - The low hanging fruit
Ruby performance - The low hanging fruitRuby performance - The low hanging fruit
Ruby performance - The low hanging fruitBruce Werdschinski
 
What's the "right" PHP Framework?
What's the "right" PHP Framework?What's the "right" PHP Framework?
What's the "right" PHP Framework?Barry Jones
 
Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...Danny Mulligan
 
Node.js Getting Started &amd Best Practices
Node.js Getting Started &amd Best PracticesNode.js Getting Started &amd Best Practices
Node.js Getting Started &amd Best Practicesbotsplash.com
 
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...srisatish ambati
 
2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with BlackfireMarko Mitranić
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Henry S
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8Heartin Jacob
 
Automated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumAutomated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumDev9Com
 
Tips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTaro L. Saito
 
Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentMongoDB
 
Contributing to rails
Contributing to railsContributing to rails
Contributing to railsLukas Eppler
 

Similaire à Debugging rails (20)

Debugging Rails 3 Applications
Debugging Rails 3 ApplicationsDebugging Rails 3 Applications
Debugging Rails 3 Applications
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Lessons Learnt in 2009
Lessons Learnt in 2009Lessons Learnt in 2009
Lessons Learnt in 2009
 
Fastest Servlets in the West
Fastest Servlets in the WestFastest Servlets in the West
Fastest Servlets in the West
 
Performance optimization - JavaScript
Performance optimization - JavaScriptPerformance optimization - JavaScript
Performance optimization - JavaScript
 
Ruby performance - The low hanging fruit
Ruby performance - The low hanging fruitRuby performance - The low hanging fruit
Ruby performance - The low hanging fruit
 
What's the "right" PHP Framework?
What's the "right" PHP Framework?What's the "right" PHP Framework?
What's the "right" PHP Framework?
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 
Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...
 
Node.js Getting Started &amd Best Practices
Node.js Getting Started &amd Best PracticesNode.js Getting Started &amd Best Practices
Node.js Getting Started &amd Best Practices
 
How DSL works on Ruby
How DSL works on RubyHow DSL works on Ruby
How DSL works on Ruby
 
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
 
2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire2019 PHP Serbia - Boosting your performance with Blackfire
2019 PHP Serbia - Boosting your performance with Blackfire
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
Automated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumAutomated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and Selenium
 
Tips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTips For Maintaining OSS Projects
Tips For Maintaining OSS Projects
 
Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production Deployment
 
Contributing to rails
Contributing to railsContributing to rails
Contributing to rails
 

Plus de Michael Denomy

Intro to automated testing
Intro to automated testingIntro to automated testing
Intro to automated testingMichael Denomy
 
Breathe In and Out With Me - Burlington Ruby Conference 2015
Breathe In and Out With Me - Burlington Ruby Conference 2015Breathe In and Out With Me - Burlington Ruby Conference 2015
Breathe In and Out With Me - Burlington Ruby Conference 2015Michael Denomy
 
Writing Maintainable Tests with PageObjects
Writing Maintainable Tests with PageObjectsWriting Maintainable Tests with PageObjects
Writing Maintainable Tests with PageObjectsMichael Denomy
 
Memory Management in RubyMotion
Memory Management in RubyMotionMemory Management in RubyMotion
Memory Management in RubyMotionMichael Denomy
 
Aikido, Controller Tests, and LinkedIn
Aikido, Controller Tests, and LinkedInAikido, Controller Tests, and LinkedIn
Aikido, Controller Tests, and LinkedInMichael Denomy
 
Design Principles - Michael Denomy at Launch Academy
Design Principles - Michael Denomy at Launch AcademyDesign Principles - Michael Denomy at Launch Academy
Design Principles - Michael Denomy at Launch AcademyMichael Denomy
 
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotionFrom Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotionMichael Denomy
 
Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven DevelopmentMichael Denomy
 

Plus de Michael Denomy (9)

Intro to automated testing
Intro to automated testingIntro to automated testing
Intro to automated testing
 
Breathe In and Out With Me - Burlington Ruby Conference 2015
Breathe In and Out With Me - Burlington Ruby Conference 2015Breathe In and Out With Me - Burlington Ruby Conference 2015
Breathe In and Out With Me - Burlington Ruby Conference 2015
 
Writing Maintainable Tests with PageObjects
Writing Maintainable Tests with PageObjectsWriting Maintainable Tests with PageObjects
Writing Maintainable Tests with PageObjects
 
Memory Management in RubyMotion
Memory Management in RubyMotionMemory Management in RubyMotion
Memory Management in RubyMotion
 
Aikido, Controller Tests, and LinkedIn
Aikido, Controller Tests, and LinkedInAikido, Controller Tests, and LinkedIn
Aikido, Controller Tests, and LinkedIn
 
Reinventing Yourself
Reinventing YourselfReinventing Yourself
Reinventing Yourself
 
Design Principles - Michael Denomy at Launch Academy
Design Principles - Michael Denomy at Launch AcademyDesign Principles - Michael Denomy at Launch Academy
Design Principles - Michael Denomy at Launch Academy
 
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotionFrom Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
 
Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven Development
 

Debugging rails