Is there a way to check if the gosub stack is empty?
The goal is avoid to call Return if the stack is empty because it causes an error on execution:
-- Executing [351@usuarios:4] Return("PJSIP/203-00000010", "") in new stack}}
-- [2019-07-01 11:33:26.972] ERROR[27565][C-00000009]: app_stack.c:389 return_exec: Return without Gosub: stack is unallocated
In my case, the same extension can be called directly or via Gosub from other contexts (for avoiding duplication), the problem is when the call is directly placed because the stack is empty and I will get an error.
Replacing the calls with Goto is not possible because I need to continue the dialplan execution when calling from other contexts.
I saw the StackPop application but it doesn’t fit the needs because remove elements from stack.
I could control with custom variables but I was looking for a more elegant way.
But that error doesn’t block call flow, and in Asterisk 16 the third option to STACK_PEEK function is a boolean that lets you suppress these sorts of errors.
Anyhow, the result of STACK_PEEK is non-empty when in Gosub vs. empty string when not in Gosub. So I think this might be all you need in the Gosub – no custom variables:
I already tried by this way with your first comment. I tried it in asterisk v16 with suppress warning set on STACK_PEEK function, the exact command you posted in this comment but it generates a error when the stack is empty.
I tried it again making a copy paste of your command to assure that I didn’t missed anything and now I have the same error:
[2019-07-08 13:19:04.085] ERROR[2627][C-00000004]: app_stack.c:855 stackpeek_read: STACK_PEEK must be called with a positive peek value
The error doesn’t block the call flow, but if your call is from a trunk… this error makes the ${DIALSTATUS} in the other party will be: CHANUNAVAIL