Skip to main content

charon_error/submit/
submit_error_report.rs

1//! Trait for submitting error reports to external issue trackers.
2
3use crate::ErrorReport;
4use url::Url;
5
6/// Trait for converting an [`ErrorReport`] into a submittable issue report.
7///
8/// Implement this trait to add support for a new issue tracking platform.
9/// See [`GitLabErrorReport`](crate::GitLabErrorReport) for the built-in GitLab implementation.
10pub trait SubmitErrorReport<'a> {
11    /// Create a new report wrapper from an error report reference.
12    #[must_use]
13    fn new(error: &'a ErrorReport) -> Self;
14    /// Return the `ErrorReport` containing the error stack.
15    fn get_error_report(&self) -> &ErrorReport;
16    /// Return the title of the error.
17    #[must_use]
18    fn get_title(&self) -> String;
19    /// Truncate a string to the given limit, respecting character boundaries.
20    #[must_use]
21    fn truncate_string(mut text: String, limit: usize) -> String {
22        let mut new_len = limit;
23
24        if new_len <= text.len() {
25            // Make sure to not cut on char boundary (to prevent panic)
26            while !text.is_char_boundary(new_len) && new_len > 0 {
27                new_len -= 1;
28            }
29            tracing::warn!(
30                "SubmitErrorReport length of text was cut off. Org len: {}, New len: {} ({})",
31                text.len(),
32                new_len,
33                new_len as isize - text.len() as isize
34            );
35            text.truncate(new_len);
36        }
37        text
38    }
39    /// Create the full user-facing error message with report instructions.
40    fn create_message(&self) -> Result<String, ErrorReport>;
41    /// Create the bug report body text (same content as the URL submission).
42    fn create_bug_report(&self) -> Result<String, ErrorReport>;
43    /// Create a URL that opens a pre-filled issue on the platform.
44    fn create_submit_url(&self) -> Result<Url, ErrorReport>;
45    /// Create a pre-filled issue URL, progressively removing detail to stay under `max_length`.
46    fn create_submit_url_limited(&self, max_length: usize) -> Result<Url, ErrorReport>;
47    /// Create a URL to search for existing reports with the same title.
48    fn check_existing_reports(&self) -> Result<Url, ErrorReport>;
49}
50
51// Look for existing issue
52// Github: https://github.com/ralpha/pdf_signing/issues?q=in%3Atitle%20pdf