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:
parent
568c92b009
commit
092af336e3
1 changed files with 3 additions and 1 deletions
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Reference in a new issue