11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/puppet/pops/issue_reporter.rb', line 11
def self.assert_and_report(acceptor, options)
return unless acceptor
max_errors = Puppet[:max_errors]
max_warnings = Puppet[:max_warnings]
max_deprecations =
if Puppet[:disable_warnings].include?('deprecations')
0
else
Puppet[:max_deprecations]
end
emit_warnings = options[:emit_warnings] || false
emit_errors = options[:emit_errors].nil? ? true : !!options[:emit_errors]
emit_message = options[:message]
emit_exception = options[:exception_class] || Puppet::ParseError
warnings = acceptor.warnings
if emit_warnings && warnings.size > 0
formatter = Puppet::Pops::Validation::DiagnosticFormatterPuppetStyle.new
emitted_w = 0
emitted_dw = 0
acceptor.warnings.each do |w|
if w.severity == :deprecation
Puppet.warning(formatter.format(w)) if emitted_dw < max_deprecations
emitted_dw += 1
else
Puppet.warning(formatter.format(w)) if emitted_w < max_warnings
emitted_w += 1
end
break if emitted_w >= max_warnings && emitted_dw >= max_deprecations end
end
errors = acceptor.errors
if errors.size > 0
unless emit_errors
raise emit_exception.new(emit_message)
end
formatter = Puppet::Pops::Validation::DiagnosticFormatterPuppetStyle.new
if errors.size == 1 || max_errors <= 1
exception = emit_exception.new(format_with_prefix(emit_message, formatter.format(errors[0])))
if errors[0].exception
exception.set_backtrace(errors[0].exception.backtrace)
end
raise exception
end
emitted = 0
if emit_message
Puppet.err(emit_message)
end
errors.each do |e|
Puppet.err(formatter.format(e))
emitted += 1
break if emitted >= max_errors
end
warnings_message = (emit_warnings && warnings.size > 0) ? ", and #{warnings.size} warnings" : ""
giving_up_message = "Found #{errors.size} errors#{warnings_message}. Giving up"
exception = emit_exception.new(giving_up_message)
exception.file = errors[0].file
raise exception
end
end
|