Replies: 1 comment 6 replies
-
I think everything works, just fix Try constructor using LanguageExt.Common;
using LanguageExt;
using static LanguageExt.Prelude;
using Microsoft.Extensions.Logging;
var logger = LoggerFactory.Create(b =>
{
b.AddConsole();
})
.CreateLogger("test");
string fileName = "some.txt";
var result =
Try(LoadFileUnsafe)
.ToEither(ex =>
new FileNotFoundError(fileName, "File not found", Error.New(ex)))
.MapLeft(err =>
{
if (err is FileNotFoundError fileError)
{
logger.LogError("File error: {@Error}", fileError);
}
return unit;
});
static Unit LoadFileUnsafe() => throw new Exception("Inner ex");
public record FileNotFoundError(string FileName, string Message, Option<Error> Inner) : Expected(Message, 1, Inner); Output:
|
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all,
I created something like this with usage
With logging, the inner details, stack trace etc are missing. What would be the correct way to use it? What am I missing, please?
Also, for certain Exceptions in the
Try
, there is a recursive issue where Serilog will keep on nesting until the not support method exception happens (probably I can apply max depth policy). Example of such exception would be ReaderException for some faulty csv file with the CsvHelper library.Beta Was this translation helpful? Give feedback.
All reactions