You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 4.3 kB

12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # Better Errors [![Gem Version](http://img.shields.io/gem/v/better_errors.svg)](https://rubygems.org/gems/better_errors) [![Build Status](https://travis-ci.org/charliesome/better_errors.svg)](https://travis-ci.org/charliesome/better_errors) [![Code Climate](http://img.shields.io/codeclimate/github/charliesome/better_errors.svg)](https://codeclimate.com/github/charliesome/better_errors)
  2. Better Errors replaces the standard Rails error page with a much better and more useful error page. It is also usable outside of Rails in any Rack app as Rack middleware.
  3. ![image](http://i.imgur.com/6zBGAAb.png)
  4. ## Features
  5. * Full stack trace
  6. * Source code inspection for all stack frames (with highlighting)
  7. * Local and instance variable inspection
  8. * Live REPL on every stack frame
  9. ## Installation
  10. Add this to your Gemfile:
  11. ```ruby
  12. group :development do
  13. gem "better_errors"
  14. end
  15. ```
  16. If you would like to use Better Errors' **advanced features** (REPL, local/instance variable inspection, pretty stack frame names), you need to add the [`binding_of_caller`](https://github.com/banister/binding_of_caller) gem by [@banisterfiend](http://twitter.com/banisterfiend) to your Gemfile:
  17. ```ruby
  18. gem "binding_of_caller"
  19. ```
  20. This is an optional dependency however, and Better Errors will work without it.
  21. _Note: If you discover that Better Errors isn't working - particularly after upgrading from version 0.5.0 or less - be sure to set `config.consider_all_requests_local = true` in `config/environments/development.rb`._
  22. ## Security
  23. **NOTE:** It is *critical* you put better\_errors in the **development** section. **Do NOT run better_errors in production, or on Internet facing hosts.**
  24. You will notice that the only machine that gets the Better Errors page is localhost, which means you get the default error page if you are developing on a remote host (or a virtually remote host, such as a Vagrant box). Obviously, the REPL is not something you want to expose to the public, but there may also be other pieces of sensitive information available in the backtrace.
  25. To poke selective holes in this security mechanism, you can add a line like this to your startup (for example, on Rails it would be `config/environments/development.rb`)
  26. ```ruby
  27. BetterErrors::Middleware.allow_ip! ENV['TRUSTED_IP'] if ENV['TRUSTED_IP']
  28. ```
  29. Then run Rails like this:
  30. ```shell
  31. TRUSTED_IP=66.68.96.220 rails s
  32. ```
  33. Note that the `allow_ip!` is actually backed by a `Set`, so you can add more than one IP address or subnet.
  34. **Tip:** You can find your apparent IP by hitting the old error page's "Show env dump" and looking at "REMOTE_ADDR".
  35. **VirtualBox:** If you are using VirtualBox and are accessing the guest from your host's browser, you will need to use `allow_ip!` to see the error page.
  36. ## Usage
  37. If you're using Rails, there's nothing else you need to do.
  38. If you're not using Rails, you need to insert `BetterErrors::Middleware` into your middleware stack, and optionally set `BetterErrors.application_root` if you'd like Better Errors to abbreviate filenames within your application.
  39. Here's an example using Sinatra:
  40. ```ruby
  41. require "sinatra"
  42. require "better_errors"
  43. configure :development do
  44. use BetterErrors::Middleware
  45. BetterErrors.application_root = __dir__
  46. end
  47. get "/" do
  48. raise "oops"
  49. end
  50. ```
  51. ### Unicorn, Puma, and other multi-worker servers
  52. Better Errors works by leaving a lot of context in server process memory. If
  53. you're using a web server that runs multiple "workers" it's likely that a second
  54. request (as happens when you click on a stack frame) will hit a different
  55. worker. That worker won't have the necessary context in memory, and you'll see
  56. a `Session Expired` message.
  57. If this is the case for you, consider turning the number of workers to one (1)
  58. in `development`. Another option would be to use Webrick, Mongrel, Thin,
  59. or another single-process server as your `rails server`, when you are trying
  60. to troubleshoot an issue in development.
  61. ## Get in touch!
  62. If you're using better_errors, I'd love to hear from you. Drop me a line and tell me what you think!
  63. ## Contributing
  64. 1. Fork it
  65. 2. Create your feature branch (`git checkout -b my-new-feature`)
  66. 3. Commit your changes (`git commit -am 'Add some feature'`)
  67. 4. Push to the branch (`git push origin my-new-feature`)
  68. 5. Create new Pull Request

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...