fix(config,persist): Harden config validation and serialize session updates - #45
Merged
Conversation
setup({ ui = false }) left cfg.ui as a boolean because field validators only
descend into tables, and the first consumer that indexed it crashed. Restore
such sections to their defaults with a warning so setup() keeps its
never-throws guarantee.
nvim_create_autocmd() throws on an event name it does not know, so a typo
such as "CursorMoveed" crashed setup(). Validate each entry with
vim.fn.exists("##<name>") and ignore unknown ones with a warning, falling
back to the defaults when nothing valid remains.
…n 2 data migrate.ensure only checked that `sessions` was a table, so a hand-edited or partially written store such as `sessions.bad = true` passed through and crashed the first consumer that indexed it (restore, upsert, rename). Drop entries that are not tables and coerce each remaining session into the expected shape: `items` must be a list, `meta` must be a record with numeric created_at/updated_at.
…sions Async save/delete/rename each read the store, mutated their own snapshot and wrote it back. When two of them overlapped, the last write to finish carried a stale snapshot and silently discarded the other's change. Unique temp file names only protected the write itself, not the read-modify-write sequence. Route all mutations through orchestrator.update_async, which queues them and starts each read only after the previous write completed. Callback errors are caught so a throwing on_done cannot wedge the queue. The sync save path goes through update_sync, which drains in-flight async updates (bounded wait) before its own read-modify-write, so a save on VimLeavePre no longer races an async save that is still mid-flight.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
setup()no longer crashes on a top-level section replaced with a non-table value or on a misspelled autocmd event name, honoring the documented never-throws guarantee.Changes
setup({ ui = false })now warns and falls back to the defaultuisection instead of leaving a boolean that crashed the first consumer indexing it; the same applies topicker,providersandpersist.close_eventsentry is checked withvim.fn.exists("##<name>"); unknown names such asCursorMoveedare ignored with a warning instead of makingnvim_create_autocmd()throw at setup time.itemsis coerced to a list andmetato a record with numeric timestamps, so a hand-edited or partially written store no longer crashes restore/upsert/rename.update_asyncthat starts each read only after the previous write completed, eliminating the read-modify-write lost update between concurrent save/delete/rename.VimLeavePre) drain in-flight async updates before writing, and a throwingon_donecallback can no longer wedge the queue.