console_error_panic_hook

A panic hook for wasm32-unknown-unknown that forwards Rust panic messages to console.error

Library
Cargo
v0.1.7
356stars
Apache-2.0/MIT

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
31/100Needs Attention
Development Activity0
Maintenance0
Community44
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
71/100Good
Architecture64
Code Quality70
Innovation58
Learning Curve90

When a Rust panic occurs in a wasm32-unknown-unknown WebAssembly build without this crate installed, the browser or Node.js console typically shows only an opaque RuntimeError: Unreachable executed, with no indication of what actually went wrong in the Rust source. console_error_panic_hook replaces the default panic behavior with one that logs the real panic message (and, where available, a stack trace) via console.error, so browser devtools and Node.js can surface it properly.

Installation is a single call — either panic::set_hook(Box::new(console_error_panic_hook::hook)) in an init function, or console_error_panic_hook::set_once() guarded by std::sync::Once on a common code path so the hook is only installed once regardless of how many times the initializer runs.

What You Get

  • A hook function to pass directly to std::panic::set_hook for readable panic messages in WASM builds
  • A set_once() convenience function (backed by std::sync::Once) to install the hook exactly once from any repeatedly-called initializer
  • Panic messages routed through console.error, which browser devtools and Node.js both capture with an accompanying stack trace
  • A no-op / pass-through implementation on non-wasm32 targets via cfg_if, so the same code compiles cleanly for native testing

Common Use Cases

  • Debugging Rust-compiled-to-WebAssembly applications where panics otherwise surface only as an opaque ‘unreachable executed’ trap
  • Standard boilerplate added to the entry point of wasm-bindgen-based WASM libraries and applications during development
  • Improving crash diagnostics for WASM modules run in Node.js server-side or tooling contexts
  • Pairing with wasm-pack-built crates to give contributors readable error output during local development

Under The Hood

Architecture: The entire implementation lives in a single src/lib.rs. It uses the cfg_if! macro to branch on target_arch = "wasm32": on wasm32 it pulls in wasm_bindgen to call the browser’s console.error JS function with the formatted panic message and location; on other targets it compiles to effectively nothing (or a fallback), so the same crate can be a dependency in cross-platform test suites without pulling in wasm-only code paths. set_once() wraps panic::set_hook in a std::sync::Once so repeated calls (e.g. from a constructor called many times) still only register the hook a single time.

Tech Stack: A minimal Rust crate whose only two dependencies are cfg-if (for the target-arch branching) and wasm-bindgen (for the JS interop that calls console.error). No build tooling beyond standard cargo — this is a leaf dependency meant to be pulled into other wasm-bindgen projects.

Code Quality: The crate ships doc-tested usage examples directly in src/lib.rs (both the set_hook and set_once patterns), plus a tests/ directory, keeping the documented API and tested behavior in sync. At ~6.5KB of Rust source, the entire implementation is small enough to audit in minutes, and its single-purpose scope has kept it stable with no need for frequent updates (last commit several years prior to this analysis) despite continued heavy download volume.

API Design: The two-line integration — either panic::set_hook(Box::new(console_error_panic_hook::hook)) or console_error_panic_hook::set_once() — requires no configuration and composes with any existing panic-hook chain via standard std::panic APIs, making it one of the lowest-friction debugging aids in the wasm-bindgen ecosystem.

Used by 5 apps in this directory

Rust
50%
Other

hoodik

File Storage · Security

1,446

Self-hosted, end-to-end encrypted cloud storage with browser-based encryption and S3-compatible storage support

View details
74
Repo Health
71
Technical
65
Dependency
Built with
Rust50%
TypeScript33%
Vue15%
Updated 4 days ago
TypeScript
76%
Other

Joplin

Note Taking

56,003

The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.

View details
93
Repo Health
87
Technical
62
Dependency
Built with
TypeScript76%
JavaScript15%
Updated yesterday
Rust
84%
Apache 2.0

liteparse

Developer Tools

12,123

A fast, lightweight, open-source document parser that extracts spatial text, bounding boxes, and Markdown from PDFs and Office files — entirely on your machine.

View details
83
Repo Health
80
Technical
74
Dependency
Built with
Rust84%
Updated today
Rust
92%
MIT

OpenPencil

AI Design Tools

5,380

An open-source, AI-native vector design tool with concurrent agent teams, design-as-code, a built-in MCP server, and multi-model intelligence — a distinct project from the similarly-named Figma-file-reading "open-pencil" editor.

View details
80
Repo Health
70
Technical
75
Dependency
Built with
Rust92%
Updated today
Python
61%
Apache 2.0

WrenAI

Analytics · AI Agents · Data Engineering

17,313

Open-source GenBI engine that lets AI agents turn natural-language questions into governed SQL, charts, and shareable dashboards across 20+ data sources — no vendor lock-in, no black-box prompts.

View details
91
Repo Health
91
Technical
69
Dependency
Built with
Python61%
Rust36%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search