louthy/language-ext · error · Exception
message
Error message
message
What it means
Prelude.failwith(message) returns an Action that, when invoked, throws a plain System.Exception with the given message. The exception is lazy — it only fires when the returned delegate is executed. The message text is whatever the caller passed.
Solutions
- Inspect the message string passed to failwith at the throw site and fix the impossible/unhandled branch it guards
- Catch System.Exception around the delegate invocation if the failure is expected/recoverable
- Prefer failwith<R> in expression positions or replace with proper Result/Option handling
Example fix
// before
Action fail = failwith("unreachable branch"); fail(); // throws Exception
// after
var result = value switch { Some(var x) => x, _ => failwith<int>("unreachable branch") }; // typed Defensive patterns
Strategy: try-catch
Try / catch
try { failAction(); }
catch (Exception ex) { logger.LogWarning("failwith guard hit: {Msg}", ex.Message); }
// note: failwith returns a lazy Action; the throw happens at invocation Prevention
- Remember failwith() is lazy — the exception fires when the Action runs
- Treat failwith sites as exhaustiveness assertions; keep them truly unreachable
- Prefer Fin/Option error channels over exception-based flow
When it happens
Trigger: Calling failwith("...") to produce a throwing Action and then invoking that action (or passing it where an Action is executed, e.g. as a callback).
Common situations: Using failwith in exhaustive switch expressions or as placeholders for impossible branches; the exception surfaces at delegate-invocation time, often far from the failwith call site.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Ord attribute should have a struct type that derives from…
- Hashable attribute should have a struct type that derives…
- Don't use Equals - use either RecordType
- Don't use Equals - use either RecordType
- s
AI-assisted analysis of louthy/language-ext@2f0e362824 (2026-09-15).
Data as JSON: /api/errors/e3ac10f1779be4dc.
Report an issue: GitHub.
Appendix: source
Thrown at LanguageExt.Core/Prelude/Prelude.cs:58
[Pure]
public static Func<A, A> constantA<A>(A x) =>
_ => x;
/// <summary>
/// Constant function
/// Always returns the first argument
/// </summary>
[Pure]
public static A constantA<A>(A x, A _) =>
x;
/// <summary>
/// Raises a lazy Exception with the message provided
/// </summary>
/// <param name="message">Exception message</param>
/// <returns>Action that when executed throws</returns>
public static Action failwith(string message) =>
() => throw new Exception(message);
/// <summary>
/// Raises an Exception with the message provided
/// </summary>
/// <typeparam name="R">The return type of the expression this function is being used in.
/// This allows exceptions to be thrown in ternary operators, or LINQ expressions for
/// example</typeparam>
/// <param name="message">Exception message</param>
/// <returns>Throws an exception</returns>
public static R failwith<R>(string message) =>
throw new Exception(message);
/// <summary>
/// Raises an ApplicationException with the message provided
/// </summary>
/// <typeparam name="R">The return type of the expression this function is being used in.
/// This allows exceptions to be thrown in ternary operators, or LINQ expressions for
/// example</typeparam>View on GitHub (pinned to 2f0e362824)