fix(json): normalize dkjson decode error behavior to match cjson #13

Closed
opened 2026-04-24 10:16:42 +02:00 by michael · 0 comments
Owner

Problem

json.decode behavior depends on the active backend:

  • cjson: throws an error on invalid input (pcall catches it correctly)
  • dkjson: returns nil, pos, err without throwing (pcall sees ok=true, result=nil)
  • pure-lua: throws an error on invalid input

This means callers using pcall(json.decode, str) get silent nil with dkjson
instead of a caught error. Exposed by daw-modul-api test_api.lua test 8.

Fix

Wrap dkjson.decode to normalize behavior: throw an error when result is nil
and err is set -- identical to cjson and pure-lua behavior.

Acceptance Criteria

  • json.decode always throws on invalid input regardless of backend
  • All three backends behave identically from the caller's perspective
  • test_json.lua extended with invalid input test
## Problem `json.decode` behavior depends on the active backend: - cjson: throws an error on invalid input (pcall catches it correctly) - dkjson: returns `nil, pos, err` without throwing (pcall sees ok=true, result=nil) - pure-lua: throws an error on invalid input This means callers using `pcall(json.decode, str)` get silent nil with dkjson instead of a caught error. Exposed by daw-modul-api test_api.lua test 8. ## Fix Wrap dkjson.decode to normalize behavior: throw an error when result is nil and err is set -- identical to cjson and pure-lua behavior. ## Acceptance Criteria - [ ] `json.decode` always throws on invalid input regardless of backend - [ ] All three backends behave identically from the caller's perspective - [ ] test_json.lua extended with invalid input test
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#13
No description provided.