bug
A Rust library for streamlined bug reporting that generates GitHub issue URLs with pre-filled templates. Works in both std
and no_std
environments. When bugs occur, bug
prints tracing-style error messages to stderr and provides clean GitHub URLs for easy bug reporting.
โจ Features
- ๐ฏ Template-based bug reporting - Define reusable issue templates with named parameters
- ๐ File-based templates - Load templates from markdown files using
include_str!
macro - ๐ท๏ธ Label support - Automatically apply labels to GitHub issues
- โ Parameter validation - Ensures all template placeholders are properly filled at compile time
- ๐ URL encoding - Handles special characters in URLs automatically
- ๐ Multiple templates - Support for different issue types per project
- ๐ ๏ธ no_std support - Works in embedded and no_std environments with
--no-default-features
- ๐ฆ Handle-based API - Alternative API that doesn't rely on global state
๐ฆ Installation
Add this to your Cargo.toml
:
[]
= "0.2.0"
no_std Support
For embedded or no_std environments:
[]
= { = "0.2.0", = false }
๐ Quick Start
use ;
This outputs:
๐ BUG ENCOUNTERED in src/main.rs:15
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=...
๐ ๏ธ no_std and Handle-based API
For no_std
environments or when you prefer not to use global state, use the handle-based API:
use ;
no_std Considerations
In no_std
mode:
- Use
FxHashMap
instead ofstd::collections::HashMap
- Global
bug!()
macro returns empty string (usebug_with_handle!()
instead) - Terminal hyperlink detection is disabled (specify
HyperlinkMode::Always
orNever
explicitly) - Custom output via the
Output
trait for logging to different targets
Custom Output in no_std
use ;
;
let mut output = MyOutput;
let url = bug_handle.report_bug_with_output;
๐ Template Files
Create structured markdown templates for consistent bug reports:
templates/crash_report.md:
Application Crash: {error_type}
- ---
1. 2.3.
{expected_behavior}
{additional_info}
The application crashed with error: {error_type}
Load in Rust:
use ;
๐ฏ Usage Examples
Multiple Template Types
use ;
Comprehensive Bug Reports
// Performance issue reporting
let url = bug!;
// Simple usage without parameters
bug!;
๐ Output Format
The bug!()
macro prints structured information to stderr:
๐ BUG ENCOUNTERED in src/database.rs:127
Template: performance
Parameters:
operation: database_query
expected: 100
actual: 1500
ratio: 15
os: windows
version: 0.1.0
File a bug report: https://github.com/myorg/myproject/issues/new?title=Performance%20Issue...
๐ Terminal Hyperlinks & Clean URLs
Generated GitHub URLs can be quite long (800+ characters) due to URL-encoded template content, making log messages verbose and cluttering terminal output. Terminal hyperlink support using ANSI escape sequences to display clean, clickable text while hiding the long URL underneath.
๐ฑ๏ธ Hyperlink Modes
Configure how links are displayed:
use ;
// Auto-detect terminal hyperlink support (default)
init
.hyperlinks
.build?;
// Always use hyperlinks
init
.hyperlinks
.build?;
// Never use hyperlinks (show full URLs)
init
.hyperlinks
.build?;
๐บ Supported Terminals
Automatic detection works with:
- Windows Terminal
- iTerm2 (macOS)
- WezTerm
- Alacritty
- VS Code Integrated Terminal
- Most xterm-compatible terminals
๐ Output Comparison
With Hyperlinks (clean):
๐ BUG ENCOUNTERED in src/main.rs:45
Template: crash
Parameters:
error_type: NullPointerException
function: calculate_sum
File a bug report
Without Hyperlinks (traditional):
๐ BUG ENCOUNTERED in src/main.rs:45
Template: crash
Parameters:
error_type: NullPointerException
function: calculate_sum
File a bug report: https://github.com/user/repo/issues/new?title=Application%20Crash...
The hyperlink text "File a bug report" becomes clickable and opens the full GitHub issue URL when clicked, keeping your logs clean while maintaining full functionality.
๐ API Reference
Core Functions
init(owner, repo)
- Initialize bug reporting configuration (std only)init_handle(owner, repo)
- Create a bug report handle (std and no_std)bug!(template, {params})
- Report a bug with given template and parameters (std only)bug_with_handle!(handle, template, {params})
- Report bug using handle (std and no_std)create_terminal_hyperlink(url, text)
- Create ANSI hyperlink escape sequencesupports_hyperlinks()
- Detect terminal hyperlink support (std only, no_std returns false)
Structs
IssueTemplate
- Represents a GitHub issue templateTemplateFile
- File-based template with validationBugReportConfigBuilder
- Fluent API for configuration (std only)BugReportHandle
- Handle-based bug reporting (std and no_std)HyperlinkMode
- Configure hyperlink display behavior
Types
FxHashMap<K, V>
- HashMap type used by the API (re-exported from hashbrown)Output
- Trait for custom output in no_std environments
Enums
HyperlinkMode::Auto
- Auto-detect terminal support (default, std only)HyperlinkMode::Always
- Always use hyperlinksHyperlinkMode::Never
- Always show full URLs
Macros
template_file!(path, labels: [...])
- Load template from filebug!(template, {key = value, ...})
- Report bug with parameters (std only)bug_with_handle!(handle, template, {key = value, ...})
- Report bug with handle (std and no_std)
Feature Flags
std
(default) - Enable std support with global state and environment detection- When
std
is disabled: no_std mode with handle-based API only
๐งช Examples
See the examples/
directory for complete working examples:
basic_usage.rs
- Basic global state usagehandle_usage.rs
- Handle-based API (works in no_std)template_file_usage.rs
- File-based templateshyperlink_demo.rs
- Terminal hyperlink examples- Template files in
templates/
directory
Run examples:
For no_std examples:
๐ค Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.