mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Adds new exception messages and custom exception handling
This commit is contained in:
parent
2b740785fe
commit
7860818be1
2 changed files with 25 additions and 11 deletions
|
|
@ -5,7 +5,7 @@ function Exit-IcingaThrowException()
|
||||||
[string]$StringPattern,
|
[string]$StringPattern,
|
||||||
[string]$CustomMessage,
|
[string]$CustomMessage,
|
||||||
[string]$ExceptionThrown,
|
[string]$ExceptionThrown,
|
||||||
[ValidateSet('Permission','Input','Unhandled')]
|
[ValidateSet('Permission','Input','Configuration','Unhandled','Custom')]
|
||||||
[string]$ExceptionType = 'Unhandled',
|
[string]$ExceptionType = 'Unhandled',
|
||||||
[switch]$Force
|
[switch]$Force
|
||||||
);
|
);
|
||||||
|
|
@ -32,9 +32,16 @@ function Exit-IcingaThrowException()
|
||||||
$ExceptionTypeString = 'Invalid Input';
|
$ExceptionTypeString = 'Invalid Input';
|
||||||
$ExceptionMessageLib = $IcingaExceptions.Inputs;
|
$ExceptionMessageLib = $IcingaExceptions.Inputs;
|
||||||
};
|
};
|
||||||
|
'Configuration' {
|
||||||
|
$ExceptionTypeString = 'Invalid Configuration';
|
||||||
|
$ExceptionMessageLib = $IcingaExceptions.Configuration;
|
||||||
|
};
|
||||||
'Unhandled' {
|
'Unhandled' {
|
||||||
$ExceptionTypeString = 'Unhandled';
|
$ExceptionTypeString = 'Unhandled';
|
||||||
};
|
};
|
||||||
|
'Custom' {
|
||||||
|
$ExceptionTypeString = 'Custom';
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[string]$ExceptionName = '';
|
[string]$ExceptionName = '';
|
||||||
|
|
@ -47,9 +54,10 @@ function Exit-IcingaThrowException()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$ExceptionName = 'Unhandled Exception';
|
$ExceptionName = [string]::Format('{0} Exception', $ExceptionTypeString);
|
||||||
$ExceptionThrown = [string]::Format(
|
$ExceptionThrown = [string]::Format(
|
||||||
'Unhandled exception occured:{0}{1}',
|
'{0} exception occured:{1}{2}',
|
||||||
|
$ExceptionTypeString,
|
||||||
"`r`n",
|
"`r`n",
|
||||||
$InputString
|
$InputString
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -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".';
|
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
|
# Once we defined a new enum hashtable above, simply add it to this list
|
||||||
# to make it available within the entire module.
|
# to make it available within the entire module.
|
||||||
|
|
@ -26,6 +31,7 @@
|
||||||
[hashtable]$IcingaExceptions = @{
|
[hashtable]$IcingaExceptions = @{
|
||||||
Permission = $Permission;
|
Permission = $Permission;
|
||||||
Inputs = $Inputs;
|
Inputs = $Inputs;
|
||||||
|
Configuration = $Configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
Export-ModuleMember -Variable @( 'IcingaExceptions' );
|
Export-ModuleMember -Variable @( 'IcingaExceptions' );
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue