question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async Validation via Sequence is Failing.

See original GitHub issue

I ran into this today and thought is was my dummy self 😉

Here’s a repro test that shows turning a Success<string, Task<int>> into a Task<Fail<string, int>> where I fully expect Task<Success<string,int>>.

[Fact]
async Task async_validation_via_sequence()
{
    Task<Validation<string, int>> validation = 
        Success<string, int>(1)
        .Map(x => (x * 2).AsTask())
        .Sequence();

    var result = await validation;
    
    Assert.False(result.IsFail);
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
TysonMNcommented, Jun 14, 2018

Indeed. Here is a slightly shorter MWE.

[Fact]
public async Task ValidationTaskSequence_Success_IsSuccessful()
{
    Task<Validation<string, int>> validation =
        Success<string, Task<int>>(1.AsTask())
        .Sequence();

    var result = await validation;

    Assert.True(result.IsSuccess);
}
0reactions
mario-d-scommented, Jan 26, 2022

@louthy may I ask why this issue was just closed without any solution/workaround? Should we watch #876 instead?

In the meantime, the workaround with Match (actually MatchAsync) that @trbngr mentioned looks like this:

[Fact]
public async Task ValidationTaskSequence_Success_IsSuccessful()
{
    Task<Validation<string, int>> validation =
        Success<string, Task<int>>(1.AsTask())
        .MatchAsync(
            async value => Success<string, int>(await value),
            Validation<string, int>.Fail);

    var result = await validation;

    Assert.True(result.IsSuccess);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Async custom validation causes an error to the console
Async custom validation causes an error to the console: "Cannot read property 'required' of null at Object. eval [as updateDirectives]" So, why ...
Read more >
Message validation in async messaging-based services
This is logic that checks for things like missing/null fields, values outside of certain ranges, bad formatting, etc.
Read more >
Async validator must return a Promise or Observable
Async validators must return a promise or an observable, and emit/resolve them whether the validation fails or succeeds. In particular, they must implement ......
Read more >
Using Custom Async Validators with Angular
While we got the async validation working like a charm, we had another problem: The error messages weren't updating in the view. At...
Read more >
Async validator
This rule was created to prevent long asynchronous validation sequences. ... Async validator. Type name John to fail validation. Validation will take 2 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found