rohitg00/ai-engineering-from-scratch · error · Error

capacity must be > 0

Error message

capacity must be > 0

What it means

Error "capacity must be > 0" thrown in rohitg00/ai-engineering-from-scratch.

Source

Thrown at phases/19-capstone-projects/11-llm-observability-dashboard/code/ts/src/spans.ts:44

  return Number.isFinite(n) && Number.isInteger(n) && n >= 0;
}

const TOKEN_KEYS = [
  "gen_ai.request.prompt_tokens",
  "gen_ai.usage.input_tokens",
  "gen_ai.request.completion_tokens",
  "gen_ai.usage.output_tokens",
  "gen_ai.usage.total_tokens",
];

export class RingBuffer<T> {
  private readonly capacity: number;
  private readonly slots: (T | undefined)[];
  private writeIdx = 0;
  private filled = false;

  constructor(capacity: number) {
    if (capacity <= 0) throw new Error("capacity must be > 0");
    this.capacity = capacity;
    this.slots = new Array<T | undefined>(capacity);
  }

  push(item: T): void {
    this.slots[this.writeIdx] = item;
    this.writeIdx = (this.writeIdx + 1) % this.capacity;
    if (this.writeIdx === 0) this.filled = true;
  }

  size(): number {
    return this.filled ? this.capacity : this.writeIdx;
  }

  isFull(): boolean {
    return this.filled;
  }

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at phases/19-capstone-projects/11-llm-observability-dashboard/code/ts/src/spans.ts:44 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/cc802dec37af6fba. Report an issue: GitHub.