[Bug] image-generation generate.py crashes with an AttributeError when its JSON argument is valid but not an object
English is recommended so global developers can help. 推荐使用英文提交,谢谢 ❤️
- I'm on the latest version and searched existing issues (incl. closed) — no duplicate.
Environment
Version: current master (commit 08f64f7)
OS: any — the script only imports the standard library
Python: 3.11 / 3.13 (CI matrix)
Channel: any (the image-generation skill calls this script)
What happened?
skills/image-generation/scripts/generate.py answers most bad calls with a JSON error envelope, but a valid-JSON argument that is not an object produces a raw Python traceback instead.
try:
args = json.loads(raw)
except json.JSONDecodeError as e:
print(json.dumps({"error": f"Invalid JSON: {e}"}))
sys.exit(1)
prompt = args.get("prompt") # <-- args may be a list / str / int / bool / Nonejson.loads also succeeds on a bare list, string, number, true and null. Only json.JSONDecodeError is caught, so those reach args.get() and raise AttributeError.
Steps to reproduce
$ python skills/image-generation/scripts/generate.py '[1, 2]'
Traceback (most recent call last):
...
AttributeError: 'list' object has no attribute 'get'
$ python skills/image-generation/scripts/generate.py 'null'
AttributeError: 'NoneType' object has no attribute 'get'
$ python skills/image-generation/scripts/generate.py '42'
AttributeError: 'int' object has no attribute 'get'
$ python skills/image-generation/scripts/generate.py 'true'
AttributeError: 'bool' object has no attribute 'get'Every one of these writes nothing to stdout and the traceback to stderr.
Expected, and consistent with every other failure in this script:
$ python skills/image-generation/scripts/generate.py '[1, 2]'
{"error": "Arguments must be a JSON object"}Actual: empty stdout, AttributeError on stderr, exit code 1.
Why the envelope matters here
The envelope is the contract: the script is invoked by the skill, so the caller parses stdout. On the malformed-JSON path it gets a parseable error; on these paths it gets nothing at all, so the failure surfaces as an unparseable result rather than the intended "you passed the wrong shape of argument" message.
Note that {not json} and {} already behave correctly — only the
valid-but-not-an-object shapes are broken, which is why this has gone unnoticed.
Suggested fix
Reject a non-object argument right after parsing, before the first .get():
if not isinstance(args, dict):
print(json.dumps({"error": "Arguments must be a JSON object"}))
sys.exit(1)Logs
Not applicable — reproducible by running the script directly, as shown above.
Source: zhayujie/CowAgent