Detectable Macro Errors
Logging Macro Results
Copyright © 2010, Juniper Networks, Inc.
CLI macros detect various errors when a macro is executed. Some of these errors are
detected without the use of an onError macro; they include the following:
Macro file not found
Macro not found
Macro compilation error
Macro does not complete error due to excessive looping or recursion
The following errors are detected only when a CLI macro file contains an onError macro:
Syntactic error in executed CLI command
Runtime error in executed CLI command
In addition to these detectable errors, you can use the following environment commands
to return textual error information to the macroData log file:
env.getErrorCommand
env.getErrorStatus
CAUTION: Though you can use the env.getErrorCommand and
env.getErrorStatus commands in any macro, the only appropriate place
from which to execute these commands is from an onError macro.
You can use the env.setResult command to set parameters within a macro to display
information through the macroData log file. When defined, parameter information appears
in the macroData log file at the NOTICE severity level following the completion of the
macro.
The following example defines several results (1 through 5):
<# numberMacro #>
<# env.setResult("A", " " $1 ) #>
<# env.setResult("A", " " $2 ) #>
<# env.setResult("A", " " $3 ) #>
<# env.setResult("A", " " $4 ) #>
<# env.setResult("A", " " $5 ) #>
<#endtmpl#>
Each value is sent to the macroData log file, starting with 1 and ending with 5. Each
successive value overwrites the previous value in the log file. In other words, if the macro
ends after setting the third result (that is, 3) the log file displays the following:
A is 3
If the macro finishes completely, the log file displays the following:
Chapter 8: Writing CLI Macros
477