Skip to content

Make "Invalid argument type" error more descriptive #2429

Open
@leibale

Description

@leibale

Motivation

Currently, when the decoder encounters an argument of a type other than string | Buffer it throws "Invalid argument type" error, but this error message is not very helpful...

I think that we should add the argument position (${i}) and its type (typeof arg / Object.prototype.toString(arg) / arg?.constructor.name) to the error message + add a "debugMode" (need a better name...), and when it is on args will be appended to the message (we can't do this by default because the arguments might contain sensitive information).

Basic Code Example

await createClient().ping(true); // should throw `expected "string | Buffer" in arguments[${i}], got ${typeof arg} instead.`

await createClient({ debugMode: true }).ping(null); // should throw `expected "string | Buffer" in arguments[${i}], got ${arg}/${typeof arg} instead. Full command: ${JSON.stringify(arg)}.`

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions