Exception: Puppet::ParseErrorWithIssue

Inherits:
ParseError show all
Defined in:
lib/puppet/error.rb

Overview

Contains an issue code and can be annotated with an environment and a node

Direct Known Subclasses

PreformattedError

Instance Attribute Summary collapse

Attributes included from ExternalFileError

#file, #line, #pos, #puppetstack

Attributes inherited from Error

#original

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, file = nil, line = nil, pos = nil, original = nil, issue_code = nil, arguments = nil) ⇒ ParseErrorWithIssue

Returns a new instance of ParseErrorWithIssue.

Parameters:

  • message (String)

    The error message

  • file (String) (defaults to: nil)

    The path to the file where the error was found

  • line (Integer) (defaults to: nil)

    The line in the file

  • pos (Integer) (defaults to: nil)

    The position on the line

  • original (Exception) (defaults to: nil)

    Original exception

  • issue_code (Symbol) (defaults to: nil)

    The issue code

  • arguments (Hash{Symbol=>Object}) (defaults to: nil)

    Issue arguments



71
72
73
74
75
76
# File 'lib/puppet/error.rb', line 71

def initialize(message, file = nil, line = nil, pos = nil, original = nil, issue_code = nil, arguments = nil)
  super(message, file, line, pos, original)
  @issue_code = issue_code
  @basic_message = message
  @arguments = arguments
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



60
61
62
# File 'lib/puppet/error.rb', line 60

def arguments
  @arguments
end

#basic_messageObject (readonly)

Returns the value of attribute basic_message.



60
61
62
# File 'lib/puppet/error.rb', line 60

def basic_message
  @basic_message
end

#environmentObject

Returns the value of attribute environment.



61
62
63
# File 'lib/puppet/error.rb', line 61

def environment
  @environment
end

#issue_codeObject (readonly)

Returns the value of attribute issue_code.



60
61
62
# File 'lib/puppet/error.rb', line 60

def issue_code
  @issue_code
end

#nodeObject

Returns the value of attribute node.



61
62
63
# File 'lib/puppet/error.rb', line 61

def node
  @node
end

Class Method Details

.from_issue_and_stack(issue, args = {}) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/puppet/error.rb', line 98

def self.from_issue_and_stack(issue, args = {})
  filename, line = Puppet::Pops::PuppetStack.top_of_stack

  new(
    issue.format(args),
    filename,
    line,
    nil,
    nil,
    issue.issue_code,
    args
  )
end

Instance Method Details

#to_hObject



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/puppet/error.rb', line 85

def to_h
  {
    :issue_code => issue_code,
    :message => basic_message,
    :full_message => to_s,
    :file => file,
    :line => line,
    :pos => pos,
    :environment => environment.to_s,
    :node => node.to_s,
  }
end

#to_sObject



78
79
80
81
82
83
# File 'lib/puppet/error.rb', line 78

def to_s
  msg = super
  msg = _("Could not parse for environment %{environment}: %{message}") % { environment: environment, message: msg } if environment
  msg = _("%{message} on node %{node}") % { message: msg, node: node } if node
  msg
end