Sha256: 347d089349e3781cf0115831f6a5e0f2d4c15f1af3d414345c6fdf53e8055788

Contents?: true

Size: 1021 Bytes

Versions: 4

Compression:

Stored size: 1021 Bytes

Contents

# frozen_string_literal: true

require 'puppet-debugger/input_responder_plugin'
module PuppetDebugger
  module InputResponders
    class Stacktrace < InputResponderPlugin
      COMMAND_WORDS = %w[stacktrace].freeze
      SUMMARY = 'Show the stacktrace for how we got here'
      COMMAND_GROUP = :tools

      # @return [Array]- returns a array of pp files that are involved in the stacktrace
      def run(_args = [])
        s = stacktrace
        s.empty? ? 'stacktrace not available'.warning : s.ai
      end

      # @return [Array] - an array of files with line numbers
      # @example
      # [
      #   "/nwops/puppetlabs-peadm/spec/fixtures/modules/peadm/plans/status.pp:23",
      #   "/nwops/puppetlabs-peadm/spec/fixtures/modules/peadm/plans/status.pp:20"
      # ]
      def stacktrace
        stack = Puppet::Pops::PuppetStack.stacktrace.find_all { |line| !line.include?('unknown') }
        stack.each_with_object([]) do |item, acc|
          acc << item.join(':')
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
puppet-debugger-1.4.0 lib/plugins/puppet-debugger/input_responders/stacktrace.rb
puppet-debugger-1.3.0 lib/plugins/puppet-debugger/input_responders/stacktrace.rb
puppet-debugger-1.2.0 lib/plugins/puppet-debugger/input_responders/stacktrace.rb
puppet-debugger-1.1.0 lib/plugins/puppet-debugger/input_responders/stacktrace.rb