Skip to content

bug: Try.Run throws when the caught exception's Message is whitespace #273

Description

@Chris-Wolfgang

Symptom

Discovered by FsCheck fuzz property Fuzz_Try_Run_of_throwing_action_carries_message in the #170 batch:

Falsifiable, after 19 tests (0 shrinks):
---- System.ArgumentException : errorMessage cannot be null, empty, or whitespace. (Parameter 'errorMessage')

Repro

Result r = Try.Run(() => throw new InvalidOperationException(" "));
// throws System.ArgumentException instead of returning r.Failed == true

Cause

Try.Run(Action) (src/Wolfgang.TryPattern/Try.cs) catches every Exception and calls Result.Failure(ex.Message). Result.Failure (src/Wolfgang.TryPattern/Result.cs) requires a non-null, non-empty, non-whitespace error message and throws ArgumentException otherwise.

An exception whose Message is whitespace-only (or empty) makes Try.Run itself throw — defeating the whole point of the wrapper. Same failure mode applies to Try.Run<T>, Try.RunAsync, Try.RunAsync<T>.

Suggested fix

In the catch inside every Try.Run* overload, defensively coerce a whitespace / empty / null exception message to a fallback string before handing it to Result.Failure. Candidates:

  • ex.GetType().Name (e.g. "InvalidOperationException").
  • "<exception message was empty or whitespace>".

Scope note

This is exactly the class of edge-case the #170 fuzz workflow was designed to surface. The tightened property in that PR uses a generator that excludes whitespace so the fuzz suite ships clean while this bug is fixed separately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions