Skip to content

Build1 publisher2 min readPublished

TinyGo 0.42 makes runtime panics catchable with plain defer and recover

InfoQ reports that nil dereferences, bad slice and map indexes and division by zero now unwind through defer and recover in TinyGo 0.42. That is the machinery the testing package's abort paths needed. Out-of-memory still ends the program.

The Engineer · Build desk

What happened

  • TinyGo 0.42 introduces recoverable runtime panics, so nil pointer dereferences, out-of-bounds slice and map accesses and division-by-zero errors can be caught with standard defer and recover.
  • Fatal conditions such as out-of-memory errors stay unrecoverable, according to InfoQ's account of the release.
  • With panic handling in place, standard library test suites can use the testing functions Goexit, SkipNow and FailNow.
  • The release also adds a UEFI target that lets Go code run natively as a UEFI application before an operating system boots.
  • A companion Starter Kit pairs the XIAO ESP32-C3 with a Grove Base and eleven modular Grove peripherals that connect without breadboard or jumper wiring, plus a tutorial series by core team member Patricio Whittingslow.

Compiled by The EngineerSomething wrong?How this is made

Why it matters

  • cost Taking the feature means taking the toolchain with it: 0.42 is the release that supports Go 1.27 and LLVM 22, and no overhead figure accompanies the unwinding support, so the flash budget check falls on whoever ships the firmware.
  • capability A test suite that aborts cases through FailNow can be compiled and run without stripping those calls out first, so an embedded team can check conformance to standard behaviour.
  • constraint Recover stops short of allocation failure, so the memory budgeting a constrained target already demands stays exactly where it was.
  • decision Teams that kept their code panic-free by convention now have a choice to make. Adopting the defer and recover idiom pins the firmware to 0.42 or later.

The test-helper detail is a statement about unwinding. InfoQ links Goexit, SkipNow and FailNow to the new panic handling [3], and a runtime with no unwinding path cannot stop one test case and carry on with the next. On Hacker News, InfoQ reports, the arrival of defer and recover was read as removing a friction point for developers who had previously rewritten standard Go idioms or handled panics by hand [10].

Three of the four newly recoverable conditions are memory-safety checks the compiler already emits, and the fourth is division by zero [16]. Recoverable division by zero sounds academic until a sensor reports a zero denominator. InfoQ describes 0.42 as closing "a major feature gap with standard Go" [6].

The same article carries a second difference from upstream. Inside WebAssembly runtimes, TinyGo runs standard goroutines through Binaryen's Asyncify with GOMAXPROCS=1 [7]. One goroutine runs at a time there. Code whose behaviour depends on two goroutines making progress simultaneously still compiles to something else under that target. This release leaves that where it was.

The write-up stops short of an overhead number [17]. Unwinding costs flash and cycles. On a microcontroller with tens of kilobytes of program space, the code-size delta measured on your own board decides whether the upgrade ships.

On the WebAssembly side, the project showed typescript-go, Microsoft's TypeScript compiler written in Go, compiled entirely into WebAssembly [8]. That exercises reflection at a scale well past a blinking-LED demo. One release earlier, 0.41 added native Wi-Fi and Bluetooth on the ESP32-C3 and ESP32-S3 through the espradio library, along with an espflasher deployment utility [11], and core support for the Arduino UNO Q, which pairs a Qualcomm MPU with an STM32 MCU [12].

The reaction InfoQ collected from r/golang was narrower and more practical. Developers picked out hosting a working HTTP server on a postage-stamp-sized microcontroller costing a few dollars [15].

What to watch

  • Whether the release notes or a follow-up publish flash and cycle overhead for unwinding on a Cortex-M target.
  • Which standard library test suites actually pass under 0.42 once run, and which still need skips.
  • Whether WebAssembly builds ever get goroutine scheduling beyond GOMAXPROCS=1 under Asyncify.
Loading claim ledger
Loading source directory links
Loading share composer
Loading topic controls
Loading related stories