traceback

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package traceback ports cpython/Python/traceback.c. v0.3 ships the data shape, the format/print entry points, and a minimal frameless builder used by the errors package to attach traceback rows from Go call sites. Real frames join in v0.6 once the VM lands.

Index

Constants

This section is empty.

Variables

Type is the type singleton for the `traceback` builtin type.

CPython: Python/traceback.c:269 PyTraceBack_Type

Functions

func Format

func Format(tb *Traceback) string

Format returns the multi-line traceback string, oldest entry first. Mirrors traceback.format_tb output.

CPython: Python/traceback.c:L985 _PyTraceBack_FromFrame

func FormatException

func FormatException(tb *Traceback, typeName, message string) string

FormatException prepends typeName: message to a Format(tb) output, matching `traceback.format_exception` for a single (no-chain) exception. The errors package walks the cause/context chain itself and calls FormatException per node.

CPython: Python/traceback.c:L1129 _PyTraceBack_Print

Types

type Entry

type Entry struct {
	File string
	Line int
	Name string
}

Entry is one line of a traceback. Mirrors the data carried by PyTracebackObject (filename, line number, function name).

CPython: Objects/frameobject.h (analog) and Python/traceback.c

type Traceback

type Traceback struct {
	objects.Header
	Entry   Entry
	Next    *Traceback
	TbFrame objects.Object
	TbLasti int
}

Traceback is the linked list of entries that backs Python's `__traceback__`. The next pointer chains older frames; CPython stores the chain in reverse, with the newest frame at the head.

In CPython this is the PyTracebackObject struct exposed as the builtin `traceback` type. The Entry field carries the position data the original v0.3 port used (file/line/name); TbFrame and TbLasti are the slots that match CPython's tb_frame / tb_lasti once a real frame is available. Either the Entry path or the TbFrame path is enough to drive Format.

CPython: Include/cpython/traceback.h:L9 PyTracebackObject

func New

func New(entry Entry) *Traceback

New builds a single-entry traceback. The errors package uses this when v0.3 runtime code wants to attach a position from Go.

CPython: Python/traceback.c:L154 PyTraceBack_Here

func Push

func Push(tb *Traceback, entry Entry) *Traceback

Push prepends a new entry. The result becomes the new head.

CPython: Python/traceback.c:L154 PyTraceBack_Here

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL