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.

Output some kind of identity for failing objects

See original GitHub issue

We have the following validation of an input:

public class UserRegisterValidator : AbstractValidator<UserRegister>
    {
        public UserRegisterValidator()
        {
            RuleFor(s => s.Users).SetCollectionValidator(new UserValidator());
        }
    }

public class UserValidator : AbstractValidator<User>
    {
        public UserValidator ()
        {
            RuleFor(s => s.Email).NotEmpty()
        }
    }

This will present the user with messages like

‘Email’ should not be empty.

But who’s email should not be empty?

I’ve seen others getting messages like

'Users[0].Email should not be empty

How can I enable such messages?

But I would like to go one step further. I would like to specify some kind of id for the object, recognizable for the user, like

‘User[John Smith].Email’ should not be empty.

How is that possible?

I guess the answer lies in the PropertyNameResolver, but I’m not sure how…

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
vegarcommented, Jan 17, 2017

Another idea I had, was to create a new WithMessage( ) that get the default message as input:

RuleFor(x => x...).Empty().WithMessage(msg => msg + " (User {0})", x => x.Name)

Allowing for ‘light’ customization of the defaults.

0reactions
JeremySkinnercommented, Jan 17, 2017

Correct, but because it’s separate there’s probably scope for extending it to support this in a similar way to how WithMessage allows custom format options to be applied via the overload of WithMessage that takes an array of lambda expressions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kinematic Equations and Free Fall
Like any moving object, the motion of an object in free fall can be described by four ... The second step involves the...
Read more >
2.7: Falling Objects
Falling objects form an interesting class of motion problems. ... Figure 2.7.1: A hammer and a feather will fall with the same constant ......
Read more >
Dropped Object Prevention: The Definitive Guide
This is the ultimate guide to stopping dropped objects when working at height. First, we'll learn how tools at height present a constant ......
Read more >
How to Implement a Dropped Objects Prevention Plan
First, an “aha!” moment occurs, a sudden bolt of recognition when a site safety manager, supervisor or someone else recognizes dropped objects ...
Read more >
Falling Objects Detection for Near Miss Incidents ...
This paper proposes a deep learning-based video monitoring method to automatically detect and analyze the probable causes of the near miss incident (falling...
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