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 <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-08-16 12:22:17 +02:00
commit 092af336e3
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -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))