class Terraspace::Shell::Error

Attributes

lines[RW]

Public Class Methods

new() click to toggle source
# File lib/terraspace/shell/error.rb, line 4
def initialize
  @lines = '' # holds aggregation of all error lines
end

Public Instance Methods

bucket_not_found?() click to toggle source
# File lib/terraspace/shell/error.rb, line 22
def bucket_not_found?
  # Message is included in aws, azurerm, and google. See: https://bit.ly/3iOKDri
  message.include?("Failed to get existing workspaces")
end
instance() click to toggle source
# File lib/terraspace/shell/error.rb, line 12
def instance
  if reinit_required?
    Terraspace::InitRequiredError.new(@lines)
  elsif bucket_not_found?
    Terraspace::BucketNotFoundError.new(@lines)
  elsif shared_cache_error?
    Terraspace::SharedCacheError.new(@lines)
  end
end
known?() click to toggle source
# File lib/terraspace/shell/error.rb, line 8
def known?
  !!instance
end
message() click to toggle source
# File lib/terraspace/shell/error.rb, line 36
def message
  @lines.gsub("\n", ' ').squeeze(' ') # remove double whitespaces and newlines
end
reinit_required?() click to toggle source
# File lib/terraspace/shell/error.rb, line 27
def reinit_required?
  # Example error: https://gist.github.com/tongueroo/f7e0a44b64f0a2e533089b18f331c21e
  general_check = message.include?("terraform init") && message.include?("Error:")
  general_check ||
  message.include?("reinitialization required") ||
  message.include?("terraform init") ||
  message.include?("require reinitialization")
end
shared_cache_error?() click to toggle source
# File lib/terraspace/shell/error.rb, line 40
def shared_cache_error?
  # Example: https://gist.github.com/tongueroo/4f2c925709d21f5810229ce9ca482560
  message.include?("Failed to install provider from shared cache") ||
  message.include?("Failed to validate installed provider")
end