-
-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking change: Improved Reader error handling
- Loading branch information
Showing
9 changed files
with
614 additions
and
225 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using static LanguageExt.Prelude; | ||
|
||
namespace LanguageExt.Common | ||
{ | ||
public struct Error | ||
{ | ||
public readonly static Error Bottom = new Error(666, "Bottom", None); | ||
|
||
readonly int code; | ||
readonly string message; | ||
public readonly Option<Exception> Exception; | ||
|
||
Error(int code, string message, Option<Exception> exception) | ||
{ | ||
this.code = code; | ||
this.message = message ?? throw new ArgumentNullException(nameof(message)); | ||
Exception = exception; | ||
} | ||
|
||
public int Code => | ||
message == null | ||
? 666 | ||
: code; | ||
|
||
public string Message => | ||
message ?? "Bottom"; | ||
|
||
public static Error New(int code, string message, Option<Exception> exception) => | ||
new Error(code, message, exception); | ||
|
||
public static Error New(Exception exception) => | ||
new Error(exception.HResult, exception.Message, exception); | ||
|
||
public static Error New(string message, Exception exception) => | ||
new Error(exception.HResult, message, exception); | ||
|
||
public static Error New(string message) => | ||
new Error(0, message, None); | ||
|
||
public static Error New(int code, string message) => | ||
new Error(code, message, None); | ||
|
||
internal Exception ToException() => | ||
Exception.IsSome | ||
? (Exception)Exception | ||
: new Exception(Message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.