Skip to content

Commit 6bce630

Browse files
committed
tacd: display an error messages if the tacd startup failed
Signed-off-by: Leonard Göhrs <[email protected]>
1 parent 2582421 commit 6bce630

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/main.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1717

1818
use anyhow::Result;
19+
use async_std::future::pending;
1920
use futures::{select, FutureExt};
21+
use log::{error, info};
2022

2123
mod adc;
2224
mod backlight;
@@ -50,7 +52,7 @@ use regulators::Regulators;
5052
use setup_mode::SetupMode;
5153
use system::System;
5254
use temperatures::Temperatures;
53-
use ui::{setup_display, Display, Ui, UiResources};
55+
use ui::{message, setup_display, Display, Ui, UiResources};
5456
use usb_hub::UsbHub;
5557
use watchdog::Watchdog;
5658

@@ -156,7 +158,7 @@ async fn run(
156158
// Expose the display as a .png on the web server
157159
ui::serve_display(&mut http_server.server, display.screenshooter());
158160

159-
log::info!("Setup complete. Handling requests");
161+
info!("Setup complete. Handling requests");
160162

161163
// Run until the user interface, http server or (if selected) the watchdog
162164
// exits (with an error).
@@ -183,6 +185,24 @@ async fn main() -> Result<()> {
183185
// Show a splash screen very early on
184186
let display = setup_display();
185187

186-
let (ui, http_server, watchdog) = init().await?;
187-
run(ui, http_server, watchdog, display).await
188+
match init().await {
189+
Ok((ui, http_server, watchdog)) => run(ui, http_server, watchdog, display).await,
190+
Err(e) => {
191+
// Display a detailed error message on stderr (and thus in the journal) ...
192+
error!("Failed to initialize tacd: {e}");
193+
194+
// ... and a generic message on the LCD, as it can not fit a lot of detail.
195+
display.clear();
196+
display.with_lock(|target| {
197+
message(
198+
target,
199+
"tacd failed to start!\n\nCheck log for info.\nWaiting for watchdog\nto restart tacd.",
200+
);
201+
});
202+
203+
// Wait forever (or more likely until the systemd watchdog timer hits)
204+
// to give the user a chance to actually see the error message.
205+
pending().await
206+
}
207+
}
188208
}

src/ui.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ mod widgets;
3535
use alerts::{AlertList, Alerter};
3636
use buttons::{handle_buttons, Button, ButtonEvent, Direction, PressDuration, Source};
3737
pub use display::{Display, ScreenShooter};
38+
pub use screens::message;
3839
use screens::{splash, ActivatableScreen, AlertScreen, NormalScreen, Screen};
3940

4041
pub struct UiResources {

0 commit comments

Comments
 (0)