Error Management (Agreements)
Agreement Accelerator comes with build-in Warning Manager, which takes care of proper calculation flow. In case an error occurs, Warning Manager intercepts it and handles it in a warning specific way. All caught warnings (if configured to do so) are then displayed in a matrix.
All engines, including custom ones, should handle errors using api.throwException
calls with direct text, such as: api.throwException("No Historical Cost data found for SKU: $sku, Period name: $periodName")
; the Warning Manager is not intended for these cases.
Technical Information
Warning Manager overrides standard behavior in case any exception is thrown. Instead of showing an alert to the user with technical message, it captures the exception and selects a corresponding message from configuration (see Configuration section).
To achieve this, Warning Manager has a method called tryToExecuteElement, which takes code we want to run as a closure parameter and then runs it in a try/catch block. Sample method call:
return out.WarningManager.tryToExecuteElement("FormulaData") {
Map generatedInputs = out.InputsGeneration
String formulaCfoUniqueName = libs.AGR_ProcessingLib.InputUtils.getFormulaCfo(generatedInputs)
if (!formulaCfoUniqueName) {
api.throwException("MISSING_FORMULA_DATA")
}
String formulaObjectTypeName = libs.AGR_FormulaLib.FormulaProcessingUtils.getFormulasObjectTypeName(formulaCfoUniqueName)
String formulaTypeName = libs.AGR_FormulaLib.FormulaProcessingUtils.getFormulaTypeName(formulaCfoUniqueName, formulaObjectTypeName)
Map formulaType = libs.AGR_FormulaLib.FormulaProcessingUtils.findFormulaType(formulaTypeName, formulaObjectTypeName)
String engineCalculatorParameterName = libs.AGR_FormulaLib.FormulaProcessingUtils.getEngineParameterName(formulaObjectTypeName)
Map formulaInputValues = libs.AGR_FormulaLib.FormulaProcessingUtils.getFormulaInputValues(formulaCfoUniqueName, formulaType, formulaObjectTypeName)
return [formula : formulaType,
formulaTypeName : formulaTypeName,
engineCalculatorParameterName: engineCalculatorParameterName,
formulaInputValues : formulaInputValues]
}
tryToExecuteElement method code:
tryToExecuteElement : { String elementName, def fallbackOnError = null, Closure elementCode ->
try {
return elementCode()
} catch (any) {
manager.handleThrownException(elementName, any)
}
return fallbackOnError
},
As you can see, the exception thrown in line 7 (first code snippet), will be caught in Warning Manager’s internal try/catch block.
To determine error-specific behavior, we use uniform exception message format: EXCEPTION_CODE::ALERT_MESSAGE. EXCEPTION_CODE serves as a lookup key in Warning Manager configuration, ::ALERT_MESSAGE is optional, mostly used when you want to include a variable value in ALERT_MESSAGE string.
Alert Types
Warning Manager uses standard Unity alerts to notify the user. You can read about them in detail here.
Configuration
To set up Warning Manager, it is enough to configure one price parameter called AGR_WarningManager.
Except for the warning message, you can also define a type of alert you want to show, whether it should be visible in the summary matrix, and if it should abort all further calculation or not. There is also a possibility to add solution suggestions and origin of the warning, e.g. database issue, configuration issue etc. You can find a thorough description of columns' purpose in the table below.
Column name | Value | Required ( Yes/No) |
---|---|---|
Exception Code | text, defines exception code used when throwing an exception | Yes |
Alert Message | text, message shown in alert displayed to the user | No |
Solution | text, possible solution of the problem | No |
Origin | text, type of the problem’s origin | No |
Display in Matrix | true/false | Yes |
Alert Type | Critical/Red/Yellow/Warning/None | Yes |
Aborts Calculation | true/false | Yes |
Â