fix(rapid7-insightidr): name the input when terms_json will not parse (v1.2.1)
json.loads answers a bad value with "Expecting value: line 1 column 1 (char 0)",
which names neither the input at fault nor what it actually received. The
command has three string inputs; nothing in that message says which one broke,
so the operator is left guessing.
The mistake it hides is the obvious one. Documentation shows the input name and
the value together, so `terms_json: [{...}]` gets pasted whole into the value
field, and the parser then chokes on the field name it was handed. Echoing the
first 80 characters back makes that visible immediately.
Also carry a worked example in the manifest — the term that keeps only alerts
attached to an investigation, which is the filter this input mainly exists for —
and say explicitly to paste the array alone.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -54,8 +54,20 @@ def _terms(inp):
|
||||
"""
|
||||
raw = inp.get("terms_json")
|
||||
if raw:
|
||||
parsed = json.loads(raw) if isinstance(raw, str) else raw
|
||||
return parsed if isinstance(parsed, list) else [parsed]
|
||||
if isinstance(raw, str):
|
||||
try:
|
||||
parsed = json.loads(raw)
|
||||
except ValueError as e:
|
||||
# json's own message ("Expecting value: line 1 column 1") names
|
||||
# neither the input nor what it received, so an operator who
|
||||
# pasted the field name along with the value — the obvious
|
||||
# mistake, since both are shown together — gets a parser error
|
||||
# with nothing to act on. Echo the head of what arrived.
|
||||
head = raw[:80] + ("…" if len(raw) > 80 else "")
|
||||
raise ValueError("terms_json is not valid JSON (" + str(e) + "). "
|
||||
"Expected a JSON array of search terms, got: " + head)
|
||||
return parsed if isinstance(parsed, list) else [parsed]
|
||||
return raw if isinstance(raw, list) else [raw]
|
||||
field_ids = _list(inp.get("search_field"))
|
||||
values = _list(inp.get("search_values"))
|
||||
if not field_ids or not values:
|
||||
|
||||
Reference in New Issue
Block a user