{"record":{"id":"e992d050d8c65434","repo":"emirpasic/gods","slug":"invalid-maxsize-should-be-at-least-1","errorCode":null,"errorMessage":"Invalid maxSize, should be at least 1","messagePattern":"Invalid maxSize, should be at least 1","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"queues/circularbuffer/circularbuffer.go","lineNumber":38,"sourceCode":"\n// Assert Queue implementation\nvar _ queues.Queue[int] = (*Queue[int])(nil)\n\n// Queue holds values in a slice.\ntype Queue[T comparable] struct {\n\tvalues  []T\n\tstart   int\n\tend     int\n\tfull    bool\n\tmaxSize int\n\tsize    int\n}\n\n// New instantiates a new empty queue with the specified size of maximum number of elements that it can hold.\n// This max size of the buffer cannot be changed.\nfunc New[T comparable](maxSize int) *Queue[T] {\n\tif maxSize < 1 {\n\t\tpanic(\"Invalid maxSize, should be at least 1\")\n\t}\n\tqueue := &Queue[T]{maxSize: maxSize}\n\tqueue.Clear()\n\treturn queue\n}\n\n// Enqueue adds a value to the end of the queue\nfunc (queue *Queue[T]) Enqueue(value T) {\n\tif queue.Full() {\n\t\tqueue.Dequeue()\n\t}\n\tqueue.values[queue.end] = value\n\tqueue.end = queue.end + 1\n\tif queue.end >= queue.maxSize {\n\t\tqueue.end = 0\n\t}\n\tif queue.end == queue.start {\n\t\tqueue.full = true","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/emirpasic/gods/blob/1d83d5ae39fbb0de45a60365791ff1c8b9bae953/queues/circularbuffer/circularbuffer.go#L20-L56","documentation":"A programming-time guard panic raised by circularbuffer.New when the maxSize argument is less than 1. A circular buffer is a fixed-capacity structure: the backing slice and index wrap-around arithmetic (end/start modulo maxSize) are meaningless for a zero or negative capacity, and zero would make the buffer permanently full/broken, so the constructor refuses such arguments instead of returning a broken queue.","triggerScenarios":"Thrown at queues/circularbuffer/circularbuffer.go:38 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a maxSize of at least 1 when calling circularbuffer.New (e.g. New[int](16) for a 16-element ring buffer).","Validate the capacity before constructing: if maxSize < 1 { return fmt.Errorf(...) } or clamp it, e.g. max(maxSize, 1), at the call site.","Compute the capacity rather than hardcoding it and check it is positive; trace where a zero/negative value originates (config, environment variable, length of an empty slice)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1d83d5ae39fbb0de45a60365791ff1c8b9bae953","analyzedAt":"2026-09-03T13:39:53.396Z","contentChangedAt":"2026-09-03T13:39:53.396Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}