{"record":{"id":"cc802dec37af6fba","repo":"rohitg00/ai-engineering-from-scratch","slug":"capacity-must-be-0","errorCode":null,"errorMessage":"capacity must be > 0","messagePattern":"capacity must be > 0","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/11-llm-observability-dashboard/code/ts/src/spans.ts","lineNumber":44,"sourceCode":"  return Number.isFinite(n) && Number.isInteger(n) && n >= 0;\n}\n\nconst TOKEN_KEYS = [\n  \"gen_ai.request.prompt_tokens\",\n  \"gen_ai.usage.input_tokens\",\n  \"gen_ai.request.completion_tokens\",\n  \"gen_ai.usage.output_tokens\",\n  \"gen_ai.usage.total_tokens\",\n];\n\nexport class RingBuffer<T> {\n  private readonly capacity: number;\n  private readonly slots: (T | undefined)[];\n  private writeIdx = 0;\n  private filled = false;\n\n  constructor(capacity: number) {\n    if (capacity <= 0) throw new Error(\"capacity must be > 0\");\n    this.capacity = capacity;\n    this.slots = new Array<T | undefined>(capacity);\n  }\n\n  push(item: T): void {\n    this.slots[this.writeIdx] = item;\n    this.writeIdx = (this.writeIdx + 1) % this.capacity;\n    if (this.writeIdx === 0) this.filled = true;\n  }\n\n  size(): number {\n    return this.filled ? this.capacity : this.writeIdx;\n  }\n\n  isFull(): boolean {\n    return this.filled;\n  }\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/11-llm-observability-dashboard/code/ts/src/spans.ts#L26-L62","documentation":"Error \"capacity must be > 0\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/19-capstone-projects/11-llm-observability-dashboard/code/ts/src/spans.ts:44 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}