def chef_error(e)
      if e.is_a?(::RightScale::Exceptions::Exec)
        msg = "External command error: "
        if match = /RightScale::Exceptions::Exec: (.*)/.match(e.message)
          cmd_output = match[1]
        else
          cmd_output = e.message
        end
        msg += cmd_output
        msg += "\nThe command was run from \"#{e.path}\"" if e.path
      elsif e.is_a?(::Chef::Exceptions::ValidationFailed) && (e.message =~ /Option action must be equal to one of:/)
        msg = "[chef] recipe references an action that does not exist.  #{e.message}"
      elsif e.is_a?(::NoMethodError) && (missing_action_match = /undefined method .action_(\S*)' for #<\S*:\S*>/.match(e.message)) && missing_action_match[1]
        msg = "[chef] recipe references the action <#{missing_action_match[1]}> which is missing an implementation"
      else
        msg              = "Execution error:\n"
        msg              += e.message
        file, line, meth = e.backtrace[0].scan(BACKTRACE_LINE_REGEXP).flatten
        line_number      = line.to_i
        if file && line && (line_number.to_s == line)
          dir = AgentConfig.cookbook_download_dir
          if file[0..dir.size - 1] == dir
            path = "[COOKBOOKS]/" + file[dir.size..file.size]
          else
            path = file
          end
          msg += "\n\nThe error occurred line #{line} of #{path}"
          msg += " in method '#{meth}'" if meth
          context = ""
          if File.readable?(file)
            File.open(file, 'r') do |f|
              lines       = f.readlines
              lines_count = lines.size
              if lines_count >= line_number
                upper   = [lines_count, line_number + 2].max
                padding = upper.to_s.size
                context += context_line(lines, line_number - 2, padding)
                context += context_line(lines, line_number - 1, padding)
                context += context_line(lines, line_number, padding, '*')
                context += context_line(lines, line_number + 1, padding)
                context += context_line(lines, line_number + 2, padding)
              end
            end
          end
          msg += " while executing:\n\n#{context}" unless context.empty?
        end
      end
      msg
    end
def chef_error(e)
      if e.is_a?(::RightScale::Exceptions::Exec)
        msg = "External command error: "
        if match = /RightScale::Exceptions::Exec: (.*)/.match(e.message)
          cmd_output = match[1]
        else
          cmd_output = e.message
        end
        msg += cmd_output
        msg += "\nThe command was run from \"#{e.path}\"" if e.path
      elsif e.is_a?(::Chef::Exceptions::ValidationFailed) && (e.message =~ /Option action must be equal to one of:/)
        msg = "[chef] recipe references an action that does not exist.  #{e.message}"
      elsif e.is_a?(::NoMethodError) && (missing_action_match = /undefined method .action_(\S*)' for #<\S*:\S*>/.match(e.message)) && missing_action_match[1]
        msg = "[chef] recipe references the action <#{missing_action_match[1]}> which is missing an implementation"
      else
        msg              = "Execution error:\n"
        msg              += e.message
        file, line, meth = e.backtrace[0].scan(BACKTRACE_LINE_REGEXP).flatten
        line_number      = line.to_i
        if file && line && (line_number.to_s == line)
          dir = AgentConfig.cookbook_download_dir
          if file[0..dir.size - 1] == dir
            path = "[COOKBOOKS]/" + file[dir.size..file.size]
          else
            path = file
          end
          msg += "\n\nThe error occurred line #{line} of #{path}"
          msg += " in method '#{meth}'" if meth
          context = ""
          if File.readable?(file)
            File.open(file, 'r') do |f|
              lines       = f.readlines
              lines_count = lines.size
              if lines_count >= line_number
                upper   = [lines_count, line_number + 2].max
                padding = upper.to_s.size
                context += context_line(lines, line_number - 2, padding)
                context += context_line(lines, line_number - 1, padding)
                context += context_line(lines, line_number, padding, '*')
                context += context_line(lines, line_number + 1, padding)
                context += context_line(lines, line_number + 2, padding)
              end
            end
          end
          msg += " while executing:\n\n#{context}" unless context.empty?
        end
      end
      msg
    end
Wrap chef exception with explanatory information and show
 context of failure

 === Parameters
 e(Exception):: Exception raised while executing Chef recipe

 === Return
 msg(String):: Human friendly error message