Exception: Textus::UnknownKey

Inherits:
Error
  • Object
show all
Defined in:
lib/textus/errors.rb

Instance Attribute Summary collapse

Attributes inherited from Error

#code, #details, #exit_code, #hint

Instance Method Summary collapse

Methods inherited from Error

#to_envelope

Constructor Details

#initialize(key, suggestions: []) ⇒ UnknownKey

Returns a new instance of UnknownKey.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/textus/errors.rb', line 29

def initialize(key, suggestions: [])
  @suggestions = Array(suggestions)
  details = { "key" => key }
  details["suggestions"] = @suggestions unless @suggestions.empty?
  msg = "key '#{key}' does not resolve"
  msg += "; did you mean: #{@suggestions.join(", ")}" unless @suggestions.empty?
  hint =
    if @suggestions.empty?
      "run 'textus list --format=json' to see all keys"
    else
      "did you mean: #{@suggestions.join(", ")}"
    end
  super("unknown_key", msg, details: details, hint: hint)
end

Instance Attribute Details

#suggestionsObject (readonly)

Returns the value of attribute suggestions.



27
28
29
# File 'lib/textus/errors.rb', line 27

def suggestions
  @suggestions
end