Skip to content

Commit

Permalink
Add runtime:getStackTrace
Browse files Browse the repository at this point in the history
Also harmonize with error:stackTrace.
Fixes #675.
  • Loading branch information
jclark committed Dec 15, 2020
1 parent a8484e1 commit 6c15d8f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lang/lib/error.bal
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,22 @@ public isolated function cause(error e) returns error? = external;
# + return - error detail value
public isolated function detail(error<DetailType> e) returns readonly & DetailType = external;

# Returns an object representing the stack trace of the error.
# Type representing a stack frame.
# A call stack is represented as an array of stack frames.
# This type is also present in lang.runtime to avoid a dependency.
public type StackFrame readonly & object {
# Returns a string representing this StackFrame.
# This must not contain any newline characters.
# + return - a string
public function toString() returns string;
};

# Returns an array representing an error's stack trace.
#
# + e - the error value
# + return - a new object representing the stack trace of the error value
public isolated function stackTrace(error e) returns readonly & object { } = external;
# + return - an array representing the stack trace of the error value
# The first member of the array represents the top of the call stack.
public isolated function stackTrace(error e) returns StackFrame[] = external;

# Converts an error to a string.
#
Expand Down
16 changes: 16 additions & 0 deletions lang/lib/runtime.bal
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,19 @@ public isolated function registerListener(DynamicListener listener) = external;
# The `listener` ceases to be a module listener of the module from
# which this function is called.
public isolated function deregisterListener(DynamicListener listener) = external;


# Type representing a stack frame.
# A call stack is represented as an array of stack frames.
# This type is also present in lang.error to avoid a dependency.
public type StackFrame readonly & object {
# Returns a string representing this StackFrame.
# This must not contain any newline characters.
# + return - a string
public function toString() returns string;
};

# Return a stack trace for the current call stack.
# + return - an array representing the current call stack
# The first member of the array represents the top of the call stack.
public function getStackTrace() returns StackFrame[] = external;

0 comments on commit 6c15d8f

Please sign in to comment.