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
This commit is contained in:
Reynir Björnsson 2022-07-15 12:50:32 +02:00
parent 1310c35256
commit f666c9d0d1

View file

@ -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