Skip to content

Throw typed ValidationErrors#1652

Merged
Marsup merged 1 commit intohapijs:v15from
aaronjameslang:1244-validation-error
Nov 19, 2018
Merged

Throw typed ValidationErrors#1652
Marsup merged 1 commit intohapijs:v15from
aaronjameslang:1244-validation-error

Conversation

@aaronjameslang
Copy link
Contributor

See #1244

@Marsup Marsup self-assigned this Nov 15, 2018
@Marsup Marsup added the feature New functionality or improvement label Nov 15, 2018
Copy link
Collaborator

@Marsup Marsup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great! Do you mind writing the docs or should I?

lib/errors.js Outdated

super(message);
this._object = object;
this.annotate = internals.annotate;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think annotate, isJoi and name can be part of the prototype as they don't change between errors. As node still doesn't support class properties I'd suggest attaching it to the prototype like exports.ValidationError.prototype.isJoi = true right after.

I have a doubt about name since it's part of Error so if you can't for this one, leave it be.

@aaronjameslang
Copy link
Contributor Author

Thanks :) I'll have a go at the docs

@aaronjameslang
Copy link
Contributor Author

If I moved the ValidationError into lib/errors/ValidationError.js and errors.js into lib/errors/index.js would there be objections? I tend to like classes in their own files.

@aaronjameslang aaronjameslang force-pushed the 1244-validation-error branch 2 times, most recently from 73bca8a to 30bd0d7 Compare November 15, 2018 09:39
@aaronjameslang
Copy link
Contributor Author

Wasn't sure what approach to take with the docs, it doesn't seem like a breaking change so I just went with 'mention it somewhere'. Let me know what you had in mind.

@Marsup
Copy link
Collaborator

Marsup commented Nov 15, 2018

If I moved the ValidationError into lib/errors/ValidationError.js and errors.js into lib/errors/index.js would there be objections? I tend to like classes in their own files.

None from me 👍

It shouldn't be a breaking change unless people do things like error.hasOwnProperty('isJoi') but I really don't expect that.

As for the docs, the error type should probably appear next to https://github.com/hapijs/joi/blob/master/API.md#version as it's now exported.

@aaronjameslang
Copy link
Contributor Author

I've add a ValidationError section to the list of exports. I wasn't sure how much I could elaborate without duplicating what's already under Errors. To be honest the error docs could use a proper re-format, but I'll do that in a seperate PR to stop the scope of this creeping.

I've not moved ValidationError into its own module for the same reason. I tried it, but that meant I had to factor out something else, which relied on something else and it just snowballed. I'd like to do it, but I'll do it in a different PR. There's a lot of opportunity for non-functional code quality improvements around the errors as well, which I'll do at the same time.

Are there any other changes I should make to this PR? Are the docs OK?

@Marsup
Copy link
Collaborator

Marsup commented Nov 17, 2018

Nope, that's perfect, just a few details to sort out to decide in which release to include this, I'll merge in a bit.

@Marsup Marsup force-pushed the master branch 2 times, most recently from 4a2de06 to a9aa3e7 Compare November 19, 2018 21:17
@Marsup Marsup changed the base branch from master to v15 November 19, 2018 22:14
@Marsup Marsup added this to the 15.0.0 milestone Nov 19, 2018
@Marsup
Copy link
Collaborator

Marsup commented Nov 19, 2018

Out of safety I'm going to set this one for v15 even though I don't personally consider it a breaking change.

@Marsup Marsup merged commit 0043859 into hapijs:v15 Nov 19, 2018
@hueniverse hueniverse added the v16 label Aug 10, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

feature New functionality or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants