aboutsummaryrefslogtreecommitdiff
path: root/src/errors.rs
diff options
context:
space:
mode:
authorrottedfm <rottedfm@proton.me>2026-08-19 11:21:47 -0400
committerrottedfm <rottedfm@proton.me>2026-08-19 11:21:47 -0400
commitea0bd36167b684c0accdb5ce2b2e21b8d84aeb25 (patch)
treebe1267972b5de2f1ae592577dfabce67f1fe6e87 /src/errors.rs
parent8c0b4c53b130555f040884c1f52b90f16b23e241 (diff)
feat: implement Helix-style modal buffer under DO-178C DAL-C
The repository was an unmodified ratatui component template: no editor code, JSON5 config, and placeholder widgets. This establishes the first working baseline — `moji <file>` opens a file into a ropey rope and edits it with Helix selection-first semantics. Requirements, implementation and tests land together because they must: the traceability check rejects requirements with no implementation and tests naming requirements that do not exist, so neither half is a valid commit on its own. Package renamed to mojibake-editor (mojibake was taken on crates.io); binary is moji, library target stays mojibake. Class: New behaviour Requirements: MJB-HLR-001..019, MJB-LLR-001..205 Derived: MJB-DR-001..007 (DR-001 resolved, six open for review) Verified: cargo build; clippy --all-targets -D warnings clean; cargo test 294 passing; ./scripts/check-trace.sh 98/98/98; cargo package clean Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'src/errors.rs')
-rw-r--r--src/errors.rs77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/errors.rs b/src/errors.rs
new file mode 100644
index 0000000..ebed8af
--- /dev/null
+++ b/src/errors.rs
@@ -0,0 +1,77 @@
+use std::env;
+
+use tracing::error;
+
+pub fn init() -> color_eyre::Result<()> {
+ let (panic_hook, eyre_hook) = color_eyre::config::HookBuilder::default()
+ .panic_section(format!(
+ "This is a bug. Consider reporting it at {}",
+ env!("CARGO_PKG_REPOSITORY")
+ ))
+ .capture_span_trace_by_default(false)
+ .display_location_section(false)
+ .display_env_section(false)
+ .into_hooks();
+ eyre_hook.install()?;
+ std::panic::set_hook(Box::new(move |panic_info| {
+ if let Ok(mut t) = crate::tui::Tui::new()
+ && let Err(r) = t.exit()
+ {
+ error!("Unable to exit Terminal: {:?}", r);
+ }
+
+ #[cfg(not(debug_assertions))]
+ {
+ use human_panic::{handle_dump, metadata, print_msg};
+ let metadata = metadata!();
+ let file_path = handle_dump(&metadata, panic_info);
+ // prints human-panic message
+ print_msg(file_path, &metadata)
+ .expect("human-panic: printing error message to console failed");
+ eprintln!("{}", panic_hook.panic_report(panic_info)); // prints color-eyre stack trace to stderr
+ }
+ let msg = format!("{}", panic_hook.panic_report(panic_info));
+ error!("Error: {}", strip_ansi_escapes::strip_str(msg));
+
+ #[cfg(debug_assertions)]
+ {
+ // Better Panic stacktrace that is only enabled when debugging.
+ better_panic::Settings::auto()
+ .most_recent_first(false)
+ .lineno_suffix(true)
+ .verbosity(better_panic::Verbosity::Full)
+ .create_panic_handler()(panic_info);
+ }
+
+ std::process::exit(libc::EXIT_FAILURE);
+ }));
+ Ok(())
+}
+
+/// Similar to the `std::dbg!` macro, but generates `tracing` events rather
+/// than printing to stdout.
+///
+/// By default, the verbosity level for the generated events is `DEBUG`, but
+/// this can be customized.
+#[macro_export]
+macro_rules! trace_dbg {
+ (target: $target:expr, level: $level:expr, $ex:expr) => {
+ {
+ match $ex {
+ value => {
+ tracing::event!(target: $target, $level, ?value, stringify!($ex));
+ value
+ }
+ }
+ }
+ };
+ (level: $level:expr, $ex:expr) => {
+ trace_dbg!(target: module_path!(), level: $level, $ex)
+ };
+ (target: $target:expr, $ex:expr) => {
+ trace_dbg!(target: $target, level: tracing::Level::DEBUG, $ex)
+ };
+ ($ex:expr) => {
+ trace_dbg!(level: tracing::Level::DEBUG, $ex)
+ };
+}