bug 0.3.0

A simple Rust library for printing an error in the event of a bug and allowing users to easily file a bug report via GitHub issues using bug templates.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
#![cfg_attr(not(feature = "std"), no_std)]

//! # bug_rs
//!
//! A simple Rust library for printing a tracing-style error in the event of a bug and allowing users to easily file a bug report via GitHub issues using bug templates.
//!
//! ## Features
//!
//! - Define reusable issue templates with named parameters
//! - Load templates from markdown files using `include_str!` macro
//! - Print formatted bug reports to stderr (similar to tracing output)
//! - Generate clean GitHub issue URLs with pre-filled templates
//! - Support for multiple issue templates per project
//! - URL encoding for special characters
//! - Optional labels for GitHub issues
//! - Parameter validation ensures all placeholders are filled
//!
//! ## Quick Start
//!
//! ```rust
//! use bug_rs::{bug, init, IssueTemplate};
//!
//! # fn main() -> Result<(), &'static str> {
//! // Initialize with your GitHub repository
//! init("username", "repository")
//!     .add_template("crash", IssueTemplate::new(
//!         "Application Crash: {error_type}",
//!         "## Description\nThe application crashed with error: {error_type}\n\n## Context\n- Function: {function}\n- Line: {line}"
//!     ).with_labels(vec!["bug".to_string(), "crash".to_string()]))
//!     .build()?;
//!
//! // Later in your code, when a bug occurs:
//! let url = bug!("crash", {
//!     error_type = "NullPointerException",
//!     function = "calculate_sum",
//!     line = "42"
//! });
//! 
//! println!("Bug report URL: {}", url);
//! # Ok(())
//! # }
//! ```
//!
//! ## Advanced Usage
//!
//! ### Multi-Crate Projects with Shared Bug Definitions
//!
//! For multi-crate projects, you can create a shared bug reporting handle that doesn't rely on global state:
//!
//! ```rust
//! use bug_rs::{bug_with_handle, init_handle, IssueTemplate, BugReportHandle};
//!
//! # fn main() {
//! // Create a handle that can be shared across crates
//! let bug_handle = init_handle("myorg", "myproject")
//!     .add_template("crash", IssueTemplate::new(
//!         "Application Crash: {error_type}",
//!         "## Description\nThe application crashed with error: {error_type}"
//!     ))
//!     .add_template("performance", IssueTemplate::new(
//!         "Performance Issue: {operation} is too slow",
//!         "Operation: {operation}\nExpected: {expected}ms\nActual: {actual}ms"
//!     ));
//!
//! // Use the handle to report bugs
//! let url = bug_with_handle!(bug_handle, "crash", {
//!     error_type = "NullPointerException"
//! });
//! # }
//! ```
//!
//! ### Using Template Files
//!
//! Create a markdown template file with placeholders:
//!
//! **templates/crash_report.md:**
//! ```markdown
//! Application Crash: {error_type}
//!
//! ## Description
//! The application crashed with error: {error_type}
//!
//! ## Context
//! - Function: {function}
//! - Line: {line}
//! - OS: {os}
//! ```
//!
//! Then load it in your Rust code:
//!
//! ```rust
//! use bug_rs::{init, template_file};
//!
//! # fn main() -> Result<(), &'static str> {
//! init("myorg", "myproject")
//!     .add_template_file("crash", template_file!("templates/crash_report.md", labels: ["bug", "crash"]))
//!     .build()?;
//! # Ok(())
//! # }
//! ```
//!
//! ### Multiple Templates
//!
//! ```rust
//! use bug_rs::{init, IssueTemplate, template_file};
//!
//! # fn main() -> Result<(), &'static str> {
//! init("myorg", "myproject")
//!     .add_template("simple", IssueTemplate::new(
//!         "Simple Issue: {title}",
//!         "Description: {description}"
//!     ))
//!     .add_template_file("detailed", template_file!("templates/detailed_report.md"))
//!     .build()?;
//! # Ok(())
//! # }
//! ```
//!
//! ### Using the bug! Macro
//!
//! The `bug!` macro provides a clean API similar to tracing macros:
//!
//! ```rust
//! # use bug_rs::{bug, init, IssueTemplate};
//! # init("test", "test").add_template("error", IssueTemplate::new("Error", "Body")).build().unwrap();
//!
//! // Simple usage without parameters
//! bug!("error");
//!
//! // With named parameters
//! bug!("performance", {
//!     operation = "database_query",
//!     expected = 100,
//!     actual = 1500,
//!     os = std::env::consts::OS,
//!     version = env!("CARGO_PKG_VERSION")
//! });
//! ```
//!
//! ## Output Format
//!
//! When `bug!()` is called, it prints to stderr in a format similar to tracing:
//!
//! ```text
//! 🐛 BUG ENCOUNTERED in src/main.rs:45
//!    Template: crash
//!    Parameters:
//!      error_type: NullPointerException
//!      function: calculate_sum
//!      line: 42
//!    File a bug report: https://github.com/username/repository/issues/new?title=Application%20Crash%3A%20NullPointerException&body=...
//! ```

mod url_encode;

#[cfg(feature = "std")]
extern crate std;

#[cfg(not(feature = "std"))]
extern crate alloc;

#[cfg(not(feature = "std"))]
use alloc::{
    string::{String, ToString},
    vec::Vec,
    format,
};

use hashbrown::HashMap;
use rustc_hash::FxHasher;
use core::hash::BuildHasherDefault;

pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;

#[cfg(feature = "std")]
use once_cell::sync::OnceCell;

#[cfg(feature = "std")]
static CONFIG: OnceCell<BugReportConfig> = OnceCell::new();

#[cfg(not(feature = "std"))]
static mut CONFIG: Option<BugReportConfig> = None;

/// Output trait for no_std compatibility
pub trait Output {
    fn write_str(&mut self, s: &str);
    fn write_fmt(&mut self, args: core::fmt::Arguments);
}

#[cfg(feature = "std")]
impl Output for std::io::Stderr {
    fn write_str(&mut self, s: &str) {
        eprint!("{}", s);
    }
    
    fn write_fmt(&mut self, args: core::fmt::Arguments) {
        eprint!("{}", args);
    }
}

/// Default no-op output for no_std
pub struct NoOutput;

impl Output for NoOutput {
    fn write_str(&mut self, _s: &str) {}
    fn write_fmt(&mut self, _args: core::fmt::Arguments) {}
}

#[derive(Debug, Clone)]
pub struct BugReportConfig {
    pub github_owner: String,
    pub github_repo: String,
    pub templates: FxHashMap<String, IssueTemplate>,
    pub template_files: FxHashMap<String, TemplateFile>,
    pub use_hyperlinks: HyperlinkMode,
}

#[derive(Debug, Clone)]
pub enum HyperlinkMode {
    /// Automatically detect terminal hyperlink support
    Auto,
    /// Always use hyperlinks
    Always,
    /// Never use hyperlinks (show full URLs)
    Never,
}

#[derive(Debug, Clone)]
pub struct IssueTemplate {
    pub title: String,
    pub body: String,
    pub labels: Vec<String>,
}

#[derive(Debug, Clone)]
pub struct TemplateFile {
    pub content: &'static str,
    pub labels: Vec<String>,
}

impl TemplateFile {
    pub fn new(content: &'static str) -> Self {
        Self {
            content,
            labels: Vec::new(),
        }
    }

    pub fn with_labels(mut self, labels: Vec<String>) -> Self {
        self.labels = labels;
        self
    }

    pub fn parse(&self) -> Result<IssueTemplate, String> {
        let lines: Vec<&str> = self.content.lines().collect();
        
        if lines.is_empty() {
            return Err("Template file is empty".to_string());
        }

        let title = lines[0].trim();
        if title.is_empty() {
            return Err("Template must have a title on the first line".to_string());
        }

        let body = if lines.len() > 1 {
            lines[1..].join("\n").trim().to_string()
        } else {
            String::new()
        };

        Ok(IssueTemplate {
            title: title.to_string(),
            body,
            labels: self.labels.clone(),
        })
    }

    pub fn validate_params(&self, params: &FxHashMap<String, String>) -> Result<(), String> {
        let placeholders = extract_placeholders(self.content);
        
        for placeholder in &placeholders {
            if !params.contains_key(placeholder) {
                return Err(format!("Missing required parameter: {}", placeholder));
            }
        }

        for param_key in params.keys() {
            if !placeholders.contains(param_key) {
                return Err(format!("Unused parameter: {}", param_key));
            }
        }

        Ok(())
    }
}

impl IssueTemplate {
    pub fn new(title: impl Into<String>, body: impl Into<String>) -> Self {
        Self {
            title: title.into(),
            body: body.into(),
            labels: Vec::new(),
        }
    }

    pub fn from_template_file(template_file: &TemplateFile, params: &FxHashMap<String, String>) -> Result<Self, String> {
        template_file.validate_params(params)?;
        let parsed_template = template_file.parse()?;
        Ok(parsed_template.fill_params(params))
    }

    pub fn with_labels(mut self, labels: Vec<String>) -> Self {
        self.labels = labels;
        self
    }

    pub fn fill_params(&self, params: &FxHashMap<String, String>) -> IssueTemplate {
        let mut filled_title = self.title.clone();
        let mut filled_body = self.body.clone();

        for (key, value) in params {
            let placeholder = format!("{{{}}}", key);
            filled_title = filled_title.replace(&placeholder, value);
            filled_body = filled_body.replace(&placeholder, value);
        }

        IssueTemplate {
            title: filled_title,
            body: filled_body,
            labels: self.labels.clone(),
        }
    }
}

fn extract_placeholders(content: &str) -> Vec<String> {
    let mut placeholders = Vec::new();
    let mut chars = content.chars().peekable();
    
    while let Some(ch) = chars.next() {
        if ch == '{' {
            let mut placeholder = String::new();
            let mut found_end = false;
            
            while let Some(inner_ch) = chars.next() {
                if inner_ch == '}' {
                    found_end = true;
                    break;
                } else if inner_ch.is_alphanumeric() || inner_ch == '_' {
                    placeholder.push(inner_ch);
                } else {
                    placeholder.clear();
                    break;
                }
            }
            
            if found_end && !placeholder.is_empty() && !placeholders.contains(&placeholder) {
                placeholders.push(placeholder);
            }
        }
    }
    
    placeholders
}

#[macro_export]
macro_rules! template_file {
    ($path:expr) => {
        $crate::TemplateFile::new(include_str!($path))
    };
    ($path:expr, labels: [$($label:expr),* $(,)?]) => {
        $crate::TemplateFile::new(include_str!($path))
            .with_labels(vec![$($label.to_string()),*])
    };
}

pub fn init(github_owner: impl Into<String>, github_repo: impl Into<String>) -> BugReportConfigBuilder {
    BugReportConfigBuilder::new(github_owner.into(), github_repo.into())
}

pub fn init_handle(github_owner: impl Into<String>, github_repo: impl Into<String>) -> BugReportHandle {
    BugReportHandle::new(github_owner.into(), github_repo.into())
}

pub struct BugReportConfigBuilder {
    config: BugReportConfig,
}

impl BugReportConfigBuilder {
    fn new(github_owner: String, github_repo: String) -> Self {
        Self {
            config: BugReportConfig {
                github_owner,
                github_repo,
                templates: FxHashMap::default(),
                template_files: FxHashMap::default(),
                use_hyperlinks: HyperlinkMode::Auto,
            },
        }
    }

    pub fn add_template(mut self, name: impl Into<String>, template: IssueTemplate) -> Self {
        self.config.templates.insert(name.into(), template);
        self
    }

    pub fn add_template_file(mut self, name: impl Into<String>, template_file: TemplateFile) -> Self {
        self.config.template_files.insert(name.into(), template_file);
        self
    }

    pub fn hyperlinks(mut self, mode: HyperlinkMode) -> Self {
        self.config.use_hyperlinks = mode;
        self
    }

    #[cfg(feature = "std")]
    pub fn build(self) -> Result<(), &'static str> {
        CONFIG.set(self.config).map_err(|_| "Bug reporting already initialized")
    }
    
    #[cfg(not(feature = "std"))]
    pub unsafe fn build(self) -> Result<(), &'static str> {
        unsafe {
            match CONFIG {
                Some(_) => return Err("Bug reporting already initialized"),
                None => CONFIG = Some(self.config),
            }
        }
        Ok(())
    }
}

#[derive(Debug, Clone)]
pub struct BugReportHandle {
    config: BugReportConfig,
}

impl BugReportHandle {
    fn new(github_owner: String, github_repo: String) -> Self {
        Self {
            config: BugReportConfig {
                github_owner,
                github_repo,
                templates: FxHashMap::default(),
                template_files: FxHashMap::default(),
                use_hyperlinks: HyperlinkMode::Auto,
            },
        }
    }

    pub fn add_template(mut self, name: impl Into<String>, template: IssueTemplate) -> Self {
        self.config.templates.insert(name.into(), template);
        self
    }

    pub fn add_template_file(mut self, name: impl Into<String>, template_file: TemplateFile) -> Self {
        self.config.template_files.insert(name.into(), template_file);
        self
    }

    pub fn hyperlinks(mut self, mode: HyperlinkMode) -> Self {
        self.config.use_hyperlinks = mode;
        self
    }

    pub fn generate_url(&self, template_name: &str, params: &FxHashMap<String, String>) -> Result<String, String> {
        let filled_template = if let Some(template) = self.config.templates.get(template_name) {
            template.fill_params(params)
        } else if let Some(template_file) = self.config.template_files.get(template_name) {
            IssueTemplate::from_template_file(template_file, params)?
        } else {
            return Err(format!("Template '{}' not found", template_name));
        };
        
        let mut url = format!(
            "https://github.com/{}/{}/issues/new",
            self.config.github_owner, self.config.github_repo
        );

        let mut query_params = Vec::new();
        
        if !filled_template.title.is_empty() {
            query_params.push(format!("title={}", url_encode::encode(&filled_template.title)));
        }
        
        if !filled_template.body.is_empty() {
            query_params.push(format!("body={}", url_encode::encode(&filled_template.body)));
        }
        
        if !filled_template.labels.is_empty() {
            let labels_str = filled_template.labels.join(",");
            query_params.push(format!("labels={}", url_encode::encode(&labels_str)));
        }

        if !query_params.is_empty() {
            url.push('?');
            url.push_str(&query_params.join("&"));
        }

        Ok(url)
    }

    pub fn report_bug(&self, template_name: &str, params: &FxHashMap<String, String>, file: &str, line: u32) -> String {
        self.report_bug_with_output(template_name, params, file, line, &mut NoOutput)
    }
    
    #[cfg(feature = "std")]
    pub fn report_bug_stderr(&self, template_name: &str, params: &FxHashMap<String, String>, file: &str, line: u32) -> String {
        self.report_bug_with_output(template_name, params, file, line, &mut std::io::stderr())
    }
    
    pub fn report_bug_with_output(&self, template_name: &str, params: &FxHashMap<String, String>, file: &str, line: u32, output: &mut dyn Output) -> String {
        match self.generate_url(template_name, params) {
            Ok(url) => {
                output.write_fmt(format_args!("🐛 BUG ENCOUNTERED in {}:{}\n", file, line));
                output.write_fmt(format_args!("   Template: {}\n", template_name));
                if !params.is_empty() {
                    output.write_str("   Parameters:\n");
                    for (key, value) in params {
                        output.write_fmt(format_args!("     {}: {}\n", key, value));
                    }
                }
                let should_use_hyperlinks = match self.config.use_hyperlinks {
                    HyperlinkMode::Auto => supports_hyperlinks(),
                    HyperlinkMode::Always => true,
                    HyperlinkMode::Never => false,
                };
                
                if should_use_hyperlinks {
                    output.write_fmt(format_args!("   {}\n", create_terminal_hyperlink(&url, "File a bug report")));
                } else {
                    output.write_fmt(format_args!("   File a bug report: {}\n", url));
                }
                output.write_str("\n");
                url
            }
            Err(e) => {
                output.write_fmt(format_args!("🐛 BUG ENCOUNTERED in {}:{}\n", file, line));
                output.write_fmt(format_args!("   Error generating bug report: {}\n", e));
                output.write_str("\n");
                String::new()
            }
        }
    }

    pub fn config(&self) -> &BugReportConfig {
        &self.config
    }
}

#[cfg(feature = "std")]
pub fn generate_github_url(template_name: &str, params: &FxHashMap<String, String>) -> Result<String, String> {
    let config = CONFIG.get().ok_or("Bug reporting not initialized. Call bug_rs::init() first.")?;
    
    let filled_template = if let Some(template) = config.templates.get(template_name) {
        template.fill_params(params)
    } else if let Some(template_file) = config.template_files.get(template_name) {
        IssueTemplate::from_template_file(template_file, params)?
    } else {
        return Err(format!("Template '{}' not found", template_name));
    };
    
    let mut url = format!(
        "https://github.com/{}/{}/issues/new",
        config.github_owner, config.github_repo
    );

    let mut query_params = Vec::new();
    
    if !filled_template.title.is_empty() {
        query_params.push(format!("title={}", url_encode::encode(&filled_template.title)));
    }
    
    if !filled_template.body.is_empty() {
        query_params.push(format!("body={}", url_encode::encode(&filled_template.body)));
    }
    
    if !filled_template.labels.is_empty() {
        let labels_str = filled_template.labels.join(",");
        query_params.push(format!("labels={}", url_encode::encode(&labels_str)));
    }

    if !query_params.is_empty() {
        url.push('?');
        url.push_str(&query_params.join("&"));
    }

    Ok(url)
}

/// Creates a terminal hyperlink using ANSI escape sequences
/// Format: \x1b]8;;URL\x1b\\TEXT\x1b]8;;\x1b\\
pub fn create_terminal_hyperlink(url: &str, text: &str) -> String {
    format!("\x1b]8;;{}\x1b\\{}\x1b]8;;\x1b\\", url, text)
}

/// Gets the hyperlink mode from configuration
#[cfg(feature = "std")]
pub fn get_hyperlink_mode() -> HyperlinkMode {
    CONFIG.get()
        .map(|config| config.use_hyperlinks.clone())
        .unwrap_or(HyperlinkMode::Never)
}

/// Gets the hyperlink mode from configuration (no_std version)
#[cfg(not(feature = "std"))]
pub unsafe fn get_hyperlink_mode() -> HyperlinkMode {
    unsafe {
        match core::ptr::addr_of!(CONFIG).read() {
            Some(config) => config.use_hyperlinks.clone(),
            None => HyperlinkMode::Never,
        }
    }
}

/// Detects if the terminal supports hyperlinks by checking environment variables
/// Only available with std feature
#[cfg(feature = "std")]
pub fn supports_hyperlinks() -> bool {
    // Check for common terminal emulators that support hyperlinks
    if let Ok(term) = std::env::var("TERM") {
        if term.contains("xterm") || term.contains("screen") || term.contains("tmux") {
            return true;
        }
    }
    
    // Check for specific terminal programs
    if let Ok(term_program) = std::env::var("TERM_PROGRAM") {
        match term_program.as_str() {
            "iTerm.app" | "WezTerm" | "Alacritty" | "Windows Terminal" => return true,
            _ => {}
        }
    }
    
    // Check for VS Code integrated terminal
    if std::env::var("VSCODE_INJECTION").is_ok() {
        return true;
    }
    
    // Default to false for unknown terminals
    false
}

/// No-std version always returns false - user must specify hyperlink mode explicitly
#[cfg(not(feature = "std"))]
pub fn supports_hyperlinks() -> bool {
    false
}

#[macro_export]
macro_rules! bug {
    ($template:expr) => {
        $crate::bug!($template, {})
    };
    ($template:expr, { $($key:ident = $value:expr),* $(,)? }) => {{
        use $crate::FxHashMap;
        
        let mut params = FxHashMap::default();
        $(
            params.insert(stringify!($key).to_string(), $value.to_string());
        )*

        #[cfg(feature = "std")]
        {
            match $crate::generate_github_url($template, &params) {
                Ok(url) => {
                    eprintln!("🐛 BUG ENCOUNTERED in {}:{}", file!(), line!());
                    eprintln!("   Template: {}", $template);
                    if !params.is_empty() {
                        eprintln!("   Parameters:");
                        for (key, value) in &params {
                            eprintln!("     {}: {}", key, value);
                        }
                    }
                    let should_use_hyperlinks = match $crate::get_hyperlink_mode() {
                        $crate::HyperlinkMode::Auto => $crate::supports_hyperlinks(),
                        $crate::HyperlinkMode::Always => true,
                        $crate::HyperlinkMode::Never => false,
                    };
                    
                    if should_use_hyperlinks {
                        eprintln!("   {}", $crate::create_terminal_hyperlink(&url, "File a bug report"));
                    } else {
                        eprintln!("   File a bug report: {}", url);
                    }
                    eprintln!();
                    url
                }
                Err(e) => {
                    eprintln!("🐛 BUG ENCOUNTERED in {}:{}", file!(), line!());
                    eprintln!("   Error generating bug report: {}", e);
                    eprintln!();
                    String::new()
                }
            }
        }
        #[cfg(not(feature = "std"))]
        {
            // In no_std mode, we can't use the global config, so just return empty string
            // User should use bug_with_handle! instead
            String::new()
        }
    }};
}

#[macro_export]
macro_rules! bug_with_handle {
    ($handle:expr, $template:expr) => {
        $crate::bug_with_handle!($handle, $template, {})
    };
    ($handle:expr, $template:expr, { $($key:ident = $value:expr),* $(,)? }) => {{
        use $crate::FxHashMap;
        
        let mut params = FxHashMap::default();
        $(
            params.insert(stringify!($key).to_string(), $value.to_string());
        )*

        $handle.report_bug($template, &params, file!(), line!())
    }};
}