Skip to content

Commit 7ed2118

Browse files
authored
Merge pull request #647 from Icinga:fix/improve_exception_and_error_handling
Feature: Improves error/exception handling
2 parents 87a9d12 + 438bd86 commit 7ed2118

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/icinga/exception/Exit-IcingaThrowCritical.psm1

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ function Exit-IcingaThrowCritical()
2525
Set-IcingaInternalPluginExitCode -ExitCode $IcingaEnums.IcingaExitCode.Critical;
2626
Set-IcingaInternalPluginException -PluginException $OutputMessage;
2727

28-
if ($Global:Icinga.Protected.RunAsDaemon -eq $FALSE -And $Global:Icinga.Protected.JEAContext -eq $FALSE) {
29-
Write-IcingaConsolePlain $OutputMessage;
30-
exit $IcingaEnums.IcingaExitCode.Critical;
28+
if ($Global:Icinga.Protected.RunAsDaemon -eq $TRUE -Or $Global:Icinga.Protected.JEAContext -eq $TRUE) {
29+
throw $OutputMessage;
30+
31+
# Just in case we don't end - shouldn't happen anyway
32+
return;
3133
}
34+
35+
Write-IcingaConsolePlain $OutputMessage;
36+
exit $IcingaEnums.IcingaExitCode.Critical;
3237
}

lib/icinga/exception/Exit-IcingaThrowException.psm1

+7-4
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,13 @@ function Exit-IcingaThrowException()
110110
Set-IcingaInternalPluginExitCode -ExitCode $IcingaEnums.IcingaExitCode.Unknown;
111111
Set-IcingaInternalPluginException -PluginException $OutputMessage;
112112

113-
if ($Global:Icinga.Protected.RunAsDaemon -eq $FALSE -And $Global:Icinga.Protected.JEAContext -eq $FALSE) {
114-
Write-IcingaConsolePlain $OutputMessage;
115-
exit $IcingaEnums.IcingaExitCode.Unknown;
116-
} else {
113+
if ($Global:Icinga.Protected.RunAsDaemon -eq $TRUE -Or $Global:Icinga.Protected.JEAContext -eq $TRUE) {
117114
throw $OutputMessage;
115+
116+
# Just in case we don't end - shouldn't happen anyway
117+
return;
118118
}
119+
120+
Write-IcingaConsolePlain $OutputMessage;
121+
exit $IcingaEnums.IcingaExitCode.Unknown;
119122
}

0 commit comments

Comments
 (0)