Skip to content

Commit 7dad963

Browse files
authored
Merge pull request rust-lang#18386 from Wilfred/missing_offset
fix: Handle missing time offsets gracefully
2 parents 1fbaccd + 33f27d1 commit 7dad963

File tree

1 file changed

+14
-6
lines changed
  • src/tools/rust-analyzer/crates/rust-analyzer/src/tracing

1 file changed

+14
-6
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/tracing/config.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,22 @@ where
5858
let writer = self.writer;
5959

6060
let ra_fmt_layer = tracing_subscriber::fmt::layer()
61-
.with_timer(
62-
time::OffsetTime::local_rfc_3339()
63-
.expect("Could not get local offset, make sure you're on the main thread"),
64-
)
6561
.with_target(false)
6662
.with_ansi(false)
67-
.with_writer(writer)
68-
.with_filter(targets_filter);
63+
.with_writer(writer);
64+
65+
let ra_fmt_layer = match time::OffsetTime::local_rfc_3339() {
66+
Ok(timer) => {
67+
// If we can get the time offset, format logs with the timezone.
68+
ra_fmt_layer.with_timer(timer).boxed()
69+
}
70+
Err(_) => {
71+
// Use system time if we can't get the time offset. This should
72+
// never happen on Linux, but can happen on e.g. OpenBSD.
73+
ra_fmt_layer.boxed()
74+
}
75+
}
76+
.with_filter(targets_filter);
6977

7078
let chalk_layer = match self.chalk_filter {
7179
Some(chalk_filter) => {

0 commit comments

Comments
 (0)