Skip to content

F0049 flt-2

Rule: HardFault and DefaultHandler do nothing that can panic or log.

Code F0049 (stable, never reused)
Id flt-2
Category flt
Source spirit_level
Fix by hand

Level per tier

Tier Level Reason
small off
small-workspace off
medium off
big off
ai off
embedded deny bedrock error: defmt, cnt!, unwrap or anything that can panic or nest-log inside HardFault / DefaultHandler: record the IRQ number raw instead
ui off
egui off
units-strict off
units-paranoid off

Why

Defmt logging, cnt!, unwrap, or any other call that can itself panic or trigger another log, reached from inside HardFault or DefaultHandler.

A fault handler already runs in the worst-understood state the firmware can be in; anything inside it that can fail recurses straight into the same handler (or a different fault) with no bottom to the recursion, which turns a diagnosable fault into a true hang with no record at all.

Example

Typec_dongle FW-48: a DefaultHandler that tried to log hit exactly this, which is also why irq-8's default handler must only record the raw IRQ number.

How to fix

Record only raw register values and numbers (no formatting, no logging) inside HardFault/ DefaultHandler; do formatting and logging only after a reset, reading the crash record back.

How it is checked

src easy: reachability from the handler body to any call that formats, allocates, or can itself panic.

Source

Ported from embedded_bedrock's firmware check catalogue, FLT-2 (book/checks.md, detail in book/checks/flt.md). Found on: typec_dongle FW-48.

Configure

[lints.flt-2]
level = "deny"
reason = "why this project wants it at this level"

Allow one finding in the code with // spirit-level: allow(flt-2) <reason> (waivers); the code works there too, as in [lints.F0049].