{"record":{"id":"9f17ba9387c83801","repo":"shareAI-lab/learn-claude-code","slug":"error-error","errorCode":null,"errorMessage":"error: {error}","messagePattern":"error: (.+?)","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"s17_goal_loop/code.py","lineNumber":882,"sourceCode":"        except (EOFError, KeyboardInterrupt):\n            break\n        if query.strip().lower() in {\"q\", \"quit\", \"exit\"}:\n            break\n        if not query.strip():\n            continue\n        result = await session.submit(query)\n        if result.text:\n            print(result.text)\n        if result.reason:\n            print(f\"[goal] {result.status}: {result.reason}\")\n        print()\n\n\nif __name__ == \"__main__\":\n    try:\n        asyncio.run(main(sys.argv[1:]))\n    except (GoalError, ValueError) as error:\n        raise SystemExit(f\"error: {error}\") from error\n","sourceCodeStart":864,"sourceCodeEnd":883,"githubUrl":"https://github.com/shareAI-lab/learn-claude-code/blob/985456f4adea6f4df8fbad4112245dbd97444eae/s17_goal_loop/code.py#L864-L883","documentation":"This is the top-level CLI exit wrapper (s17_goal_loop/code.py:882): asyncio.run(main(...)) raised a GoalError or ValueError, and the handler converts it into SystemExit with the message prefixed 'error: {error}', printing it to stderr and exiting non-zero. It is a reporting boundary, not an error of its own — the underlying message (e.g. 'MODEL_ID is required...') names the real problem.","triggerScenarios":"Running the module as a script (__main__) with any invalid input: empty goal condition, block_cap/max_turns < 1, missing MODEL_ID, missing dependencies, unknown tool, or a path-escape during a live run. Any GoalError/ValueError raised anywhere under main() lands here.","commonSituations":"First-run setup failures (no .env, deps not installed); bad CLI arguments (empty goal text); runtime tool-misuse errors during an agent session; anything the deeper validation layers already rejected.","solutions":["Read the text after 'error: ' — it is the specific validation message from the deeper layer; fix that cause (see the matching error in this index)","Run with missing-argument validation before main() so usage errors print a usage message instead","For scripted use, call main() via try/except SystemExit to capture the message programmatically"],"exampleFix":"# before\n$ python -m s17_goal_loop.code \"\"\nerror: goal condition cannot be empty\n\n# after\n$ python -m s17_goal_loop.code \"tests pass with pytest\"","handlingStrategy":"try-catch","validationCode":"args = sys.argv[1:]\nif not args or not args[0].strip():\n    raise SystemExit(\"usage: python -m s17_goal_loop.code <goal condition>\")\nif not os.getenv(\"MODEL_ID\") and not Path(\".env\").exists():\n    raise SystemExit(\"configure MODEL_ID in .env before running\")","typeGuard":null,"tryCatchPattern":"try:\n    asyncio.run(main(sys.argv[1:]))\nexcept SystemExit as exit_error:\n    message = str(exit_error)\n    if message.startswith(\"error: \"):\n        handle_root_cause(message[len(\"error: \"):])  # route to the real fix\n    else:\n        raise","preventionTips":["Treat 'error: ...' as a wrapper; always read the suffix, which names the true validation failure","Validate CLI args and env config before main() so setup failures print usage, not raw errors","When embedding the CLI in scripts, catch SystemExit to capture the message for logging"],"tags":["goal-loop","cli","error-handling","exit-code"],"backgroundTag":null,"analyzedSha":"985456f4adea6f4df8fbad4112245dbd97444eae","analyzedAt":"2026-08-14T22:02:26.028Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}