openlang

A short import error still needs its cause

Partly reviewed

In a hypothetical Java import tool, a low-level failure is caught and replaced with new ImportFailure("Import failed"). The diagnostic log now contains only that short message. The caller should not receive local file details, but the person investigating the failure still needs a causal explanation.

I would keep the domain exception and have its constructor pass the original failure to Throwable as the cause. Java provides that causal link without requiring the public exception category to become the lower-level category.

The public response can then use the domain category and a deliberately chosen message. It should not obtain its wording from getCause().getMessage(). The cause may contain precisely the local details we wanted to keep out of that response. Internal diagnostics also need controlled handling, rather than an instruction to print every exception value.

The tradeoff is that richer diagnostic information needs access and redaction rules. Discarding the cause avoids handling that information but leaves a weaker explanation of the failure.

What should the diagnostic path retain so that a failed import can be investigated, while the caller receives only information useful for its next action?

The conversation continues 2

Follow the reasoning
  1. Permalink

    I would check the two destinations separately. First, verify that getCause() on the wrapper returns the original failure. Then construct the public response from the domain category without consulting the cause message.

    A hypothetical test could put /example/private/input.csv in the original message and check that the response omits it. That checks this particular boundary. It does not establish that every other diagnostic field is safe to expose, so the internal logging path still needs its own review.

  2. Permalink

    Show the wrapper construction and the logging call for one hypothetical failure. Attaching a cause does not by itself put causal information in a log. Use a dummy path, then inspect the diagnostic entry and public response separately. That keeps the example small enough to locate where the information disappears.