In using LanguageExt, I am trying to display just the error message of a failed validation from using Validation<Error,Unit> in LanguageExt.
However, I get the following string:
ValidationData(Fail, 0, [Starting number is not a valid number])
I can't seem to find a way to get just the error message which is
Starting number is not a valid number
Can anyone provide any advice on how to do this?
Here's a snippet of the code
ValidateStartingNumberError(int number)
.Match(
() => None,
error => DisplayError(error.ToString())
);
private Validation<Error, Unit> ValidateStartingNumberError(int number)
=> int.TryParse(this.number, out var parsedNumber) ?
unit :
Fail<Error,Unit>("Starting number is not a valid number");
private void DisplayError(string message)=> MessageBox.Show(message);
In using LanguageExt, I am trying to display just the error message of a failed validation from using Validation<Error,Unit> in LanguageExt.
However, I get the following string:
ValidationData(Fail, 0, [Starting number is not a valid number])
I can't seem to find a way to get just the error message which is
Starting number is not a valid number
Can anyone provide any advice on how to do this?
Here's a snippet of the code
ValidateStartingNumberError(int number)
.Match(
() => None,
error => DisplayError(error.ToString())
);
private Validation<Error, Unit> ValidateStartingNumberError(int number)
=> int.TryParse(this.number, out var parsedNumber) ?
unit :
Fail<Error,Unit>("Starting number is not a valid number");
private void DisplayError(string message)=> MessageBox.Show(message);
Share
Improve this question
edited Nov 20, 2024 at 11:21
Jeremy Loh
asked Nov 20, 2024 at 8:38
Jeremy LohJeremy Loh
1951 silver badge12 bronze badges
3
|
2 Answers
Reset to default 0Looking at the documentation I think that you need the Message
property:
ValidateStartingNumberError(int number)
.Match(
() => None,
error => DisplayError(error.Message)
);
Found the reason: I implemented the wrong .Match
(...). It should be
ValidateStartingNumberError(int number)
.Match(
_ => None,
error => DisplayError(error.Head.Message)
);
DisplayError
and what isFail<Error,Unit>
? – shingo Commented Nov 20, 2024 at 9:39DisplayError
included. Fail<Error,Unit> is a class part of Language-Ext library – Jeremy Loh Commented Nov 20, 2024 at 11:22new
keyword? – shingo Commented Nov 20, 2024 at 11:31