Class: Terraspace::Shell::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/terraspace/shell/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeError

Returns a new instance of Error.



4
5
6
# File 'lib/terraspace/shell/error.rb', line 4

def initialize
  @lines = [] # holds aggregation of all error lines
end

Instance Attribute Details

#linesObject

Returns the value of attribute lines.



3
4
5
# File 'lib/terraspace/shell/error.rb', line 3

def lines
  @lines
end

Instance Method Details

#bucket_not_found?Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/terraspace/shell/error.rb', line 24

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

#instanceObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/terraspace/shell/error.rb', line 12

def instance
  if reinit_required?
    Terraspace::InitRequiredError.new(message)
  elsif bucket_not_found?
    Terraspace::BucketNotFoundError.new(message)
  elsif shared_cache_error?
    Terraspace::SharedCacheError.new(message)
  elsif state_lock_error?
    Terraspace::StateLockError.new(message)
  end
end

#known?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/terraspace/shell/error.rb', line 8

def known?
  !!instance
end

#messageObject



38
39
40
41
# File 'lib/terraspace/shell/error.rb', line 38

def message
  # For error messages, terraform lines from buffer do not contain newlines. So join with newline
  @lines.map { |l| l.force_encoding('UTF-8') }.join("\n")
end

#reinit_required?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
# File 'lib/terraspace/shell/error.rb', line 29

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?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/terraspace/shell/error.rb', line 43

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

#state_lock_error?Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/terraspace/shell/error.rb', line 49

def state_lock_error?
  # Example: https://gist.github.com/tongueroo/6bcb86f88053c58fa50f434789268b78
  message.include?("Error acquiring the state lock")
end