isomerpages / isomercms-backend

A static website builder and host for the Singapore Government
5 stars 1 forks source link

fix(directory): default to empty array #777

Closed seaerchin closed 1 year ago

seaerchin commented 1 year ago

Problem

Directory.list can return an empty object. However, our frontend expects an empty array (it calls val.map), which causes it to crash on an empty object returned.

Solution

Change the default empty object return to empty array. this is safe because the call sites for Directory.list uses a .reduce with [] as the base acc, showing that they expect empty array (<Collection | Subfolder>.js). The callsite in directory.js also uses an empty array as the base if there's an error thrown during .list (this bug might appear there too).

Testing

verified by @kishore03109