In this example, the following macro file (badMacroInvocation.mac) is programmed to invoke a missing or nonexistent macro (tmpl.foo).
- <# badMacroInvocation #>
- <# env.setResult("runStatus","start" ) #>
- <# tmpl.foo #>
- <# env.setResult("runStatus","complete" ) #>
- <#endtmpl#>
- <# onerror #>
- <# errCmd := env.getErrorCommand #>
- <# errStatus := env.getErrorStatus #>
- <# env.setResult("commandError", errCmd) #>
- <# env.setResult("commandErrorStatus", errStatus) #>
- <#endtmpl#>
When using the onError macro, the macro stops when it encounters the missing macro. The output appears as follows:
host1# macro badMacroInvocation.mac badMacroInvocation Macro 'badMacroInvocation' in file 'badMacroInvocation.mac' starting execution (Id: 407) % can't find macro foo Macro 'badMacroInvocation' in file 'badMacroInvocation.mac' ending execution (Id: 407)
You can determine the execution progress through the runStatus result entry in the macroData log file. For this example, the log output indicates the macro error and displays the following to indicate that the macro ended prior to invoking the macro:
start
host1# show log data category macrodata severity debug NOTICE 05/27/2005 12:39:10 macroData: Macro 'badMacroInvocation' in file 'badMacroInvocation.mac' starting execution (Id: 407) on vty, 0 ERROR 05/27/2005 12:39:10 macroData: (Id: 407) Command error: foo, macro not found NOTICE 05/27/2005 12:39:10 macroData: (Id: 407) commandError is foo NOTICE 05/27/2005 12:39:10 macroData: (Id: 407) commandErrorStatus is macro not found NOTICE 05/27/2005 12:39:10 macroData: (Id: 407) runStatus is start NOTICE 05/27/2005 12:39:10 macroData: Macro 'badMacroInvocation' in file 'badMacroInvocation.mac' ending execution (Id: 407) on vty, 0