Adds new exception messages and custom exception handling

This commit is contained in:
Lord Hepipud 2020-05-19 17:29:42 +02:00
parent 2b740785fe
commit 7860818be1
2 changed files with 25 additions and 11 deletions

View file

@ -5,7 +5,7 @@ function Exit-IcingaThrowException()
[string]$StringPattern,
[string]$CustomMessage,
[string]$ExceptionThrown,
[ValidateSet('Permission','Input','Unhandled')]
[ValidateSet('Permission','Input','Configuration','Unhandled','Custom')]
[string]$ExceptionType = 'Unhandled',
[switch]$Force
);
@ -32,9 +32,16 @@ function Exit-IcingaThrowException()
$ExceptionTypeString = 'Invalid Input';
$ExceptionMessageLib = $IcingaExceptions.Inputs;
};
'Configuration' {
$ExceptionTypeString = 'Invalid Configuration';
$ExceptionMessageLib = $IcingaExceptions.Configuration;
};
'Unhandled' {
$ExceptionTypeString = 'Unhandled';
};
'Custom' {
$ExceptionTypeString = 'Custom';
};
}
[string]$ExceptionName = '';
@ -47,9 +54,10 @@ function Exit-IcingaThrowException()
}
}
} else {
$ExceptionName = 'Unhandled Exception';
$ExceptionName = [string]::Format('{0} Exception', $ExceptionTypeString);
$ExceptionThrown = [string]::Format(
'Unhandled exception occured:{0}{1}',
'{0} exception occured:{1}{2}',
$ExceptionTypeString,
"`r`n",
$InputString
);

View file

@ -16,6 +16,11 @@
ConversionUnitMissing = 'Unable to parse input value. You have to add an unit to your input value. Example: "10GB". Allowed units are: "B, KB, MB, GB, TB, PB, KiB, MiB, GiB, TiB, PiB".';
};
[hashtable]$Configuration = @{
PluginArgumentConflict = 'Your plugin argument configuration is causing a conflict. Mostly this error is caused by missmatching configurations by enabling multiple switch arguments which are resulting in a conflicting configuration for the plugin.';
PluginArgumentmissing = 'Your plugin argument configuration is missing mandatory arguments. This is error is caused when mandatory or required arguments are missing from a plugin call and the operation is unable to process without them.';
}
<#
# Once we defined a new enum hashtable above, simply add it to this list
# to make it available within the entire module.
@ -26,6 +31,7 @@
[hashtable]$IcingaExceptions = @{
Permission = $Permission;
Inputs = $Inputs;
Configuration = $Configuration;
}
Export-ModuleMember -Variable @( 'IcingaExceptions' );