Skip to content

Parser crash on trailing whitespace in last posting line without amount #7

@JaGitJe

Description

@JaGitJe

When the last line of a posting has no explicit amount and ends with a trailing space, the plugin crashes with a nil node error.

Reproduction

account Ausgaben:Transport
account Aktiva:Girokonto

commodity 1000.00 EUR

2025-01-08 This Posting has trailing space in line 3 
    Ausgaben:Transport            EUR 49.00
    Aktiva:Girokonto 

2025-01-09 Monatskarte BVG
    Ausgaben:Transport            EUR 49.00
    Aktiva:Girokonto

Line 3 has a trailing space. Opening this file crashes immediately. Removing the space or adding an explicit amount prevents the crash.

Error

"test.journal" 12L, 289B written
Error detected while processing BufWritePost Autocommands for "*.journal":
Error executing lua callback: /usr/share/nvim/runtime/lua/vim/treesitter.lua:219: attempt to index local 'node' (a nil value)
stack traceback:
        /usr/share/nvim/runtime/lua/vim/treesitter.lua:219: in function 'get_node_text'
        ....local/share/nvim/lazy/ledger.nvim/lua/ledger/parser.lua:154: in function 'get_postings_from_source'
        ...local/share/nvim/lazy/ledger.nvim/lua/ledger/context.lua:70: in function 'add_file'
        ...ocal/share/nvim/lazy/ledger.nvim/lua/ledger/commands.lua:104: in function <...ocal/share/nvim/lazy/ledger.nvim/lua/ledger/commands.lua:100>

:InspectTree shows no ERROR nodes — tree-sitter parses the file fine. Looks like a missing nil check before get_node_text in parser.lua:154.

Environment

  • Neovim v0.11.6, ledger.nvim v0.3.0, tree-sitter-ledger latest, Arch Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions