Originally Posted by Wims
Although the very last request which leads to the new $fromeditbox talks about a $calias, which has been suggested in the past, the purpose of such a function was to report the name of the alias which called our alias (or maybe the addition of $caller has nothing to do with https://forums.mirc.com/ubbthreads.php/topics/262061/$fromeditbox ??)

$caller does not actually do that, it seems to return information about the context in which the alias was called, which is great to have too, but it's not addressing the main issue: debugging script by displaying a "stack trace".

Something else which would help a lot with debugging would be able to also get the script filename which have the alias which called our alias, as well as getting the script line.

So maybe the current $caller could see some properties (without any parameter just like $mouse!):

$caller.alias - return the name of the alias which called the current alias
$caller.script - return the filename in which the alias which called the current alias can be found
$caller.scriptline - return the line number in $caller.script where the alias which called the current alias can be found.

To be able to produce a stack trace, what you need in addition to properties is for $caller to be extended as follows:

$caller(0) - return the depth of the call stack
$caller(x).prop - return above details of the call from x levels higher

You could then have the following:

Code
alias FooBar {
    return $identifier
:error
    StackTrace $ $+ identifier returned an error
}

alias StackTrace {
    var %n $caller(0), %i 2
    if (%n == 1) {
        echo -s 4 StackTrace can be used to report an error and give details of how the error code was reached
        halt
    }
    echo -s 4 StackTrace: Fatal error: $1- $+ : " $+ $error $+ " occurred in $caller(1).script at line $caller(1).scriptline $+ :
    while (%i <= %n) {
        echo -s 4 StackTrace: Called as $caller(%i) $caller(%i).alias from $caller(%i).script at line $caller(%i).scriptline
        inc %i
    }
    halt
}


Unfortunately this implementation would require an error routine in every alias because if the error propagated to a higher level alias, the stack trace would be lost. However if the stack trace in $caller was copied to an extended $error identifier at the time of the error, you could then have something like the following:


Code
alias FooBar {
    Foo
:error
    StackTrace $ $+ identifier returned an error
}

alias Foo { Bar }

alias Bar { CREATEanERROR }

alias StackTrace {
    var %n $error(0), %i 2
    if (%n == 1) {
        echo -s 4 StackTrace can be used to report an error and give details of how the error code was reached
        halt
    }
    echo -s 4 StackTrace: Fatal error: $1- $+ : " $+ $error $+ " occurred in $error(1).script at line $error(1).scriptline $+ :
    while (%i <= %n) {
        echo -s 4 StackTrace: Called as $error(%i).type $error(%i).alias from $error(%i).script at line $error(%i).scriptline
        inc %i
    }
    halt
}