Fastify Caught exception: FastifyError [FST_ERR_REP_INVALID_PAYLOAD_TYPE] - fastify

I'm using Fastify 2.12.1 and I keep getting this FastifyError FST_ERR_REP_INVALID_PAYLOAD_TYPE could someone help me debug this issue.
Caught exception: FastifyError [FST_ERR_REP_INVALID_PAYLOAD_TYPE]: FST_ERR_REP_INVALID_PAYLOAD_TYPE: Attempted to send payload of invalid type 'object'. Expected a string or Buffer.
at onSendEnd (/usr/app/node_modules/fastify/lib/reply.js:361:11)
at wrapOnSendEnd (/usr/app/node_modules/fastify/lib/reply.js:331:5)
at next (/usr/app/node_modules/fastify/lib/hooks.js:103:7)
at Object.<anonymous> (/usr/app/build/server.js:3:2695689)
at next (/usr/app/node_modules/fastify/lib/hooks.js:107:34)
at onSendHookRunner (/usr/app/node_modules/fastify/lib/hooks.js:121:3)
at onSendHook (/usr/app/node_modules/fastify/lib/reply.js:315:5)
at _Reply.Reply.send (/usr/app/node_modules/fastify/lib/reply.js:150:3)
at Object.basic404 [as handler] (/usr/app/node_modules/fastify/lib/fourOhFour.js:49:21)
at notFound (/usr/app/node_modules/fastify/lib/reply.js:571:17)
at _Reply.Reply.callNotFound (/usr/app/node_modules/fastify/lib/reply.js:244:3)
at SendStream.<anonymous> (/usr/app/node_modules/fastify-static/index.js:98:24)
at SendStream.emit (events.js:223:5) at SendStream.EventEmitter.emit (domain.js:475:20) at SendStream.error (/usr/app/node_modules/fastify-static/node_modules/send/index.js:270:17)
at SendStream.onStatError (/usr/app/node_modules/fastify-static/node_modules/send/index.js:421:12)
{ name: 'FastifyError [FST_ERR_REP_INVALID_PAYLOAD_TYPE]', code: 'FST_ERR_REP_INVALID_PAYLOAD_TYPE', message: "FST_ERR_REP_INVALID_PAYLOAD_TYPE: Attempted to send payload of invalid type 'object'. Expected a string or Buffer.", statusCode: 500 }

Related

node-opcua OPCUAClient.connect error: Invalid position

When connecting to an OPCUA Server using an endpoint (opc.tcp://{serverIP:port}/OPCUASserver), I am getting an error that I do not know how to interpret.
I create an OPCUAClient using:
let client = OPCUAClient.create(clientOptions);
Then call connect
try {
await client.connect(connection.endpoint);
} catch (err) {
console.log('opcuaClient: connection error: ', err);
Here is the log message that gets printed to console:
opcuaClient: connection error: Error: Invalid position : buf.length=0 pos =0
at readTag (/node_js/app/node_modules/node-opcua-crypto/dist/source/asn1.js:36:15)
at Object.split_der (/node_js/app/node_modules/node-opcua-crypto/dist/source/crypto_explore_certificate.js:569:47)
at OPCUAClientImpl.getCertificate (/node_js/app/node_modules/node-opcua-common/dist/opcua_secure_object.js:37:52)
at OPCUAClientImpl.<anonymous> (/node_js/app/node_modules/node-opcua-client/dist/verify.js:106:34)
at Generator.next (<anonymous>)
at /node_js/app/node_modules/node-opcua-client/dist/verify.js:8:71
at new Promise (<anonymous>)
at __awaiter (/node_js/app/node_modules/node-opcua-client/dist/verify.js:4:12)
at OPCUAClientImpl.performCertificateSanityCheck (/node_js/app/node_modules/node-opcua-client/dist/verify.js:104:12)
at OPCUAClientImpl.<anonymous> (/node_js/app/node_modules/node-opcua-client/dist/private/client_base_impl.js:569:62)
at Generator.next (<anonymous>)
at /node_js/app/node_modules/node-opcua-client/dist/private/client_base_impl.js:8:71
at new Promise (<anonymous>)
at __awaiter (/node_js/app/node_modules/node-opcua-client/dist/private/client_base_impl.js:4:12)
at /node_js/app/node_modules/node-opcua-client/dist/private/client_base_impl.js:566:122
at Object.<anonymous> (/node_js/app/node_modules/#ster5/global-mutex/dist/source/index.js:194:26)
I am not sure what this error means.
Thanks!

Line number error does not show up when using MSSQL Node?

I have been using MySQL database with Nodejs for a while. I recently switched to MSSQL with Nodejs
When using a try catch block with Nodejs and Mysql any error with the query execution would give me the line at which the error occured
So while using MySQL I did:
try{
await pool.quer(`sql statement`)
}
catch(err){
console.log(err)
}
This would give me an error and the line number of error. But with node-mssql, I get:
{ RequestError: Incorrect syntax near 'Invalid'.
at StreamEvents.req.once.err (C:\Users\David\Main Web\node_modules\mssql\lib\msnodesqlv8\request.js:463:17)
at Object.onceWrapper (events.js:277:13)
at StreamEvents.emit (events.js:189:13)
at errors.forEach.err (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\reader.js:33:20)
at Array.forEach (<anonymous>)
at routeStatementError (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\reader.js:26:14)
at invokeObject.end (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\reader.js:258:13)
at freeStatement (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\driver.js:160:13)
at cppDriver.freeStatement (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\driver.js:150:11)
code: 'EREQUEST',
originalError:
{ Error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'Invalid'. sqlstate: '42000', code: 102 },
name: 'RequestError',
number: 102,
state: undefined }
This is such an unhelpful error. I know where the error is coming from for this error because there is only one sql statement getting executed right now but as my program grows without knowing where the error is coming from it will be hard to debug. Is this an expected behavior of node-mssql?
If you see the documentation here, it clearly mentions what it return in error and what not.
It clearly mentions that "Those errors are initialized in node-mssql module and its original stack may be cropped. You can always access original error with err.originalError"
In your catch block you can try printing the stack trace. That should give you the line number where the error occurred. You can use one of the following statements:
console.stack("---TRACE---")
OR
var stackTrace = new Error().stack
console.log(stackTrace)

bodyParse error suppression

I'm currently using bodyParser with Express to accept JSON requests. Whenever I pass in an incorrectly formed JSON object it returns a nasty error via the endpoint and logs it to the console as well. The following is the error:
SyntaxError: Unexpected string
at Object.parse (native)
at parse (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/lib/types/json.js:88:17)
at /Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/lib/read.js:108:18
at done (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:239:14)
at IncomingMessage.onEnd (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:285:7)
at IncomingMessage.g (events.js:199:16)
at IncomingMessage.emit (events.js:104:17)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
SyntaxError: Unexpected string
at Object.parse (native)
at parse (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/lib/types/json.js:88:17)
at /Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/lib/read.js:108:18
at done (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:239:14)
at IncomingMessage.onEnd (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:285:7)
at IncomingMessage.g (events.js:199:16)
at IncomingMessage.emit (events.js:104:17)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
I'm wondering how I can suppress the error or patch this completely. I've investigated the error but can't find any specific recommendations for patching it.
It's common to declare an error handler with Express:
app.use(function(err, req, res, next) {
...
return res.sendStatus(500);
});
This will also catch errors thrown in middleware like body-parser.

Node.js buffer + lz4 issues - buffer.js:705 throw TypeError('value is out of bounds')

I have the following line in my node.js script that is generating a fatal error:
var compressedOutput = lz4.encode(new Buffer(logdata,"utf8"));
The variable 'logdata' contains a string I create with http request parameters. Is this an issue with lz4 or the way I'm creating my buffer? How can I resolve? Error message is below:
buffer.js:705
throw TypeError('value is out of bounds');
^
TypeError: value is out of bounds
at TypeError (<anonymous>)
at checkInt (buffer.js:705:11)
at Buffer.writeInt32LE (buffer.js:782:5)
at Encoder._flush (/var/www/node_modules/lz4/lib/encoder_stream.js:210:7)
at Encoder.<anonymous> (_stream_transform.js:130:12)
at Encoder.g (events.js:180:16)
at Encoder.emit (events.js:92:17)
at finishMaybe (_stream_writable.js:359:12)
at endWritable (_stream_writable.js:366:3)
at Encoder.Writable.end (_stream_writable.js:344:5)
worker 3884 died
Thanks and much appreciated!

easysoap promise ReferenceError: error is not defined

I installed easysoap but get this reference error
/Users/frank/Documents/NodeJs/node_modules/easysoap/node_modules/promise/index.js:82
throw err
^ ReferenceError: error is not defined
at /Users/frank/Documents/NodeJs/node_modules/easysoap/lib/easysoap.js:90:60
at Object._onImmediate (/Users/frank/Documents/NodeJs/node_modules/easysoap/node_modules/promise/core.js:34:15)
at processImmediate [as _immediateCallback] (timers.js:330:15)
Is this caused by a mistake i did make, or is anyone else also getting this error?
Is there any documantation on the web?
Looks like a bug on easysoap's side to me. From the source code:
request.get(params, this.opts)
.done(function(data) {
// ...
}, function(err) {
that.emit('error', 'fail to get wsdl', error);
});
The error variable indeed doesn't exist, and should have been err. You should report this bug to easysoap's maintainer.

Resources