An LLM wrote a small helper for some Rye tooling I was working on. The helper looked up an environment variable. If the lookup failed, it returned an empty string.

The caller then checked for an empty string to find out whether the lookup had failed.

Something like this, in Python:

def get_rye_home():
    return os.environ.get("RYE_HOME", "")

home = get_rye_home()
if home == "":
    print("RYE_HOME is not set")

This is ordinary code. You can find versions of it everywhere. It is also a strange little round trip: we discard the information that an operation failed, then inspect its replacement value to try to recover that information.

The problem isn’t the empty string itself. It’s that we have quietly made it mean two things.

A value with a secret second job

An environment variable can be missing. It can also be present and contain an empty string. Depending on what the variable is for, those states might deserve the same treatment—or quite different treatment.

Our helper has already decided that they are indistinguishable. Its caller cannot change that decision.

And the return value now comes with an unwritten protocol:

This function returns a string, except that one particular string means it didn’t really return a string successfully.

Every caller has to know that protocol. A caller that doesn’t know it may happily join the empty string with a filename and look in the current directory instead of the intended installation directory.

We haven’t eliminated error handling. We’ve moved it into a convention about an otherwise valid value.

Sometimes that is a deliberate API design. Often it is just a fallback added to make the immediate error go away.

The same mistake, with more convincing values

Empty strings are relatively easy to suspect. Other replacements look perfectly respectable:

def load_config(path):
    try:
        with open(path) as f:
            return json.load(f)
    except (OSError, ValueError):
        return {}

Now these all produce the same result:

  • The file contains an empty configuration.
  • The file doesn’t exist.
  • The process cannot read it.
  • The file contains malformed JSON.

The program continues. Perhaps it even works—with default settings instead of the settings someone deliberately supplied.

Or consider an API client:

def fetch_orders():
    try:
        return request_orders()
    except RequestError:
        return []

There is a substantial difference between “there are no orders” and “we don’t know whether there are orders.” The empty list turns the second statement into the first.

A report built from that result may look entirely successful. It is just wrong.

A failure that stops a report is visible. A failure converted into plausible data can travel much further.

The familiar version: NULL

There is a much more famous value with a secret second job: NULL, the null reference Tony Hoare called his “billion-dollar mistake.”

Unlike an empty string, null doesn’t pretend to be a string. But when used as the result of an unsuccessful operation, it has a related problem: it tells us that something is absent, without telling us why.

Did the lookup find nothing? Was access denied? Has the value not been initialized yet? Did a dependency fail?

A particular API may document one precise meaning. Too often, though, the meaning is an assumption shared between the person who wrote the function and the person calling it. The value itself carries none of that explanation.

And in languages that allow unchecked nulls, it can travel. One function returns it, another stores it, another passes it along. Eventually some unrelated-looking operation tries to use it and fails. The place where the program finally trips over the missing value may be far from the place where its meaning was known.

This isn’t an argument that every absence is a failure. An optional middle name really can be absent. An explicit optional type can express that contract and require the caller to consider it. The problem is using an unexplained, freely passable absence to represent an operation that could not produce its result.

Replacing that null with "" or {} doesn’t solve the problem. It can make the missing result even harder to notice.

Recovery is a decision, not a conversion

This doesn’t mean a failed lookup should always stop the program. Defaults are useful. Empty collections are useful. Recovery is useful.

But recovery requires knowing what the result is for.

Suppose RYE_HOME is missing:

  • An interactive setup tool might ask the user for a directory.
  • A diagnostic command might report the problem and continue checking other things.
  • An installer might use a documented default location.
  • A deployment script might need to stop immediately.

A helper whose job is “look up RYE_HOME” doesn’t necessarily know which of those policies is appropriate.

Its most useful answer is the information it actually has: a value, or a failed lookup.

The caller can then make a decision with more context.

Choose a default where you know it is an acceptable substitute—not merely where you first encounter a failure.

That boundary isn’t always far away. Sometimes the lookup and the policy belong on the same line. The point is not to propagate every failure through ten layers. It is to avoid discarding information before making a deliberate decision about it.

What this looks like in Rye

Rye is the scripting language I’m working on. It has no NULL. When a function cannot produce its result, it produces a failure instead.

A failure is specific information, not just a marker for absence. It can describe what went wrong, contain an underlying failure, and be wrapped with context as it moves back toward the caller. Error-handling functions can inspect it, recover from it, or explicitly return it onward.

The original helper used fix, which evaluates a recovery block when an operation fails:

get-rye-home: does {
    os/env? "RYE_HOME" |fix { "" }
}

The problem isn’t fix. It does exactly what we asked: replace a failure with a successful value.

The problem is that we haven’t actually recovered. We have no usable home directory. We have only made the result look more ordinary.

If the helper’s responsibility is just the lookup, it should preserve the failure and explicitly return it, rather than substitute an empty string:

get-rye-home: does {
    os/env? "RYE_HOME" |^check "Cannot determine Rye home"
}

Here the helper adds context without choosing a fallback. We can also omit the helper and call os/env? directly at the point where we will handle its result.

Now a caller that really has a fallback can choose it:

home: get-rye-home |fix { default-rye-home }

Here default-rye-home stands for the application’s own fallback policy. Whether that is sensible depends on the application, not on the availability of fix.

A caller that requires the variable can instead add context and return the failure:

require-rye-home: does {
    get-rye-home |^check "RYE_HOME is required for this operation"
}

^check adds context to a failure and returns early from the enclosing function. On success, it passes the value through. The ^ marks the returning behavior.

Neither approach is universally better. They express different decisions:

  • fix: I can provide an acceptable alternative.
  • ^check: I cannot complete this operation; here is why this failure matters.

The useful distinction isn’t between short and verbose error handling. It’s between recovering from a failure and disguising one.

A failure cannot quietly travel as ordinary data

There is another part of Rye’s design that matters here. Its failures are values, but they are not freely passable substitutes for successful results.

A failure must be handled by a failure-handling function, such as fix or check, or explicitly returned from the enclosing function. If code instead passes an unhandled failure to an ordinary function or tries to use it as an ordinary result, Rye turns that unhandled state into an error and stops execution.

That is a deliberate distinction between two things:

  • An operation failed: something the program can account for, recover from, or report to its caller.
  • The program continued without handling that failure: a bug in the program.

A missing environment variable is not necessarily a programming bug. Trying to carry on with its failed lookup as though we had obtained a usable path is.

This means a failure cannot take the usual unchecked-null journey through ordinary functions, waiting to break something much later. It can move outward, but only through explicit failure handling and return—not by accidentally blending into the successful dataflow.

As it moves outward, it can also accumulate useful context. Conceptually, a nested failure might say:

Cannot initialize the tool
  because: Cannot determine Rye home
    because: Environment variable RYE_HOME is not set

Each layer explains what the underlying failure means for its own operation. We keep the original reason instead of replacing it with a generic absence.

These two properties work together: failures carry information, and the runtime requires code to acknowledge them. A richly described failure that could be silently ignored would solve only half the problem.

This also makes the original fix { "" } more revealing. It doesn’t just discard a diagnostic. It tells the runtime that recovery succeeded. Once we substitute a string, the runtime has no reason to stop us from using it as a string.

The language can require us to handle a failure. It cannot guarantee that the recovery we choose makes sense.

Missing is not the same as invalid

Preserving the lookup failure is only the first step.

What if RYE_HOME exists but is empty? What if it names a file instead of a directory? What if the directory exists but lacks something this operation needs?

Those are validation questions, not lookup questions.

A useful sequence is:

  1. Look up the variable.
  2. Require a non-empty value.
  3. Check that it names an existing directory.
  4. Check whatever this particular operation needs from that directory.

The diagnostics should preserve those distinctions:

RYE_HOME is not set
RYE_HOME is set, but empty
RYE_HOME points to a directory that does not exist: /opt/rye
RYE_HOME does not contain the runtime required by this operation

It would be easy to perform all four checks and then attach “RYE_HOME is not set” to any failure. That would repeat the original mistake at a different level: we would preserve failure as a category while throwing away its meaning.

Adding context should explain an error, not overwrite it with a guess.

Also, checking a directory now doesn’t guarantee it will still be accessible when we use it. Validation improves the diagnosis; the eventual file operation still needs its own failure handling.

When a fallback really is success

There are plenty of cases where replacing a failure is the right thing to do.

An optional user configuration file might have an explicit contract:

If the file does not exist, use the built-in settings.

Then a missing file is a legitimate reason to select those settings. A malformed file is not necessarily the same thing:

def load_optional_config(path):
    try:
        with open(path) as f:
            return json.load(f)
    except FileNotFoundError:
        return {}

This fallback is narrower. It doesn’t silently treat a permissions problem or a syntax error as an empty configuration.

Likewise, serving cached data after a network failure may be an excellent recovery strategy. But if freshness matters to the caller, the result should communicate that the data is stale. Successful recovery doesn’t require pretending nothing happened.

And a convenience function that returns an empty string for both missing and empty environment variables can be perfectly reasonable if that equivalence is its documented purpose. The mistake is making that decision accidentally, then expecting callers to reconstruct the distinction.

Keep the information until you can use it

There is a temptation to measure error handling by how little of it remains visible. A helper catches an error, returns something familiar, and makes the caller look cleaner.

But clean-looking code isn’t enough. The caller also needs an honest answer.

When reviewing a fallback, I now find these questions more useful than “did we handle the error?”:

  • Is this replacement a result the caller can legitimately use?
  • Can the caller distinguish it from a normal result, if that matters?
  • Are we handling a specific condition, or hiding several unrelated failures?
  • Will the next layer inspect this value just to rediscover the failure we removed?

That last question caught the problem in the RYE_HOME helper. We weren’t simplifying anything. We were translating a failure into an empty string and then translating it back, with less information each time.

Rye’s answer has two parts: no null standing in for an unexplained missing result, and no unhandled failure quietly passing through ordinary code. Keep the reason, and require an explicit decision about what happens next.

But we can still defeat both properties with one convenient fallback. fix { "" } is an explicit decision—it just may be the wrong one.

A fallback should mean “we can still do the job,” not merely “we can keep executing.”