-
-
Notifications
You must be signed in to change notification settings - Fork 935
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
Throw more useful errors for request validation #1257
Comments
I knew someone would raise an issue about this someday... See sindresorhus/is#107 |
Currently dealing with this. Error log{
"error": "Expected value which is `predicate returns truthy for any value`, received values of types `string`.",
"stack": "TypeError: Expected value which is `predicate returns truthy for any value`, received values of types `string`.\n at assertType (/usr/src/app/packages/server/node_modules/@sindresorhus/is/dist/index.js:293:15)\n at Object.any (/usr/src/app/packages/server/node_modules/@sindresorhus/is/dist/index.js:386:16)\n at normalizeArguments (/usr/src/app/packages/server/node_modules/got/dist/source/core/index.js:386:21)\n at mergeOptions (/usr/src/app/packages/server/node_modules/got/dist/source/create.js:39:25)\n at Function.got.extend (/usr/src/app/packages/server/node_modules/got/dist/source/create.js:151:22)\n at new REDACTED (/usr/src/app/packages/server/node_modules/_REDACTED_/dist/index.js:31:38)\n at boot (/usr/src/app/packages/server/dist/app.js:180:22)\n at Object.<anonymous> (/usr/src/app/packages/server/dist/app.js:239:9)\n at Module._compile (internal/modules/cjs/loader.js:1085:14)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)",
"level": "error",
"message": "startup error"
} Relevant LOCsassert(this.options.token, 'Token required')
assert(this.options.url, 'URL required')
const prefixUrl = new URL(this.options.url)
this.request = got.extend({
prefixUrl,
timeout: this.options.timeout || DEFAULT_TIMEOUT,
headers: {
Authorization: `Bearer ${this.options.token}`
}
}) Would hugely appreciate it if |
In my case, a string was being passed as |
In my case I was migrating from axios and had to change |
I also spent a long time debugging an issue (after upgrading to 12.0.1) where by the looks of it I was getting:
There was no mention of this in the Breaking Changes, at least not that I could fathom. |
GAH! Thanks, @movy. That appears to have been my exact problem! I was confused because a quick glance at the docs for Options make like Alas, as you've pointed out, the fix was as simple as using Of course, arguably the best solution would be to improve the error messages. With that said, here's my error message to help with Google indexing:
|
Thank you, bro 😎 |
https://eaflood.atlassian.net/browse/WATER-3833 When we deployed the lastest version of the repo with the new [Request new bill run in Charging Module API](#83) we kept getting a `500` error returned by the service. The root error was ```text Error: undefined - Expected value which is `predicate returns truthy for any value`, received values of types `Object`. 6|system | at _formattedInitiateBillingBatchError (/home/repos/water-abstraction-system/app/controllers/bill-runs/bill-runs.controller.js:40:15) 6|system | at create (/home/repos/water-abstraction-system/app/controllers/bill-runs/bill-runs.controller.js:25:12) 6|system | at processTicksAndRejections (node:internal/process/task_queues:96:5) 6|system | at async exports.Manager.execute (/home/repos/water-abstraction-system/node_modules/@hapi/hapi/lib/toolkit.js:60:28) 6|system | at async Object.internals.handler (/home/repos/water-abstraction-system/node_modules/@hapi/hapi/lib/handler.js:46:20) 6|system | at async exports.execute (/home/repos/water-abstraction-system/node_modules/@hapi/hapi/lib/handler.js:31:20) 6|system | at async Request._lifecycle (/home/repos/water-abstraction-system/node_modules/@hapi/hapi/lib/request.js:370:32) 6|system | at async Request._execute (/home/repos/water-abstraction-system/node_modules/@hapi/hapi/lib/request.js:280:9) ``` After some research we found mention of this error in a couple of [Got](https://github.com/sindresorhus/got) related issues - [Throw more useful errors for request validation](sindresorhus/got#1257) - [Enhance assert error messages](sindresorhus/is#107 (comment)) Basically, we were passing in an invalid property for one of the options. In our case we were passing `body: {}` when it should have been `json: {}`. So, just a simple tweak but it gets the thing working!
https://eaflood.atlassian.net/browse/WATER-3833 When we deployed the latest version of the repo with the new [Request new bill run in Charging Module API](#83) we kept getting a `500` error returned by the service. The root error was ```text Error: undefined - Expected value which is `predicate returns truthy for any value`, received values of types `Object`. 6|system | at _formattedInitiateBillingBatchError (/home/repos/water-abstraction-system/app/controllers/bill-runs/bill-runs.controller.js:40:15) 6|system | at create (/home/repos/water-abstraction-system/app/controllers/bill-runs/bill-runs.controller.js:25:12) 6|system | at processTicksAndRejections (node:internal/process/task_queues:96:5) 6|system | at async exports.Manager.execute (/home/repos/water-abstraction-system/node_modules/@hapi/hapi/lib/toolkit.js:60:28) 6|system | at async Object.internals.handler (/home/repos/water-abstraction-system/node_modules/@hapi/hapi/lib/handler.js:46:20) 6|system | at async exports.execute (/home/repos/water-abstraction-system/node_modules/@hapi/hapi/lib/handler.js:31:20) 6|system | at async Request._lifecycle (/home/repos/water-abstraction-system/node_modules/@hapi/hapi/lib/request.js:370:32) 6|system | at async Request._execute (/home/repos/water-abstraction-system/node_modules/@hapi/hapi/lib/request.js:280:9) ``` After some research, we found mention of this error in a couple of [Got](https://github.com/sindresorhus/got) related issues - [Throw more useful errors for request validation](sindresorhus/got#1257) - [Enhance assert error messages](sindresorhus/is#107 (comment)) Basically, we were passing in an invalid property for one of the options. In our case we were passing `body: {}` when it should have been `json: {}`. So, just a simple tweak but it gets the thing working!
Also facing this issue when trying to post FormData object, any hints on how to fix it? I'm using |
Coming back here nearly 2 years later. timeout: {
lookup: 100,
connect: 50,
secureConnect: 50,
socket: 1000,
send: 10000,
response: 1000
} |
I want to add that I got the error
Blog: https://schalkneethling.com/posts/moving-from-got-11-to-12 |
I set |
What problem are you trying to solve?
I passed in searchParams option as null and got back an error that looks like this:
It took some time to figure out why I was getting this error, I had to look at the callstack of the error figure out what was wrong.
Would it be possible to add to the error message saying that the option
searchParams
(or another option) is the wrong type? It would be much clearer and help with debugging. Another option is to accept null for options, which seems reasonable to me.The text was updated successfully, but these errors were encountered: