Exception: FormulaOrCaskUnavailableError

Inherits:
RuntimeError
  • Object
show all
Defined in:
exceptions.rb

Overview

Raised when neither a formula nor a cask with the given name is available.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ FormulaOrCaskUnavailableError

Returns a new instance of FormulaOrCaskUnavailableError.



86
87
88
89
90
91
92
93
94
95
96
# File 'exceptions.rb', line 86

def initialize(name)
  super()

  @name = name

  # Store the state of these envs at the time the exception is thrown.
  # This is so we do the fuzzy search for "did you mean" etc under that same mode,
  # in case the list of formulae are different.
  @without_api = Homebrew::EnvConfig.no_install_from_api?
  @auto_without_api = Homebrew::EnvConfig.automatically_set_no_install_from_api?
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



84
85
86
# File 'exceptions.rb', line 84

def name
  @name
end

Instance Method Details

#did_you_meanString

Returns:



99
100
101
102
103
104
105
106
# File 'exceptions.rb', line 99

def did_you_mean
  require "formula"

  similar_formula_names = Homebrew.with_no_api_env_if_needed(@without_api) { Formula.fuzzy_search(name) }
  return "" if similar_formula_names.blank?

  "Did you mean #{similar_formula_names.to_sentence two_words_connector: " or ", last_word_connector: " or "}?"
end

#to_sString

Returns:



109
110
111
112
113
114
115
# File 'exceptions.rb', line 109

def to_s
  s = "No available formula or cask with the name \"#{name}\". #{did_you_mean}".strip
  if @auto_without_api && !CoreTap.instance.installed?
    s += "\nA full git tap clone is required to use this command on core packages."
  end
  s
end