fix: yaml uses error() instead of nil, err -- inconsistent API #23

Closed
opened 2026-05-25 17:57:40 +02:00 by michael · 1 comment
Owner

Problem

yaml.load_file and parse_map use error() instead of returning
nil, err like the rest of daw.common.

This forces callers to wrap every yaml.load_file call in pcall,
which is inconsistent with how other daw.common modules work.

Fix

  • load_file: return nil, "[ERROR] yaml: cannot open file: " .. path
  • parse_map: propagate error as return value instead of throwing

Also

Header path comment is outdated: says src/daw/lua/common/yaml.lua
and usage example shows daw.lua.common.yaml -- both should be
daw/common/yaml.lua and daw.common.yaml.

## Problem `yaml.load_file` and `parse_map` use `error()` instead of returning `nil, err` like the rest of daw.common. This forces callers to wrap every yaml.load_file call in pcall, which is inconsistent with how other daw.common modules work. ## Fix - `load_file`: return `nil, "[ERROR] yaml: cannot open file: " .. path` - `parse_map`: propagate error as return value instead of throwing ## Also Header path comment is outdated: says `src/daw/lua/common/yaml.lua` and usage example shows `daw.lua.common.yaml` -- both should be `daw/common/yaml.lua` and `daw.common.yaml`.
Author
Owner

parse_map/parse_seq/parse_block now return (node, next_i, err) instead of throwing. Nil is reserved exclusively for the error channel -- an empty/absent block returns {} on success, not nil, resolving the ambiguity that a naive nil,err conversion would have created (nil previously meant both 'legitimately empty' and 'parse error'). Verified against reconstructed tenant.yaml / uk_ebook_zero.yaml structures plus the nested-sequence-of-maps path (parse_seq calling parse_map recursively).

parse_map/parse_seq/parse_block now return (node, next_i, err) instead of throwing. Nil is reserved exclusively for the error channel -- an empty/absent block returns {} on success, not nil, resolving the ambiguity that a naive nil,err conversion would have created (nil previously meant both 'legitimately empty' and 'parse error'). Verified against reconstructed tenant.yaml / uk_ebook_zero.yaml structures plus the nested-sequence-of-maps path (parse_seq calling parse_map recursively).
michael 2026-07-19 17:55:33 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/daw-lua-common#23
No description provided.