Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to override/remove type label in error message #200

Open
taylorjdawson opened this issue Jan 22, 2021 · 2 comments
Open

Add option to override/remove type label in error message #200

taylorjdawson opened this issue Jan 22, 2021 · 2 comments

Comments

@taylorjdawson
Copy link

taylorjdawson commented Jan 22, 2021

Currently when a predicate is failed by returning a message the type is pre-pended to the message like so:

const greaterThan = (max: number, x: number) => {
	return x > max || `Expected \`${x}\` to be greater than \`${max}\``;
};

ow(5, ow.number.is(x => greaterThan(10, x)));
// => ArgumentError: (number) Expected `5` to be greater than `10`

and if a custom label is added:

ow(5, 'custom label', ow.number.is(x => greaterThan(10, x)));
// => ArgumentError: (number `custom label`) Expected `5` to be greater than `10`

I would love the option to override/remove as I want to send this error message back to the client and having the type there would be context leak e.g. the client has no need to know backend type implementations.

@sindresorhus
Copy link
Owner

Any suggestions on how to best resolve this?

@taylorjdawson
Copy link
Author

What about the option to call ow without a type?

ow(5, ow.is(x => greaterThan(10, x)));
// => ArgumentError: Expected `5` to be greater than `10`

ow(5, 'custom label', ow.is(x => greaterThan(10, x)));
// => ArgumentError: (custom label) Expected `5` to be greater than `10`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants