From 092af336e38ef57878f9f03e545956ed78ca31c8 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sun, 16 Aug 2026 12:22:17 +0200 Subject: [PATCH] load_yaml: __main__: Harden debug entry point The __main__ debug printer crashes with a bare IndexError when no file argument is given, and json.dumps() crashes on YAML values that have no JSON representation, such as dates. Check the argument count and print a usage message, and pass default = str to json.dumps() so that non-JSON values are rendered as strings instead of aborting the dump. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2 Signed-off-by: Jan Lindemann --- src/python/jw/util/load_yaml.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/python/jw/util/load_yaml.py b/src/python/jw/util/load_yaml.py index ef01d7b..d8bdade 100644 --- a/src/python/jw/util/load_yaml.py +++ b/src/python/jw/util/load_yaml.py @@ -389,4 +389,6 @@ if __name__ == '__main__': import json import sys - print(json.dumps(load_yaml(sys.argv[1]), indent = 2)) + if len(sys.argv) != 2: + sys.exit(f'usage: {sys.argv[0]} FILE.yaml') + print(json.dumps(load_yaml(sys.argv[1]), indent = 2, default = str))