shareAI-lab/learn-claude-code · error · GoalError

goal condition cannot be empty

Error message

goal condition cannot be empty

What it means

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.

Source

Thrown at s17_goal_loop/code.py:285

        block_cap: int = DEFAULT_STOP_HOOK_BLOCK_CAP,
        events: list[dict[str, Any]] | None = None,
    ):
        if block_cap < 1:
            raise GoalError("block_cap must be at least 1")
        self.evaluator = evaluator
        self.block_cap = block_cap
        self.events = events if events is not None else []
        self.active: GoalState | None = None
        self.last_status: dict[str, Any] | None = None
        self.consecutive_blocks = 0

    def begin_query(self) -> None:
        self.consecutive_blocks = 0

    def set_goal(self, condition: str, tokens_at_start: int = 0) -> GoalState:
        condition = condition.strip()
        if not condition:
            raise GoalError("goal condition cannot be empty")
        if len(condition) > MAX_GOAL_LENGTH:
            raise GoalError(
                f"goal condition cannot exceed {MAX_GOAL_LENGTH} characters"
            )
        if self.active is not None:
            self._record(
                active=False,
                met=False,
                failed=False,
                reason="replaced by a new goal",
            )
        self.active = GoalState(
            condition=condition,
            iterations=0,
            set_at=time.time(),
            tokens_at_start=tokens_at_start,
        )
        self.consecutive_blocks = 0

View on GitHub (pinned to 985456f4ad)

Solutions

  1. Check the condition is non-empty before calling set_goal
  2. Default to a concrete goal constant when the source field is missing
  3. Validate at the CLI boundary: fail with a usage message when the goal argument is absent

Example fix

# before
session.goal.set_goal(args.goal or "")

# after
if not (args.goal or "").strip():
    raise SystemExit("usage: provide a goal condition")
session.goal.set_goal(args.goal)
Defensive patterns

Strategy: validation

Validate before calling

condition = (raw_goal or "").strip()
if not condition:
    raise SystemExit("a non-empty goal condition is required")
goal_state = controller.set_goal(condition)

Type guard

def is_non_empty_goal(condition: object) -> bool:
    return isinstance(condition, str) and len(condition.strip()) > 0

Try / catch

try:
    controller.set_goal(condition)
except GoalError as error:
    raise SystemExit(f"invalid goal: {error}") from error

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of shareAI-lab/learn-claude-code@985456f4ad (2026-08-14). Data as JSON: /api/errors/e75e00a0fb9552a6. Report an issue: GitHub.