Hmbown/CodeWhale · error · Error
maxBins must be an integer in [16, 1048576].
Error message
maxBins must be an integer in [16, 1048576].
What it means
buildPyramid validates its maxBins parameter: it must be an integer between 16 and 1,048,576 inclusive. This bound keeps the multi-resolution signal pyramid memory-bounded while ensuring enough resolution levels. Non-integers, values below 16, or values above 1M throw immediately.
Solutions
- Pass an integer maxBins within [16, 1048576], e.g. 16384 (the default).
- Clamp user/config values: Math.min(1_048_576, Math.max(16, Math.round(value))).
- Omit the argument entirely to use the default 16384 instead of passing null/undefined explicitly where a number is required.
Example fix
// before buildPyramid(events, duration, settings.bins); // could be "16384" // after buildPyramid(events, duration, Math.max(16, Math.min(1_048_576, parseInt(settings.bins, 10))));
Defensive patterns
Strategy: validation
Validate before calling
const bins = Math.max(16, Math.min(1_048_576, Math.round(opts.maxBins ?? 16_384)));
if (!Number.isInteger(bins)) throw new TypeError('maxBins must resolve to an integer'); Type guard
const isValidMaxBins = (v) => Number.isInteger(v) && v >= 16 && v <= 1_048_576;
Try / catch
try { buildPyramid(events, d, maxBins) } catch (err) { if (err.message.startsWith('maxBins')) return buildPyramid(events, d); throw err; } Prevention
- Clamp config-driven bin values before calling
- Use the 16384 default unless you have a reason
- Never pass options objects positionally into maxBins
When it happens
Trigger: Calling buildPyramid(events, duration, maxBins) with maxBins = 0, a float like 100.5, a very large value above 1_048_576, or the argument omitted positionally so an options object landed in the maxBins slot.
Common situations: Config-driven bin counts read from user settings without clamping, NaN from a failed parseInt, or swapped arguments when calling with positional parameters.
Related errors
- Codewhale terminal receipt contained an invalid count
- Codewhale terminal receipt exceeded its string bound
- Codewhale terminal receipt exceeded its total bound
- Invalid evidence bundle or record limit exceeded.
- Invalid pet PCM range.
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/67ba41e76c501f2f.
Report an issue: GitHub.
Appendix: source
Thrown at pet/ios/Resources/pet-native.js:1313
exports.chooseLevel = chooseLevel;
exports.binValue = binValue;
exports.intensity = intensity;
exports.totals = totals;
exports.onsetSeries = onsetSeries;
exports.autocorrelation = autocorrelation;
exports.periodogram = periodogram;
exports.unionDuration = unionDuration;
const model_js_1 = require("./model.js");
function emptyLevel(length, binMs) {
const n = model_js_1.CATEGORIES.length * length;
return { binMs, length, onsets: new Float64Array(n), activeMs: new Float64Array(n),
outputTokens: new Float64Array(n), cost: new Float64Array(n), errors: new Float64Array(n), peak: new Float64Array(n) };
}
const FIELDS = ['onsets', 'activeMs', 'outputTokens', 'cost', 'errors'];
/** O(events + channels × bins), including long intervals. No span-length inner loop. */
function buildPyramid(events, requestedDuration, maxBins = 16_384) {
if (!Number.isInteger(maxBins) || maxBins < 16 || maxBins > 1_048_576)
throw new Error('maxBins must be an integer in [16, 1048576].');
let duration = requestedDuration ?? 1;
for (const e of events)
duration = Math.max(duration, e.endTime, e.startTime, e.status === 'error' ? (0, model_js_1.errorOnsetOf)(e) : 0);
if (!Number.isFinite(duration) || duration < 0)
throw new Error('Signal duration must be finite and nonnegative.');
duration = Math.max(1, duration);
const binMs = 2 ** Math.ceil(Math.log2(Math.max(1, duration / (maxBins - 1))));
const length = Math.floor(duration / binMs) + 1, fine = emptyLevel(length, binMs);
const stride = length + 1;
const activeDiff = new Float64Array(model_js_1.CATEGORIES.length * stride), tokenDiff = new Float64Array(model_js_1.CATEGORIES.length * stride);
for (const e of events) {
if (!Number.isFinite(e.startTime) || !Number.isFinite(e.endTime) || e.startTime < 0 || e.endTime < e.startTime)
throw new Error(`Invalid interval for ${e.id}.`);
const channel = model_js_1.CATEGORIES.indexOf(e.category);
if (channel < 0)
throw new Error(`Unknown category for ${e.id}.`);
const a = Math.floor(e.startTime / binMs), b = Math.floor(e.endTime / binMs);
const at = channel * length, diff = channel * stride;View on GitHub (pinned to 433685b202)