Hmbown/CodeWhale · error

should error on empty queue

Error message

should error on empty queue

What it means

Panic in the MockLlmClient test errors_when_queue_exhausted. MockLlmClient::new(Vec::new()) is created with no canned responses, so create_message_stream must return Err (containing "no canned"). The panic fires if the mock unexpectedly returned Ok despite an empty queue — meaning the exhausted-queue error path regressed.

Solutions

  1. Check MockLlmClient::create_message_stream still returns the "no canned" error when the queue is empty.
  2. Ensure the new synthesis path (create_message_synthesizes_from_streaming_turn) is not applied inside create_message_stream, or split the tests.
  3. If empty-queue Ok is now intended, rewrite the test for the new contract.

Example fix

// before
Ok(_) => panic!("should error on empty queue"),
// after
Ok(resp) => panic!("should error on empty queue, got response with {} blocks", resp.content.len()),
Defensive patterns

Strategy: try-catch

Validate before calling

// caller-side: never construct MockLlmClient with an empty queue unless you expect the error
assert!(!responses.is_empty(), "mock created with empty queue; create_message_stream will fail");

Type guard

fn is_no_canned(err: &LlmError) -> bool { format!("{err}").contains("no canned") }

Try / catch

match mock.create_message_stream(req).await { Ok(_) => panic!("should error on empty queue"), Err(e) => assert!(format!("{e}").contains("no canned")) }

Prevention

When it happens

Trigger: Creating MockLlmClient with an empty response queue and calling create_message_stream; the mock returns Ok(_) instead of an error mentioning "no canned".

Common situations: Refactoring the mock to synthesize streaming turns from requests changed behavior so it no longer errors on an empty queue; someone added a default canned response.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/5a777e5978cb4c45. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/llm_client/mock.rs:539

                    break;
                }
                _ => {}
            }
        }

        assert_eq!(text, "hello world");
        assert!(saw_stop);
        assert_eq!(mock.call_count(), 1);
        assert_eq!(mock.captured_requests().len(), 1);
        assert_eq!(mock.remaining_turns(), 0);
    }

    #[tokio::test]
    async fn errors_when_queue_exhausted() {
        let mock = MockLlmClient::new(Vec::new());
        let result = mock.create_message_stream(empty_request()).await;
        match result {
            Ok(_) => panic!("should error on empty queue"),
            Err(err) => assert!(format!("{err}").contains("no canned")),
        }
    }

    #[tokio::test]
    async fn captures_request_payload_for_assertions() {
        let mock = MockLlmClient::new(vec![canned::simple_text_turn("ok")]);
        let mut req = empty_request();
        req.temperature = Some(0.42);
        let _ = mock.create_message_stream(req).await.unwrap();

        let captured = mock.last_request().expect("should have captured");
        assert_eq!(captured.temperature, Some(0.42));
    }

    #[tokio::test]
    async fn stream_auto_appends_message_stop() {
        // Queue a turn missing MessageStop — mock should append one.

View on GitHub (pinned to 433685b202)