Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmd/av/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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')",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Hardcoding user-facing error messages like this can lead to maintainability issues. If this message needs to be changed, it might be missed if it's duplicated elsewhere. Also, it makes the code harder to read. Consider defining this format string as a package-level constant. This improves code clarity and makes future updates easier and safer.

dbPath,
)
}
return db, exists, nil
}

func allBranches(ctx context.Context) ([]string, error) {
Expand Down