From f666c9d0d1065e94cd401a493bbbd658d0b5b838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Fri, 15 Jul 2022 12:50:32 +0200 Subject: [PATCH] Improve builder-web setup error messages Give hints what to do in case the database file does not exist, or when the database is not of the expected version. Addresses #82 --- bin/builder_web_app.ml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/builder_web_app.ml b/bin/builder_web_app.ml index 55a3dba..8de60e1 100644 --- a/bin/builder_web_app.ml +++ b/bin/builder_web_app.ml @@ -126,14 +126,23 @@ let setup_app level influx port host datadir cachedir configdir run_batch_viz_fl run_batch_viz ~cachedir ~datadir ~configdir in match Builder_web.init dbpath datadir with + | exception Sqlite3.Error e -> + Format.eprintf "Error: @[@,%s.\ + @,Does the database file exist? Create with `builder-db migrate`.@]\n%!" + e; + exit 2 | Error (#Caqti_error.load as e) -> Format.eprintf "Error: %a\n%!" Caqti_error.pp e; exit 2 + | Error (`Wrong_version _ as e) -> + Format.eprintf "Error: @[@,%a.\ + @,Migrate database version with `builder-migrations`,\ + @,or start with a fresh database with `builder-db migrate`.@]\n%!" + Builder_web.pp_error e; | Error ( #Caqti_error.connect | #Caqti_error.call_or_retrieve - | `Msg _ - | `Wrong_version _ as e + | `Msg _ as e ) -> Format.eprintf "Error: %a\n%!" Builder_web.pp_error e; exit 1