Website crashing when authors are deleted

I’m updating a website I made a couple of years back with Kirby 2.4.1. Here it is:
General Economy

Within it, authors can be added and linked to articles. I had some test authors in place to make sure the functionality worked. Now I’m getting rid of them and it’s throwing errors like on this page:

I managed to handle the error on other pages by using the following code:

               <?php $author = page('authors')->children()->find($article->author()->value()); ?>

            <?php if ($article->author() == str_replace("authors/","", $author)): ?>
              <h4 class="article-author"> <?= $author->title() ?> —</h4>

            <?php endif ?>

Which seems to work on all other pages except the article page. I’ve tried using bool() and exists() and isNotEmpty() but none of it seems to work and just throw the same error.

[EDIT]Here are the other forum questions from 2 years ago related to adding an authoring system if that helps give context:

You don’t check if the author exists, should be something like:

<?php if ($author = page('authors')->children()->find($article->author()->value())): ?>

   <h4 class="article-author"> <?= $author->title() ?> —</h4>

<?php endif ?>

It’s a general rule to always check if an object exists (no matter if your are dealing with pages, files or whatever), before calling any of the methods.

Hmm so now I added your code and it’s throwing a null error:
Call to a member function author() on null

and ah okay, I thought exists and isNotEmpty is how it was checked.

$article is not defined, should probably be $page->author()

:dizzy_face:Solved. Thanks