editor icon indicating copy to clipboard operation
editor copied to clipboard

fix(core): coerce unknown material.preset to 'custom' (Sentry MONOREPO-EDITOR-DB)

Open anton-pascal opened this issue 5 months ago • 1 comments

Problem

Production editor crashes with an unhandled ZodError during slab boundary edits (Sentry MONOREPO-EDITOR-DB, issue id 7543527892):

ZodError: invalid_value at ["material","preset"]
expected one of white|brick|concrete|wood|glass|metal|plaster|tile|marble|custom

Stack: polygon-editor.tsx → slab/boundary-editor handlePolygonChange → use-scene updateNode → SlabNode.parse.

This happens when node data carries a material.preset value outside the MaterialPreset enum — typically legacy, imported, or AI-generated scenes (e.g. "stone").

Fix

In MaterialSchema, change:

preset: MaterialPreset.optional()

to:

preset: MaterialPreset.catch('custom').optional()

Unknown preset values are now coerced to 'custom' instead of throwing, making loading/updating tolerant of bad data. The exported MaterialPreset enum itself stays strict, so all other consumers keep exact enum validation. resolveMaterial already falls back to DEFAULT_MATERIALS.custom merged with material.properties for 'custom', so coerced materials render with whatever explicit properties the node carries.

Verified undefined handling: missing/undefined preset still parses to undefined (zod v4 .catch() before .optional() does not swallow undefined).

Tests

New packages/core/src/schema/material.test.ts:

  • valid presets pass through unchanged (all 10 enum values)
  • unknown preset ('stone') coerces to 'custom'
  • non-string preset coerces to 'custom'
  • missing / explicit-undefined preset stays undefined

bun test src/schema/ → 50 pass, 0 fail; tsc --build clean; biome check clean.

anton-pascal avatar Jun 12 '26 04:06 anton-pascal

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
pascal 🔴 Failed – Jun 12, 2026, 4:14 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

mintlify[bot] avatar Jun 12 '26 04:06 mintlify[bot]