Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol. wisp.place

gracefully error on unparsable .meta file

+14 -2
+14 -2
packages/@wispplace/tiered-storage/src/tiers/S3StorageTier.ts
··· 236 236 ]); 237 237 238 238 const json = new TextDecoder().decode(metaBuffer); 239 - const metadata = JSON.parse(json) as StorageMetadata; 239 + let metadata: StorageMetadata; 240 + try { 241 + metadata = JSON.parse(json) as StorageMetadata; 242 + } catch { 243 + // Corrupted or partial .meta file — return null so the caller 244 + // falls through to on-demand fetch rather than serving bad data. 245 + return null; 246 + } 240 247 metadata.createdAt = new Date(metadata.createdAt); 241 248 metadata.lastAccessed = new Date(metadata.lastAccessed); 242 249 if (metadata.ttl) { ··· 587 594 588 595 const buffer = await this.streamToUint8Array(response.Body as Readable); 589 596 const json = new TextDecoder().decode(buffer); 590 - const metadata = JSON.parse(json) as StorageMetadata; 597 + let metadata: StorageMetadata; 598 + try { 599 + metadata = JSON.parse(json) as StorageMetadata; 600 + } catch { 601 + return null; 602 + } 591 603 592 604 metadata.createdAt = new Date(metadata.createdAt); 593 605 metadata.lastAccessed = new Date(metadata.lastAccessed);