Sha256: 63bb580430d69041cce64e3f1f2110b67b3e79320f68e6b742b4af99a7faffe6

Contents?: true

Size: 1.37 KB

Versions: 13

Compression:

Stored size: 1.37 KB

Contents

class Terraspace::Shell
  class Error
    attr_accessor :lines
    def initialize
      @lines = '' # holds aggregation of all error lines
    end

    def known?
      !!instance
    end

    def instance
      if reinit_required?
        Terraspace::InitRequiredError.new(@lines)
      elsif bucket_not_found?
        Terraspace::BucketNotFound.new(@lines)
      elsif shared_cache_error?
        Terraspace::SharedCacheError.new(@lines)
      end
    end

    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

    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

    def message
      @lines.gsub("\n", ' ').squeeze(' ') # remove double whitespaces and newlines
    end

    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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
terraspace-0.5.11 lib/terraspace/shell/error.rb
terraspace-0.5.10 lib/terraspace/shell/error.rb
terraspace-0.5.9 lib/terraspace/shell/error.rb
terraspace-0.5.8 lib/terraspace/shell/error.rb
terraspace-0.5.7 lib/terraspace/shell/error.rb
terraspace-0.5.6 lib/terraspace/shell/error.rb
terraspace-0.5.5 lib/terraspace/shell/error.rb
terraspace-0.5.4 lib/terraspace/shell/error.rb
terraspace-0.5.3 lib/terraspace/shell/error.rb
terraspace-0.5.2 lib/terraspace/shell/error.rb
terraspace-0.5.1 lib/terraspace/shell/error.rb
terraspace-0.5.0 lib/terraspace/shell/error.rb
terraspace-0.4.4 lib/terraspace/shell/error.rb