mvanhorn/last30days-skill · warning · SystemExit

error: {resp['error']}

Error message

error: {resp['error']}

What it means

Not a Python exception - the standalone CLI branch of stocktwits.py prints 'error: <message>' and exits with SystemExit(1) when search_stocktwits returned an 'error' key and zero messages. The error string comes from the dict envelope: either 'no symbol resolved' (no ticker detected) or the stringified exception from a failed stream fetch.

Source

Thrown at skills/last30days/scripts/lib/stocktwits.py:366

        "url": item.url,
        "timestamp": newest or None,
    }


# --------------------------------------------------------------------------- #
# Standalone CLI (ad-hoc use today, before any engine wiring)                  #
#   python3 stocktwits.py "ServiceNow stock"                                   #
# --------------------------------------------------------------------------- #
if __name__ == "__main__":
    topic = " ".join(sys.argv[1:]) or "$NOW"
    if not is_financial_topic(topic) and not detect_symbols(topic, resolve=False):
        print(f"Not a ticker/crypto topic — skipping StockTwits: {topic!r}")
        raise SystemExit(0)
    today = datetime.date.today()
    since = (today - datetime.timedelta(days=30)).isoformat()
    resp = search_stocktwits(topic, from_date=since, depth="default")
    if resp.get("error") and not resp.get("messages"):
        print("error:", resp["error"]); raise SystemExit(1)
    items = parse_stocktwits_response(resp, query=topic)
    agg = aggregate_sentiment(resp["messages"])
    print(f"symbol(s): {resp.get('symbols')} | watchlist {resp.get('watchlist')}")
    print(f"sentiment: {agg['bullish']} bull / {agg['bearish']} bear "
          f"({agg['pct_bullish']}% bullish of tagged) over {agg['sample']} msgs")
    for it in sorted(items, key=lambda x: x["engagement"]["likes"], reverse=True)[:8]:
        s = it["metadata"]["sentiment"] or "-"
        print(f"  [{it['engagement']['likes']}♥ {s}] @{it['author']}: {it['snippet'][:120]}")

View on GitHub (pinned to c7460f6114)

Solutions

  1. Check the exit code ($?) when scripting around this CLI and read the printed error to classify: symbol resolution vs fetch failure
  2. Pass an explicit cashtag ('$NOW') to bypass symbol-detection failures
  3. For fetch failures, retry after a pause or from a different network; for resolution failures, change the topic wording
  4. Prefer importing search_stocktwits and inspecting the returned dict instead of parsing CLI stdout

Example fix

# before
python3 stocktwits.py "how about that stock"  # error: no symbol resolved; exit 1

# after
python3 stocktwits.py "$NOW"  # explicit cashtag, detection bypassed
Defensive patterns

Strategy: validation

Validate before calling

from lib.stocktwits import detect_symbols, _CASHTAG

topic = " ".join(sys.argv[1:]) or "$NOW"
if not _CASHTAG.fullmatch("$" + topic.lstrip("$")) and not detect_symbols(topic):
    print("Not a ticker topic; skipping")
    raise SystemExit(0)

Type guard

def is_cashtag(topic: str) -> bool:
    import re
    return bool(re.fullmatch(r"\$[A-Z]{1,8}", topic.strip().upper()))

Try / catch

resp = search_stocktwits(topic, from_date=since)
if resp.get("error") and not resp.get("messages"):
    # programmatic path: inspect the envelope instead of parsing CLI stdout
    handle_error(resp["error"])

Prevention

When it happens

Trigger: python3 stocktwits.py 'ServiceNow stock' where the topic resolves no symbol, or where the stream fetch raises (network failure, StockTwits block) so the except branch returns messages=[] plus an error string; the CLI then prints the error and exits nonzero.

Common situations: Passing a non-financial phrase that dodges detect_symbols; running the CLI behind a firewall or from a blocked datacenter IP; StockTwits API downtime; empty argv defaulting to $NOW during an outage.

Related errors


AI-assisted analysis of mvanhorn/last30days-skill@c7460f6114 (2026-08-15). Data as JSON: /api/errors/25dfe9f7ff43ac54. Report an issue: GitHub.