groupBy errors if value is blank. Breaks site

I fetching a list of child pages grouped by a content field like so:

$pages = $site->page('some/path')->children()->visible()->sortBy('year')->groupBy('year');

However, if a page has a blank “year” field, it’s throwing a fatal error and breaking the entire page.

Uncaught exception 'Exception' with message 'Invalid grouping value for key: some/path/a_page' in /.../kirby/core/pages.php:285

I think there are two options:

  1. Make sure the field is always filled by requiring it
  2. Filter pages with an empty year field
$pages = $site->page('some/path')->children()->visible()->filterBy('year', '!=', '')->sortBy('year')->groupBy('year');

Ok, thanks. Seems easiest to just make it required.