{"record":{"id":"e75e00a0fb9552a6","repo":"shareAI-lab/learn-claude-code","slug":"goal-condition-cannot-be-empty","errorCode":null,"errorMessage":"goal condition cannot be empty","messagePattern":"goal condition cannot be empty","errorType":"validation","errorClass":"GoalError","httpStatus":null,"severity":"error","filePath":"s17_goal_loop/code.py","lineNumber":285,"sourceCode":"        block_cap: int = DEFAULT_STOP_HOOK_BLOCK_CAP,\n        events: list[dict[str, Any]] | None = None,\n    ):\n        if block_cap < 1:\n            raise GoalError(\"block_cap must be at least 1\")\n        self.evaluator = evaluator\n        self.block_cap = block_cap\n        self.events = events if events is not None else []\n        self.active: GoalState | None = None\n        self.last_status: dict[str, Any] | None = None\n        self.consecutive_blocks = 0\n\n    def begin_query(self) -> None:\n        self.consecutive_blocks = 0\n\n    def set_goal(self, condition: str, tokens_at_start: int = 0) -> GoalState:\n        condition = condition.strip()\n        if not condition:\n            raise GoalError(\"goal condition cannot be empty\")\n        if len(condition) > MAX_GOAL_LENGTH:\n            raise GoalError(\n                f\"goal condition cannot exceed {MAX_GOAL_LENGTH} characters\"\n            )\n        if self.active is not None:\n            self._record(\n                active=False,\n                met=False,\n                failed=False,\n                reason=\"replaced by a new goal\",\n            )\n        self.active = GoalState(\n            condition=condition,\n            iterations=0,\n            set_at=time.time(),\n            tokens_at_start=tokens_at_start,\n        )\n        self.consecutive_blocks = 0","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/shareAI-lab/learn-claude-code/blob/985456f4adea6f4df8fbad4112245dbd97444eae/s17_goal_loop/code.py#L267-L303","documentation":"GoalController.set_goal was called with a condition that is empty after stripping whitespace (s17_goal_loop/code.py:285). The condition string is the verifiable predicate the evaluator judges against, so an empty condition cannot ever be evaluated and is rejected immediately.","triggerScenarios":"Calling set_goal(\"\"), set_goal(\"   \"), or set_goal with a value derived from user input or an env/config field that trimmed to nothing (e.g. passing a CLI argument that was never supplied).","commonSituations":"Forwarding sys.argv or CLI flags into set_goal without checking presence; reading the goal from a config file with a missing key (defaulting to ''); building the goal string by concatenation/f-string where all components are empty.","solutions":["Check the condition is non-empty before calling set_goal","Default to a concrete goal constant when the source field is missing","Validate at the CLI boundary: fail with a usage message when the goal argument is absent"],"exampleFix":"# before\nsession.goal.set_goal(args.goal or \"\")\n\n# after\nif not (args.goal or \"\").strip():\n    raise SystemExit(\"usage: provide a goal condition\")\nsession.goal.set_goal(args.goal)","handlingStrategy":"validation","validationCode":"condition = (raw_goal or \"\").strip()\nif not condition:\n    raise SystemExit(\"a non-empty goal condition is required\")\ngoal_state = controller.set_goal(condition)","typeGuard":"def is_non_empty_goal(condition: object) -> bool:\n    return isinstance(condition, str) and len(condition.strip()) > 0","tryCatchPattern":"try:\n    controller.set_goal(condition)\nexcept GoalError as error:\n    raise SystemExit(f\"invalid goal: {error}\") from error","preventionTips":["Validate CLI/config goal fields at the boundary before touching the controller","Fail with a usage message when the goal argument is missing instead of defaulting to ''","Strip whitespace once at input time so the controller never sees a blank string"],"tags":["goal-loop","validation","input"],"backgroundTag":null,"analyzedSha":"985456f4adea6f4df8fbad4112245dbd97444eae","analyzedAt":"2026-08-14T22:02:26.028Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}