Hmbown/CodeWhale · error · Error
Invalid pet raster size.
Error message
Invalid pet raster size.
What it means
terminal() renders the pet as a character-cell raster and validates that width and height are safe integers in [1, 512] before laying out a canvas of width*2 x height*4 pixels. Out-of-range or non-integer dimensions are rejected to prevent zero/negative or absurdly large allocations.
Solutions
- Clamp width and height to integers in [1, 512] before calling terminal().
- Compute dimensions as Math.max(1, Math.floor(value)) and handle undefined/NaN with a default (e.g. 80x24).
- Cap against the 512 limit rather than passing raw terminal size.
- Re-query terminal size on resize events instead of using cached values that may be undefined.
Example fix
// before bridge.terminal(process.stdout.columns, process.stdout.rows); // undefined before first resize // after const w = Math.min(512, Math.max(1, Math.floor(process.stdout.columns ?? 80))); const h = Math.min(512, Math.max(1, Math.floor(process.stdout.rows ?? 24))); bridge.terminal(w, h);
Defensive patterns
Strategy: validation
Validate before calling
function safeRasterSize(w, h) {
const c = (n, d) => Number.isSafeInteger(n) && n >= 1 && n <= 512 ? n : d;
return [c(Math.floor(w), 80), c(Math.floor(h), 24)];
}
const [w, h] = safeRasterSize(cols, rows); Type guard
const isValidRasterDim = (n) => Number.isSafeInteger(n) && n >= 1 && n <= 512;
Try / catch
try {
return bridge.terminal(w, h);
} catch (e) {
if (e.message === 'Invalid pet raster size.') return bridge.terminal(80, 24);
throw e;
} Prevention
- Default to 80x24 when terminal size is undefined (before the first resize event).
- Always floor() and clamp to [1, 512]; never pass fractional cell metrics.
- Recompute size on SIGWINCH/resize instead of caching possibly-undefined values.
When it happens
Trigger: terminal(width, height) called with 0, negative, non-integer (fractional from a resize calculation), NaN, or values above 512 (e.g. a full-screen size on a 4K terminal).
Common situations: Passing process.stdout.columns/rows before the first resize event (undefined -> NaN); floating-point terminal sizes from fractional cell metrics; very large terminal windows exceeding 512 columns/rows.
Related errors
- 1
- A pinned task provider requires an explicit model
- A positive pull request number is required
- A provider and page loader are required.
- accepted_requests must equal requests_attempted; sender…
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/e3e6b10026e6790c.
Report an issue: GitHub.
Appendix: source
Thrown at pet/ios/Resources/pet-native.js:120
}
advanceEngine(timeMs, motion, waiting) {
const target = Math.floor(timeMs * 30 / 1000 + 1e-8);
if (!Number.isFinite(timeMs) || target < this.engineTick || target - this.engineTick > 300)
throw new Error('Engine pet clock jump.');
this.engine.confirmWaiting(timeMs, waiting);
const voices = [];
while (this.engineTick < target) {
if ((this.engineTick + 1) % 12 === 0)
this.world.acceptTelemetry(this.engine.bucket(Math.floor(this.engineTick / 12)));
this.world.step(1 / 30, { motion, sensitivity: 1 });
voices.push(...this.world.voices);
this.engineTick++;
}
this.world.voices = voices;
}
terminal(width, height) {
if (![width, height].every(n => Number.isSafeInteger(n) && n >= 1 && n <= 512))
throw new Error('Invalid pet raster size.');
const { sim, frame } = this.world, l = (0, pet_sim_js_1.layout)(width * 2, height * 4, frame.state);
const cells = Array(width * height).fill(0), bits = [[1, 8], [2, 16], [4, 32], [64, 128]];
sim.p.forEach((p, i) => {
if (frame.state.observed < .92 && i % 2 === 1)
return;
const x = Math.round(l.ox + p.x * l.scale * l.flipX), y = Math.round(l.oy + p.y * l.scale);
if (x >= 0 && x < width * 2 && y >= 0 && y < height * 4)
cells[Math.floor(y / 4) * width + Math.floor(x / 2)] |= bits[y % 4][x % 2];
});
return JSON.stringify({ width, height, cells, timeMs: frame.timeMs, channel: frame.state.channel, arch: pet_sim_js_1.ARCH_OF[frame.state.channel],
hollow: frame.state.observed < .92, dozing: frame.behaviour === 'doze', lit: frame.state.lit });
}
pcmChannels(voicesJSON, startSample, length, rate) {
const p = (0, pet_audio_js_1.renderPetPCM)(JSON.parse(voicesJSON), startSample, length, rate);
return [p.left, p.right];
}
pcm(voicesJSON, startSample, length, rate) {
return JSON.stringify(this.pcmChannels(voicesJSON, startSample, length, rate).map(channel => Array.from(channel)));View on GitHub (pinned to 433685b202)