Why does most software break or refuse to continue immediately if the folder where their data is stored is not available?

error handlingfile-storage

Most software creates a directory (usually in ~/Library or ~/Library/Application Support in MacOS) to store user preferences, browser history, etc. Most software attempts to create their data directory immediately upon launch and will either crash or refuse to continue if the directory cannot be created.

For example, if I create a file called ~/Library/Application Support/Google, then Google Chrome will be unable to access or create a directory there, because the name is already taken by a non directory. This will cause Google Chrome to immediately 'quit unexpectedly'. If I do the equivalent to Firefox, a message will say that an 'unexpected error has prevented changes from being saved' and will have to quit.

Why would changes have to be saved in software so importantly that the software will break if it cannot? Do they really need to create a bunch of files to render a webpage at a URL? I do not see any way were saving data is critical to the immediate execution of the app. The worst that should happen is all the apps configuration and data should reset as soon as it quits.

Why is it common for apps to break immediately if no data saving directory is available?

Best Answer

In C programming, we have this notion of undefined behavior.

It means that, if you write code that creates situations that are not defined by the language standard, anything can happen. The program could crash, it could corrupt memory, it could accidentally call fireMissiles(). Or, it could exhibit reasonable behavior. There's no way to be sure, once you enter the "undefined behavior" space.

Hence, the simple assumption that a program usually makes that it can access the disk, not an unreasonable assumption in most cases. Most programs will give up if the computer they're running on cannot meet this simple requirement. Continuing to run a program when a machine has been perceived to be compromised in some way can cause all sorts of unforseen problems.

Chrome doesn't make the guarantee that it doesn't save any kind of state at all in incognito mode. It only makes certain assertions about your privacy. Remembering the window location when you close the program doesn't have anything to do with your privacy, and I'm sure there are other examples that I haven't thought of.