Gosub()

"Gosub attempted to reach non-existent destination" in Asterisk

Gosub failures are more confusing than Goto failures because the Gosub is often one you did not write. Dial() and Queue() call subroutines implicitly, and when those targets are missing the error names a destination you have never typed.

What it looks like in the log

[2026-08-17 14:22:09] ERROR[16601][C-00001d40] app_stack.c: Gosub attempted to reach non-existent destination 'macro-answer,s-ANSWER,1'

What it means

Gosub() is a call to a dialplan subroutine that returns when it hits Return(). Like Goto, it needs a context, extension and priority that all exist. Unlike Goto, it is frequently invoked on your behalf.

The U() option on Dial() runs a subroutine when the call is answered. The b() option runs one before the outbound leg is created. Queue() has equivalents. Each of them builds a target name from the option you supplied plus a suffix Asterisk chooses - which is where s-ANSWER comes from, and why searching your dialplan for that string finds nothing.

Most common causes

  1. 01A macro or subroutine that was renamed or removed

    The most common cause. The context named in the U() or b() option no longer exists under that name.

  2. 02The s-ANSWER pattern from Dial()'s U() option

    Dial() appends the status to the subroutine name. If the target context does not define an s-ANSWER extension, the answer handler fails even though the context itself exists.

  3. 03A migration from Macro() to Gosub()

    Converting old macro-based dialplans leaves references in one style pointing at contexts defined in the other. The names are close enough to look correct.

  4. 04A missing priority rather than a missing extension

    The target extension exists but not at priority 1, which the error reports identically.

  5. 05A subroutine in a file that is no longer included

    Splitting the dialplan across files and forgetting one #include makes a whole set of subroutines vanish at once.

How to tell which one it is

Read the full destination in the error - it is printed as context,extension,priority. Then check each of the three separately. Very often the context exists and the extension does not, which points at the implicit-suffix case rather than at a typo.

If the extension name ends in a status word like -ANSWER, the call came from a Dial() or Queue() option. Find the option in the dialplan and check what context name it supplies.

How to fix it

Related failures