{"id":13580753,"url":"https://github.com/rustwasm/console_error_panic_hook","last_synced_at":"2025-05-15T16:07:52.893Z","repository":{"id":32463647,"uuid":"134631768","full_name":"rustwasm/console_error_panic_hook","owner":"rustwasm","description":"A panic hook for wasm32-unknown-unknown that logs panics with console.error","archived":false,"fork":false,"pushed_at":"2022-12-04T18:10:44.000Z","size":516,"stargazers_count":339,"open_issues_count":14,"forks_count":29,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-15T00:10:18.990Z","etag":null,"topics":["console","panic-hook","rust","rust-wasm","wasm"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rustwasm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-23T22:25:27.000Z","updated_at":"2025-05-12T19:51:05.000Z","dependencies_parsed_at":"2023-01-14T21:18:48.941Z","dependency_job_id":null,"html_url":"https://github.com/rustwasm/console_error_panic_hook","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fconsole_error_panic_hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fconsole_error_panic_hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fconsole_error_panic_hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fconsole_error_panic_hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rustwasm","download_url":"https://codeload.github.com/rustwasm/console_error_panic_hook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254254028,"owners_count":22039792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["console","panic-hook","rust","rust-wasm","wasm"],"created_at":"2024-08-01T15:01:54.797Z","updated_at":"2025-05-15T16:07:52.842Z","avatar_url":"https://github.com/rustwasm.png","language":"Rust","funding_links":[],"categories":["Rust","Libraries"],"sub_categories":["Error Handling"],"readme":"## `console_error_panic_hook`\n\n[![](https://docs.rs/console_error_panic_hook/badge.svg)](https://docs.rs/console_error_panic_hook/)\n[![](https://img.shields.io/crates/v/console_error_panic_hook.svg)](https://crates.io/crates/console_error_panic_hook)\n[![](https://img.shields.io/crates/d/console_error_panic_hook.png)](https://crates.io/crates/console_error_panic_hook)\n[![Build Status](https://travis-ci.org/rustwasm/console_error_panic_hook.svg?branch=master)](https://travis-ci.org/rustwasm/console_error_panic_hook)\n\nThis crate lets you debug panics on `wasm32-unknown-unknown` by providing a\npanic hook that forwards panic messages to\n[`console.error`](https://developer.mozilla.org/en-US/docs/Web/API/Console/error).\n\nWhen an error is reported with `console.error`, browser devtools and node.js\nwill typically capture a stack trace and display it with the logged error\nmessage.\n\nWithout `console_error_panic_hook` you just get something like *RuntimeError: Unreachable executed*\n\nBrowser:\n![Console without panic hook](without_panic_hook.png)\n\nNode:\n![Node console without panic hook](without_panic_hook_node.png)\n\nWith this panic hook installed you will see the panic message\n\nBrowser:\n![Console with panic hook set up](with_panic_hook.png)\n\nNode:\n![Node console with panic hook set up](with_panic_hook_node.png)\n\n### Usage\n\nThere are two ways to install this panic hook.\n\nFirst, you can set the hook yourself by calling `std::panic::set_hook` in\nsome initialization function:\n\n```rust\nextern crate console_error_panic_hook;\nuse std::panic;\n\nfn my_init_function() {\n    panic::set_hook(Box::new(console_error_panic_hook::hook));\n\n    // ...\n}\n```\n\nAlternatively, use `set_once` on some common code path to ensure that\n`set_hook` is called, but only the one time. Under the hood, this uses\n`std::sync::Once`.\n\n```rust\nextern crate console_error_panic_hook;\n\nstruct MyBigThing;\n\nimpl MyBigThing {\n    pub fn new() -\u003e MyBigThing {\n        console_error_panic_hook::set_once();\n\n        MyBigThing\n    }\n}\n```\n\n### Error.stackTraceLimit\n\nMany browsers only capture the top 10 frames of a stack trace. In rust programs this is less likely to be enough. To see more frames, you can set the non-standard value `Error.stackTraceLimit`. For more information see the [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Microsoft_Extensions/Error.stackTraceLimit) or [v8 docs](https://v8.dev/docs/stack-trace-api).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustwasm%2Fconsole_error_panic_hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frustwasm%2Fconsole_error_panic_hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustwasm%2Fconsole_error_panic_hook/lists"}