16
16
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
17
18
18
use anyhow:: Result ;
19
+ use async_std:: future:: pending;
19
20
use futures:: { select, FutureExt } ;
21
+ use log:: { error, info} ;
20
22
21
23
mod adc;
22
24
mod backlight;
@@ -50,7 +52,7 @@ use regulators::Regulators;
50
52
use setup_mode:: SetupMode ;
51
53
use system:: System ;
52
54
use temperatures:: Temperatures ;
53
- use ui:: { setup_display, Display , Ui , UiResources } ;
55
+ use ui:: { message , setup_display, Display , Ui , UiResources } ;
54
56
use usb_hub:: UsbHub ;
55
57
use watchdog:: Watchdog ;
56
58
@@ -156,7 +158,7 @@ async fn run(
156
158
// Expose the display as a .png on the web server
157
159
ui:: serve_display ( & mut http_server. server , display. screenshooter ( ) ) ;
158
160
159
- log :: info!( "Setup complete. Handling requests" ) ;
161
+ info ! ( "Setup complete. Handling requests" ) ;
160
162
161
163
// Run until the user interface, http server or (if selected) the watchdog
162
164
// exits (with an error).
@@ -183,6 +185,24 @@ async fn main() -> Result<()> {
183
185
// Show a splash screen very early on
184
186
let display = setup_display ( ) ;
185
187
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 \n Check log for info.\n Waiting for watchdog\n to 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
+ }
188
208
}
0 commit comments