DEV Community

ENAMETOOLONG: how one dirty database field crashed our static build

At podbor-minuta.ru about 600 apartment listing pages are built ahead of time into static HTML. Each page address is built from data: city, district or metro, room count, price. For example, /novostroyki/rayon/nagatino/2-komnatnye. One day the build crashed with ENAMETOOLONG, file name too long. Here is how it happened. We collect apartment data automatically from several sites. In one record the district field held a whole sentence from a description instead of a district name, about 295 characters, something like "prices in nearby projects start from 8.9 million for a one-room with finishing". Our page generator took that field and made it part of an address. The static builder (Vike) creates a directory on disk for each address. A directory name in the filesystem cannot be longer than 255 bytes. 295 characters, once encoded, is well past that. mkdir fails, and the whole build fails with it. Why we did not catch it right away. The build runs in Docker. The static-build layer was cached, so for a while the step was skipped and the error was invisible. Locally the build sometimes did not reach that point because the data fetch stalled and the broken page never made it into the set. The error only showed up on a clean build in CI. What we fixed. Two things. First, a length guard right in the address generator. Any address segment longer than a sane limit is dropped and the page is not created: function isSafeSegment(seg: string): boolean { return seg.length > 0 && seg.length <= 120; } 120 characters is well under the filesystem limit, and real district and station names are shorter. Second, cleaning at the source. We did not want to just hide bad data, so we filtered the junk where the district is read from the database: a value that looks like a description sentence (too long, with digits and words like "rubles", "apartments", "finishing") never enters the listings. This also removed dozens of thin empty pages that such junk produced. What to take from this. In a static site any field from your database eventually becomes part of a file name. Data you do not control (from scraping, from users) has to be checked and trimmed before it turns into an address or a path. And one bad record should not crash the whole build, better to skip it than to fall over completely. The site is podbor-minuta.ru, daily price monitoring for Moscow new builds. Top comments (0)

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.