From 92a0d3a59a69a49d7797c302f42a2db2013761a2 Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Mon, 23 Mar 2026 00:29:54 -0700 Subject: [PATCH] improve error message when av.db is corrupted Wrap the database open error with a user-friendly message that names the file path and suggests deleting the file and running 'av init'. Previously a corrupted av.db would produce an unclear JSON parse error without actionable guidance. Closes #514 Co-Authored-By: Claude Opus 4.6 --- cmd/av/helpers.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/av/helpers.go b/cmd/av/helpers.go index e653e903..f71a6c5b 100644 --- a/cmd/av/helpers.go +++ b/cmd/av/helpers.go @@ -69,7 +69,14 @@ func getDB(ctx context.Context, repo *git.Repo) (meta.DB, error) { func getOrCreateDB(repo *git.Repo) (meta.DB, bool, error) { dbPath := filepath.Join(repo.AvDir(), "av.db") - return jsonfiledb.OpenPath(dbPath) + db, exists, err := jsonfiledb.OpenPath(dbPath) + if err != nil { + return nil, false, errors.WrapIff(err, + "failed to open av database at %q (the file may be corrupted; try deleting it and running 'av init')", + dbPath, + ) + } + return db, exists, nil } func allBranches(ctx context.Context) ([]string, error) {