extended_bundler-errors 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/extended_bundler-errors.gemspec +38 -0
- data/lib/extended_bundler/backports.rb +20 -0
- data/lib/extended_bundler/errors.rb +87 -0
- data/lib/extended_bundler/errors/formatter.rb +178 -0
- data/lib/extended_bundler/errors/version.rb +5 -0
- data/lib/extended_bundler/handlers/http_parser.yml +16 -0
- data/lib/extended_bundler/handlers/rmagick.yml +18 -0
- data/lib/extended_bundler/handlers/testing_stuff.yml +7 -0
- data/lib/extended_bundler/handlers/testing_stuff_2.yml +6 -0
- data/lib/extended_bundler/handlers/unf_ext.yml +18 -0
- data/plugins.rb +2 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: babe18203afe94da9da04ea703d4e66333764a4202b7c3d0385dc13ac0573a9d
|
4
|
+
data.tar.gz: c58c050aabcc9990511a5cec4721b210030ce925b4a2046318c033a93cd5ae1b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97276b990723124ffd052ea12178efedfd17ec929e33c76691de445324d90f7e327a2f30053bfbf83610a9c4b61a3d24a628381f84b5f6d3838e6ec09c9d5a5a
|
7
|
+
data.tar.gz: 888187e9f737440a9655eab7fd5854f7169a24ae822c982fbf21396de5083c6a9442b452473660d8dc6e20fb2fc39fc919a5011e81bc89541f8b927ded2bddb0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at julian@jnadeau.ca. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
extended_bundler-errors (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
metaclass (0.0.4)
|
10
|
+
minitest (5.11.3)
|
11
|
+
mocha (1.5.0)
|
12
|
+
metaclass (~> 0.0.1)
|
13
|
+
rake (10.5.0)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
bundler (~> 1.16)
|
20
|
+
extended_bundler-errors!
|
21
|
+
minitest (~> 5.0)
|
22
|
+
mocha
|
23
|
+
rake (~> 10.0)
|
24
|
+
|
25
|
+
BUNDLED WITH
|
26
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 jules2689
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# ExtendedBundler::Errors
|
2
|
+
|
3
|
+
Extended Bundler Errors is a `bundler` plugin that makes gem installation errors more actionable, educative, and all around easier to understand.
|
4
|
+
|
5
|
+
Previously when gems fail, `bundler` would simply tell you it failed and give you any output from the gem itself. This often includes C traces from native extensions.
|
6
|
+
|
7
|
+
These are hard to follow, particularly for people new to Ruby, because it requires you to understand the underlying system, programs in use (Imagemagick, SSL libraries, parsers, etc), and the output is simply verbose.
|
8
|
+
|
9
|
+
This gem instead will try to match the output of the gem to a series of handlers (see `lib/extended_bundler/handlers` for a list). Each handler is specific to a gem, an matches one of many potential output. Once matched, we replace the error with something that explains the known problem, how to fix it, and (if possible) include a link to the original output.
|
10
|
+
|
11
|
+
Here is an example:
|
12
|
+
|
13
|
+
Before when RMagick fails to install, you got a verbose log.
|
14
|
+
|
15
|
+
![Before this plugin, RMagick failures were cryptic and confusing](https://user-images.githubusercontent.com/3074765/40488035-c89a6678-5f33-11e8-89fc-f66c054d8765.png)
|
16
|
+
|
17
|
+
After when it fails to install you get a specific, actionable reason and step-by-step guide on how to handle it.
|
18
|
+
|
19
|
+
![After This Plugin, RMagick has better errors](https://user-images.githubusercontent.com/3074765/40489293-c8cf8e9a-5f36-11e8-88f5-fceed052aa24.png)
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
While this is a gem, you need to install it as a plugin:
|
24
|
+
|
25
|
+
`bundler plugin install extended_bundler-errors`
|
26
|
+
|
27
|
+
OR
|
28
|
+
|
29
|
+
`bundler plugin install extended_bundler-errors --git=https://github.com/Shopify/extended_bundler-errors.git`
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
It is recommended to install from `git` and work directly in a `bundle install` run.
|
34
|
+
|
35
|
+
You can also...
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/extended_bundler-errors. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
48
|
+
|
49
|
+
## Code of Conduct
|
50
|
+
|
51
|
+
Everyone interacting in the ExtendedBundler::Errors project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/extended_bundler-errors/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "extended_bundler/errors"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "extended_bundler/errors/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "extended_bundler-errors"
|
8
|
+
spec.version = ExtendedBundler::Errors::VERSION
|
9
|
+
spec.authors = ["jules2689"]
|
10
|
+
spec.email = ["julian@jnadeau.ca"]
|
11
|
+
|
12
|
+
spec.summary = "Extended Errors for Bundler"
|
13
|
+
spec.description = "Extended Errors for Bundler"
|
14
|
+
spec.homepage = "http://github.com/shopify/extended_bundler-errors"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'bundler/version'
|
2
|
+
|
3
|
+
# In Bundler <= 1.17, we do not have the `after-install` hook, so monkey patch Bundler to include it
|
4
|
+
if Gem::Version.new(Bundler::VERSION) < Gem::Version.new('1.17')
|
5
|
+
# We need to make sure ParallelInstaller is defined before we can patch it
|
6
|
+
require 'bundler/installer/parallel_installer'
|
7
|
+
|
8
|
+
module Bundler
|
9
|
+
class ParallelInstaller
|
10
|
+
private
|
11
|
+
|
12
|
+
alias_method :old_do_install, :do_install
|
13
|
+
def do_install(spec_install, worker_num)
|
14
|
+
ret = old_do_install(spec_install, worker_num)
|
15
|
+
Bundler::Plugin.hook('after-install', ret)
|
16
|
+
ret
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "extended_bundler/errors/version"
|
2
|
+
require "extended_bundler/errors/formatter"
|
3
|
+
require "extended_bundler/backports"
|
4
|
+
|
5
|
+
require "bundler"
|
6
|
+
require "fileutils"
|
7
|
+
require "yaml"
|
8
|
+
|
9
|
+
module ExtendedBundler
|
10
|
+
module Errors
|
11
|
+
class << self
|
12
|
+
# Registers the plugin and adds all needed hooks
|
13
|
+
# Will call troubleshoot via the `after-install` hook if the install does not succeed
|
14
|
+
def register
|
15
|
+
return if defined?(@registered) && @registered
|
16
|
+
@registered = true
|
17
|
+
|
18
|
+
Bundler::Plugin.add_hook('after-install') do |spec_install|
|
19
|
+
troubleshoot(spec_install) if spec_install.state != :installed
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Troubleshoots a failed installation
|
24
|
+
# Will return if we have no handlers for this gem, otherwise finds a handler to match against
|
25
|
+
# Each YAML file is assumed to have an array of hashes with 3 keys in each hash
|
26
|
+
# - versions : either `all` or a hash with min/max indicating the versions of the gem this applies to
|
27
|
+
# - matching : An array of strings that will be used (as a regex) to match against the error message
|
28
|
+
# - message : A message to tell the user instead of the original stack trace
|
29
|
+
#
|
30
|
+
# This works by finding all potential "handlers" for a given gem and finding one that matches the version
|
31
|
+
# and has an output (in matching) that matches the message. If it does match, it will replace the error message
|
32
|
+
# and provide step by step instructions on how to proceed
|
33
|
+
#
|
34
|
+
# @param spec_install [Bundler::ParallelInstaller::SpecInstallation] a SpecInstallation object from Bundler
|
35
|
+
def troubleshoot(spec_install)
|
36
|
+
path = handler_path(spec_install.name)
|
37
|
+
return nil unless File.exist?(path)
|
38
|
+
yaml = YAML.load_file(path)
|
39
|
+
yaml.each do |handler|
|
40
|
+
next unless version_match?(spec_install.spec.version, handler['versions'])
|
41
|
+
next unless handler['matching'].any? { |m| spec_install.error =~ Regexp.new(m) }
|
42
|
+
spec_install.error = build_error(spec_install, handler)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def version_match?(spec_version, matching_versions)
|
49
|
+
# Valid versions are either the string `all` or a hash with min/max
|
50
|
+
return true if matching_versions == 'all'
|
51
|
+
|
52
|
+
# Validate the matching versions are correct (Hash)
|
53
|
+
unless matching_versions.is_a?(Hash)
|
54
|
+
return ArgumentError, 'matching key must be "all" or a hash with min/max'
|
55
|
+
end
|
56
|
+
|
57
|
+
# If we don't specify a minimum, we can just start from 0
|
58
|
+
min = Gem::Version.new(matching_versions.fetch('min', '0'))
|
59
|
+
|
60
|
+
# If we don't specify a max, we just dont compare against a max
|
61
|
+
if matching_versions['max']
|
62
|
+
max = Gem::Version.new(matching_versions['max'])
|
63
|
+
return spec_version >= min && spec_version <= max
|
64
|
+
end
|
65
|
+
spec_version > min
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_error(spec_install, handler)
|
69
|
+
body = handler['message']
|
70
|
+
# If we can pull out the original logs, add those to the message
|
71
|
+
if log = spec_install.error.match(/Results logged to (?<message>.*)/)
|
72
|
+
body += "\n{{bold:Original Logs are available at:}}\n" + log[:message]
|
73
|
+
end
|
74
|
+
|
75
|
+
# Otherwise just format what we have
|
76
|
+
title = "#{spec_install.name} (#{spec_install.spec.version.to_s}) could not be installed"
|
77
|
+
lines = [ "{{bold:#{title}}}", ("━" * title.length), body.lines.map(&:chomp) ].flatten
|
78
|
+
formatted_lines = lines.map { |l| "{{red:┃}} #{l}".strip }
|
79
|
+
ExtendedBundler::Errors::Formatter.new(formatted_lines.join("\n")).format
|
80
|
+
end
|
81
|
+
|
82
|
+
def handler_path(gem_name)
|
83
|
+
File.expand_path("../handlers/#{gem_name}.yml", __FILE__)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'strscan'
|
4
|
+
|
5
|
+
module ExtendedBundler
|
6
|
+
module Errors
|
7
|
+
class Formatter
|
8
|
+
# Available mappings of formattings
|
9
|
+
# To use any of them, you can use {{<key>:<string>}}
|
10
|
+
# There are presentational (colours and formatters)
|
11
|
+
# and semantic (error, info, command) formatters available
|
12
|
+
#
|
13
|
+
SGR_MAP = {
|
14
|
+
# presentational
|
15
|
+
'red' => '31',
|
16
|
+
'green' => '32',
|
17
|
+
'yellow' => '33',
|
18
|
+
# default blue is low-contrast against black in some default terminal color scheme
|
19
|
+
'blue' => '94', # 9x = high-intensity fg color x
|
20
|
+
'magenta' => '35',
|
21
|
+
'cyan' => '36',
|
22
|
+
'bold' => '1',
|
23
|
+
'italic' => '3',
|
24
|
+
'underline' => '4',
|
25
|
+
'reset' => '0',
|
26
|
+
|
27
|
+
# semantic
|
28
|
+
'error' => '31', # red
|
29
|
+
'success' => '32', # success
|
30
|
+
'warning' => '33', # yellow
|
31
|
+
'info' => '94', # bright blue
|
32
|
+
'command' => '36', # cyan
|
33
|
+
}.freeze
|
34
|
+
|
35
|
+
BEGIN_EXPR = '{{'
|
36
|
+
END_EXPR = '}}'
|
37
|
+
|
38
|
+
SCAN_FUNCNAME = /\w+:/
|
39
|
+
SCAN_GLYPH = /.}}/
|
40
|
+
SCAN_BODY = /
|
41
|
+
.*?
|
42
|
+
(
|
43
|
+
#{BEGIN_EXPR} |
|
44
|
+
#{END_EXPR} |
|
45
|
+
\z
|
46
|
+
)
|
47
|
+
/mx
|
48
|
+
|
49
|
+
DISCARD_BRACES = 0..-3
|
50
|
+
|
51
|
+
LITERAL_BRACES = :__literal_braces__
|
52
|
+
|
53
|
+
class FormatError < StandardError
|
54
|
+
attr_accessor :input, :index
|
55
|
+
|
56
|
+
def initialize(message = nil, input = nil, index = nil)
|
57
|
+
super(message)
|
58
|
+
@input = input
|
59
|
+
@index = index
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Initialize a formatter with text.
|
64
|
+
#
|
65
|
+
# ===== Attributes
|
66
|
+
#
|
67
|
+
# * +text+ - the text to format
|
68
|
+
#
|
69
|
+
def initialize(text)
|
70
|
+
@text = text
|
71
|
+
end
|
72
|
+
|
73
|
+
# Format the text using a map.
|
74
|
+
#
|
75
|
+
# ===== Attributes
|
76
|
+
#
|
77
|
+
# * +sgr_map+ - the mapping of the formattings. Defaults to +SGR_MAP+
|
78
|
+
#
|
79
|
+
# ===== Options
|
80
|
+
#
|
81
|
+
# * +:enable_color+ - enable color output? Default is true
|
82
|
+
#
|
83
|
+
def format(sgr_map = SGR_MAP, enable_color: true)
|
84
|
+
@nodes = []
|
85
|
+
stack = parse_body(StringScanner.new(@text))
|
86
|
+
prev_fmt = nil
|
87
|
+
content = @nodes.each_with_object(+'') do |(text, fmt), str|
|
88
|
+
if prev_fmt != fmt && enable_color
|
89
|
+
text = apply_format(text, fmt, sgr_map)
|
90
|
+
end
|
91
|
+
str << text
|
92
|
+
prev_fmt = fmt
|
93
|
+
end
|
94
|
+
|
95
|
+
stack.reject! { |e| e == LITERAL_BRACES }
|
96
|
+
|
97
|
+
return content unless enable_color
|
98
|
+
return content if stack == prev_fmt
|
99
|
+
|
100
|
+
unless stack.empty? && (@nodes.size.zero? || @nodes.last[1].empty?)
|
101
|
+
content << apply_format('', stack, sgr_map)
|
102
|
+
end
|
103
|
+
content
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def apply_format(text, fmt, sgr_map)
|
109
|
+
sgr = fmt.each_with_object(+'0') do |name, str|
|
110
|
+
next if name == LITERAL_BRACES
|
111
|
+
begin
|
112
|
+
str << ';' << sgr_map.fetch(name)
|
113
|
+
rescue KeyError
|
114
|
+
raise FormatError.new(
|
115
|
+
"invalid format specifier: #{name}",
|
116
|
+
@text,
|
117
|
+
-1
|
118
|
+
)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
"\x1b[#{sgr.to_s}m" + text
|
122
|
+
end
|
123
|
+
|
124
|
+
def parse_expr(sc, stack)
|
125
|
+
if match = sc.scan(SCAN_GLYPH)
|
126
|
+
glyph_handle = match[0]
|
127
|
+
begin
|
128
|
+
glyph = Glyph.lookup(glyph_handle)
|
129
|
+
emit(glyph.char, [glyph.color.name.to_s])
|
130
|
+
rescue Glyph::InvalidGlyphHandle
|
131
|
+
index = sc.pos - 2 # rewind past '}}'
|
132
|
+
raise FormatError.new(
|
133
|
+
"invalid glyph handle at index #{index}: '#{glyph_handle}'",
|
134
|
+
@text,
|
135
|
+
index
|
136
|
+
)
|
137
|
+
end
|
138
|
+
elsif match = sc.scan(SCAN_FUNCNAME)
|
139
|
+
funcname = match.chop
|
140
|
+
stack.push(funcname)
|
141
|
+
else
|
142
|
+
# We read a {{ but it's not apparently Formatter syntax.
|
143
|
+
# We could error, but it's nicer to just pass through as text.
|
144
|
+
# We do kind of assume that the text will probably have balanced
|
145
|
+
# pairs of {{ }} at least.
|
146
|
+
emit('{{', stack)
|
147
|
+
stack.push(LITERAL_BRACES)
|
148
|
+
end
|
149
|
+
parse_body(sc, stack)
|
150
|
+
stack
|
151
|
+
end
|
152
|
+
|
153
|
+
def parse_body(sc, stack = [])
|
154
|
+
match = sc.scan(SCAN_BODY)
|
155
|
+
if match && match.end_with?(BEGIN_EXPR)
|
156
|
+
emit(match[DISCARD_BRACES], stack)
|
157
|
+
parse_expr(sc, stack)
|
158
|
+
elsif match && match.end_with?(END_EXPR)
|
159
|
+
emit(match[DISCARD_BRACES], stack)
|
160
|
+
if stack.pop == LITERAL_BRACES
|
161
|
+
emit('}}', stack)
|
162
|
+
end
|
163
|
+
parse_body(sc, stack)
|
164
|
+
elsif match
|
165
|
+
emit(match, stack)
|
166
|
+
else
|
167
|
+
emit(sc.rest, stack)
|
168
|
+
end
|
169
|
+
stack
|
170
|
+
end
|
171
|
+
|
172
|
+
def emit(text, stack)
|
173
|
+
return if text.nil? || text.empty?
|
174
|
+
@nodes << [text, stack.reject { |n| n == LITERAL_BRACES }]
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
-
|
2
|
+
versions: all
|
3
|
+
matching:
|
4
|
+
- "ld: library not found for -lgmp"
|
5
|
+
message: |
|
6
|
+
You need to install developer tools for your system.
|
7
|
+
|
8
|
+
One of the following commands may help:
|
9
|
+
|
10
|
+
Ubuntu:
|
11
|
+
- `apt-get install build-essential`
|
12
|
+
- `apt-get install libgmp-dev`
|
13
|
+
|
14
|
+
Mac:
|
15
|
+
- `xcode-select --install`
|
16
|
+
- `brew uninstall gmp` and `brew install gmp`
|
@@ -0,0 +1,18 @@
|
|
1
|
+
-
|
2
|
+
versions:
|
3
|
+
min: "0"
|
4
|
+
matching:
|
5
|
+
- Can't install RMagick [\d\.]+. Can't find MagickWand.h.
|
6
|
+
- No package 'MagickCore' found
|
7
|
+
message: |
|
8
|
+
{{bold:What is the problem?}}
|
9
|
+
The issue is {{underline:likely that the version of Imagemagick on your computer is incompatible.}}
|
10
|
+
|
11
|
+
{{bold:Compatible versions of Imagemagick}}
|
12
|
+
- {{underline:ImageMagick 6.9.9-40}} and lower
|
13
|
+
|
14
|
+
{{bold:What can I do?}}
|
15
|
+
One of the following steps may help:
|
16
|
+
- install a compatible Imagemagick
|
17
|
+
- upgrade RMagick
|
18
|
+
- use a different gem (like mini_magick)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
-
|
2
|
+
versions: all
|
3
|
+
matching:
|
4
|
+
- "ld: library not found for -lgmp"
|
5
|
+
message: |
|
6
|
+
{{bold:What is the problem?}}
|
7
|
+
You need to install developer tools for your system.
|
8
|
+
|
9
|
+
{{bold:What can I do?}}
|
10
|
+
One of the following commands may help:
|
11
|
+
|
12
|
+
{{italic:Ubuntu:}}
|
13
|
+
- {{command:apt-get install build-essential}}
|
14
|
+
- {{command:apt-get install libgmp-dev}}
|
15
|
+
|
16
|
+
{{italic:Mac:}}
|
17
|
+
- {{command:xcode-select --install}}
|
18
|
+
- {{command:brew uninstall gmp}} and {{command:brew install gmp}}
|
data/plugins.rb
ADDED
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: extended_bundler-errors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jules2689
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: Extended Errors for Bundler
|
56
|
+
email:
|
57
|
+
- julian@jnadeau.ca
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- CODE_OF_CONDUCT.md
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- extended_bundler-errors.gemspec
|
73
|
+
- lib/extended_bundler/backports.rb
|
74
|
+
- lib/extended_bundler/errors.rb
|
75
|
+
- lib/extended_bundler/errors/formatter.rb
|
76
|
+
- lib/extended_bundler/errors/version.rb
|
77
|
+
- lib/extended_bundler/handlers/http_parser.yml
|
78
|
+
- lib/extended_bundler/handlers/rmagick.yml
|
79
|
+
- lib/extended_bundler/handlers/testing_stuff.yml
|
80
|
+
- lib/extended_bundler/handlers/testing_stuff_2.yml
|
81
|
+
- lib/extended_bundler/handlers/unf_ext.yml
|
82
|
+
- plugins.rb
|
83
|
+
homepage: http://github.com/shopify/extended_bundler-errors
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata:
|
87
|
+
allowed_push_host: https://rubygems.org
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.7.6
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Extended Errors for Bundler
|
108
|
+
test_files: []
|