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 where
15 Self: Sized;
16 /// Return the `ErrorReport` containing the error stack.
17 fn get_error_report(&self) -> &ErrorReport;
18 /// Return the title of the error.
19 #[must_use]
20 fn get_title(&self) -> String;
21 /// Truncate a string to the given limit, respecting character boundaries.
22 #[must_use]
23 fn truncate_string(mut text: String, limit: usize) -> String
24 where
25 Self: Sized,
26 {
27 let mut new_len = limit;
28
29 if new_len <= text.len() {
30 // Make sure to not cut on char boundary (to prevent panic)
31 while !text.is_char_boundary(new_len) && new_len > 0 {
32 new_len -= 1;
33 }
34 tracing::warn!(
35 "SubmitErrorReport length of text was cut off. Org len: {}, New len: {} ({})",
36 text.len(),
37 new_len,
38 new_len as isize - text.len() as isize
39 );
40 text.truncate(new_len);
41 }
42 text
43 }
44 /// Create the full user-facing error message with report instructions.
45 fn create_message(&self) -> Result<String, ErrorReport>;
46 /// Create the bug report body text (same content as the URL submission).
47 fn create_bug_report(&self) -> Result<String, ErrorReport>;
48 /// Create a URL that opens a pre-filled issue on the platform.
49 fn create_submit_url(&self) -> Result<Url, ErrorReport>;
50 /// Create a pre-filled issue URL, progressively removing detail to stay under `max_length`.
51 fn create_submit_url_limited(&self, max_length: usize) -> Result<Url, ErrorReport>;
52 /// Create a URL to search for existing reports with the same title.
53 fn check_existing_reports(&self) -> Result<Url, ErrorReport>;
54
55 /// Validate that required global settings have been configured.
56 ///
57 /// Called by [`setup_panic!`](crate::setup_panic) in debug builds to
58 /// catch missing configuration early.
59 fn validate_settings(&self) -> Result<(), ErrorReport>;
60}
61
62// Look for existing issue
63// Github: https://github.com/ralpha/pdf_signing/issues?q=in%3Atitle%20pdf