From 5a58b5a5086eb29715203db5aa3f9b8f1d7a7c5b Mon Sep 17 00:00:00 2001 From: Anantha Kumaran Date: Wed, 20 Apr 2022 09:03:09 +0530 Subject: [PATCH] show proper error message if ledger is not installed --- internal/ledger/ledger.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/ledger/ledger.go b/internal/ledger/ledger.go index 9441aa52..464b63ca 100644 --- a/internal/ledger/ledger.go +++ b/internal/ledger/ledger.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/csv" - "log" + log "github.com/sirupsen/logrus" "os/exec" "strconv" "time" @@ -15,11 +15,16 @@ import ( func Parse(journalPath string) ([]*posting.Posting, error) { var postings []*posting.Posting + _, err := exec.LookPath("ledger") + if err != nil { + log.Fatal(err) + } + command := exec.Command("ledger", "-f", journalPath, "csv", "--csv-format", "%(quoted(date)),%(quoted(payee)),%(quoted(display_account)),%(quoted(commodity(scrub(display_amount)))),%(quoted(quantity(scrub(display_amount)))),%(quoted(to_int(scrub(market(amount,date)))))\n") var output, error bytes.Buffer command.Stdout = &output command.Stderr = &error - err := command.Run() + err = command.Run() if err != nil { log.Fatal(error.String()) return nil, err