ananthakumaran / paisa

Paisa – Personal Finance Manager. https://paisa.fyi demo: https://demo.paisa.fyi
https://paisa.fyi
GNU Affero General Public License v3.0
2.4k stars 124 forks source link

FATAL while importing journal with syntax error #56

Closed pashagolub closed 11 months ago

pashagolub commented 11 months ago

if I have any syntax error in the journal and try to Sync Journal the application fails with FATAL level

INFO    Syncing transactions from journal
INFO    POST 200 2498ms /api/sync                     clientIP=127.0.0.1 referer="http://localhost:7500/ledger/editor/main.ledger"
INFO    GET 200 23ms /api/editor/files                clientIP=127.0.0.1 referer="http://localhost:7500/ledger/editor/main.ledger"
INFO    POST 200 221ms /api/editor/validate           clientIP=127.0.0.1 referer="http://localhost:7500/ledger/editor/main.ledger"
INFO    Syncing transactions from journal
FATAL   exit status 1

If one runs an application it crashes with ugly error box. If one is running CLI version the front-end is always showin progress indication, while the back-end is dead.

Solution: produce a regular error and proceed without terminating application

pashagolub commented 11 months ago

I'd go with such a solution

func SyncJournal(db *gorm.DB) error {
    AutoMigrate(db)
    log.Info("Syncing transactions from journal")
    prices, err := ledger.Cli().Prices(config.GetJournalPath())
    if err != nil {
        return err
    }

    price.UpsertAllByType(db, config.Unknown, prices)

    postings, err := ledger.Cli().Parse(config.GetJournalPath(), prices)
    if err != nil {
        return err
    }
    posting.UpsertAll(db, postings)
}