DistributedProofreaders / dproofreaders

Distributed Proofreaders is a web application intended to ease the process of converting public domain books into e-texts.
https://www.pgdp.net
GNU General Public License v2.0
46 stars 28 forks source link

Replace die()s with exceptions and fix an assert #1213

Closed cpeel closed 1 month ago

cpeel commented 1 month ago

die()s in functions are a Very Bad Idea because there's no way for callers to capture and do something about the error. They also can cause silent failures by exiting the page without anyone else knowing. This replaces die()s in our include files with exceptions. This does not replace die()s in non-include files. This shouldn't need a lot of (any?) testing as die()s are effectively the same as thrown exceptions from a "stop the world" perspective.

Also replace an assert() that should always be checked. Asserts are only for dev & test and in "production" mode the code within them is not generated or evaluated at all. See https://www.php.net/manual/en/function.assert.php

Sandbox: https://www.pgdp.org/~cpeel/c.branch/die-die-and-asserts/