subspace_core/diagnostics/
local.rs1use super::{BuildIdentity, ErrorDetails, IssuePaths, RedactionContext, RuntimeDetails};
2
3#[derive(Clone)]
6pub struct LocalDiagnostics {
7 pub(super) identity: BuildIdentity,
8 pub(super) framework_version: String,
9 pub(super) os_version: Option<String>,
10 pub(super) runtime: Option<RuntimeDetails>,
11 pub(super) redaction: RedactionContext,
12}
13
14impl Default for LocalDiagnostics {
15 fn default() -> Self {
16 Self::new(
17 BuildIdentity::new("unavailable", "unavailable"),
18 "unavailable",
19 )
20 }
21}
22
23impl LocalDiagnostics {
25 pub fn new(identity: BuildIdentity, framework_version: impl Into<String>) -> Self {
26 Self {
27 identity,
28 framework_version: framework_version.into(),
29 os_version: None,
30 runtime: None,
31 redaction: RedactionContext::default(),
32 }
33 }
34
35 pub fn with_os_version(mut self, version: impl Into<String>) -> Self {
36 self.os_version = Some(version.into());
37 self
38 }
39
40 pub fn with_runtime(mut self, runtime: RuntimeDetails) -> Self {
41 self.runtime = Some(runtime);
42 self
43 }
44
45 pub fn with_redaction(mut self, redaction: RedactionContext) -> Self {
46 self.redaction = redaction;
47 self
48 }
49
50 pub fn issue_paths(&self, config_path: Option<&str>) -> IssuePaths {
53 IssuePaths::project(self.runtime.as_ref(), &self.redaction, config_path)
54 }
55
56 pub fn local_copy(&self, error: Option<&ErrorDetails>) -> LocalCopy {
57 let fields = [
58 ("Product", Some(self.identity.product_id())),
59 ("App version", Some(self.identity.app_version())),
60 ("Build channel", self.identity.channel()),
61 ("Commit", self.identity.commit()),
62 (
63 "Subspace Framework version",
64 Some(self.framework_version.as_str()),
65 ),
66 ("OS", self.identity.os()),
67 ("OS version", self.os_version.as_deref()),
68 ("Architecture", self.identity.architecture()),
69 ];
70 let mut fields: Vec<_> = fields
71 .into_iter()
72 .map(|(name, value)| {
73 (
74 name,
75 self.redaction.public_field(value.unwrap_or("unavailable")),
76 )
77 })
78 .collect();
79 fields.extend(super::markdown::runtime_fields(
80 self.runtime.as_ref(),
81 &self.redaction,
82 ));
83 let diagnostics = super::markdown::section("Diagnostics", &fields);
84 LocalCopy(super::markdown::render(self, error, diagnostics))
85 }
86}
87
88#[derive(Debug, Clone)]
92pub struct LocalCopy(String);
93
94impl LocalCopy {
95 pub fn markdown(&self) -> &str {
96 &self.0
97 }
98}