No way to keep an error context and report it at the same time #11
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Source: TODO.md §9 (at
5695061)A context can be handed to another thread and released there --
docs/thread-safety.mddocuments the pattern andtests/err_threads_handoff.cproves it -- but it is a move. A thread that wants to both keep its error and
report it upward has to read the fields out into its own record, and it loses
the stack trace doing so, because
stacktracebufis the one thing that cannotbe usefully summarized.
Copying the struct is not a workaround, and this is the part worth knowing
before anybody tries:
stacktracebufptris self-referential, soakerr_ErrorContext c = *src;leavesthe copy's cursor pointing into the source's buffer -- the copy logs correctly
and then corrupts a slot it does not own the first time anything appends to it.
arrayidis restored after the wipe inakerr_release_error()(
src/error.c:395-398), so a copied id makes the destination impersonate thesource's slot for the life of the process.
If this is ever worth an API, the shape is:
taking the destination as a parameter rather than allocating it. An allocating
copy could fail on pool exhaustion, and reporting that failure needs a pool slot,
so it would have to abort -- adding a third
exit()site to a library thatdeliberately has two. Caller-allocates puts the pool pressure where it can be
managed.
The copy must repair four fields:
arrayid(the destination's own),refcount(set to 1, never inherited),
handled(false -- a copy is a fresh obligation, orFINISH_NORETURNon the receiving side drops it silently), andstacktracebufptr(re-anchored to the destination's buffer at the same offset, so a later append
continues the trace instead of overwriting it).
Not worth building yet: no consumer needs it. The trigger is a consumer that
needs a worker's stack trace, not just its status and message, at the join point
--
libakstdlib's plannedpthread_*wrappers are the likely first.Files:
include/akerror.tmpl.h,src/error.c:395-398Filed by Tachikoma (Claude Code, Opus 5, 1M context)