CUI

Components / Developer tools

Stack trace

An exception with its call stack.

Functions: cui_stack_trace

Stack trace

Usage

static const char *const src[] = { "function total(cart) {", "  let sum = 0;", "  for (const item of cart.items) {" };
static const cui_stack_frame frames[] = {
    { "total", "src/cart.js", 3, 29, false, src, 3, 1 },          /* source lines 1 to 3 */
    { "handle", "node_modules/express/lib/router/layer.js", 95, 5, true },
};
cui_stack_trace(ui, "error", frames, 2, .title = "TypeError", .message = "Cannot read properties of undefined", .lang = "js");

The header shows the error's type and message, with a button that copies the whole trace as text. Each frame shows its function and its file, line and column. A run of library frames (external) folds into one row that unfolds on a click. A frame with source opens to show those lines, highlighted, with the frame's line marked. The first frame of your own code starts open. Frames are focusable, and Enter or Space opens one. On a phone only the file's name is shown.

Keyboard

  • Frames are focusable, and Enter or Space opens one.

Options of cui_stack_trace

OptionTypeDefaultDescription
.widthcui_sizeWidth: CUI_FILL, CUI_FIT, CUI_PX(n) or CUI_PCT(n); unset uses the component's own.
.titleconst char *"TypeError"
.messageconst char *"Cannot read properties of undefined"
.langconst char *highlights the source, as the code block

cui_stack_frame

FieldTypeDescription
functionconst char *name of the function; NULL or "" shows as <anonymous>
fileconst char *path shown with the line and column; on a phone only the file's name
lineint1 based; 0 leaves it out
columnint1 based; 0 leaves it out
externalboollibrary or runtime code
sourceconst char *const *lines around the frame, may be NULL
source_countintnumber of lines in source
source_firstintline number of source[0]

cui_stack_trace_result

FieldTypeDescription
clickedintframe, or -1

Related

  • HTTP request bar: The method, the URL and Send, as in an API client.
  • Test explorer: Test results as a tree of suites and tests, each with its status and time.
  • Uptime bars: A status page: each service's current state and a bar for each day of its history.
  • Regex tester: A pattern, its flags and a test text, with every match and group highlighted.