Module: ExtendedBundler::Errors
- Defined in:
- lib/extended_bundler/errors.rb,
lib/extended_bundler/errors/version.rb,
lib/extended_bundler/errors/formatter.rb
Defined Under Namespace
Classes: Formatter
Constant Summary collapse
- NATIVE_EXTENSION_MSG =
ExtendedBundler::Errors::Formatter.new(<<-EOF).format #{'=' * 20} We weren't able to handle this error, but we noticed it is an issue with {{bold:native extensions}}. It is recommended to: 1. Find a string in the output that looks like it could be unique to this failure 2. Search Google to try and find a solution 3. Make an issue on {{underline:#{ExtendedBundler::Errors::HOMEPAGE}}} with the output and any solutions you found EOF
- VERSION =
"0.3.0"
- HOMEPAGE =
"http://github.com/jules2689/extended_bundler-errors"
Class Method Summary collapse
-
.register ⇒ Object
Registers the plugin and adds all needed hooks Will call troubleshoot via the ‘after-install` hook if the install does not succeed.
-
.troubleshoot(spec_install) ⇒ Object
Troubleshoots a failed installation Will return if we have no handlers for this gem, otherwise finds a handler to match against Each YAML file is assumed to have an array of hashes with 3 keys in each hash - versions : either ‘all` or a hash with min/max indicating the versions of the gem this applies to - matching : An array of strings that will be used (as a regex) to match against the error message - message : A message to tell the user instead of the original stack trace.
Class Method Details
.register ⇒ Object
Registers the plugin and adds all needed hooks Will call troubleshoot via the ‘after-install` hook if the install does not succeed
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/extended_bundler/errors.rb', line 25 def register return if defined?(@registered) && @registered @registered = true Bundler::Plugin.add_hook('after-install') do |spec_install| troubleshoot(spec_install) if spec_install.state != :installed end Bundler::Plugin.add_hook('before-install-all') do |_d| # This hook makes bundler load the plugin # Because the plugin is loaded before everything, our after-install hook is registered end end |
.troubleshoot(spec_install) ⇒ Object
Troubleshoots a failed installation Will return if we have no handlers for this gem, otherwise finds a handler to match against Each YAML file is assumed to have an array of hashes with 3 keys in each hash
-
versions : either ‘all` or a hash with min/max indicating the versions of the gem this applies to
-
matching : An array of strings that will be used (as a regex) to match against the error message
-
message : A message to tell the user instead of the original stack trace
This works by finding all potential “handlers” for a given gem and finding one that matches the version and has an output (in matching) that matches the message. If it does match, it will replace the error message and provide step by step instructions on how to proceed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/extended_bundler/errors.rb', line 51 def troubleshoot(spec_install) path = handler_path(spec_install.name) return nil unless File.exist?(path) troubleshooted = false yaml = YAML.load_file(path) yaml.each do |handler| next unless version_match?(spec_install.spec.version, handler['versions']) next unless handler['matching'].any? { |m| spec_install.error =~ Regexp.new(m) } spec_install.error = build_error(spec_install, handler) troubleshooted end if !troubleshooted && spec_install.error.include?('Failed to build gem native extension') spec_install.error = spec_install.error + "\n\n" + NATIVE_EXTENSION_MSG end end |