PacktPublishing / Accelerating-Server-Side-Development-with-Fastify

Accelerate Web Development with Fastify, published by Packt
MIT License
129 stars 37 forks source link

mixing of async and callback styles #62

Closed EnergeticPixels closed 1 month ago

EnergeticPixels commented 2 months ago

@Eomm @mcollina,

I have been trying to follow the book as I am learning many things I wish I had before diving into my own Fastify backend. I ran into a Fastify warning FSTWRN002 in Chapter 8. It was sourced to the loader.js. If I remove the "next" callback, the warning does not display.

The warning I am getting: (node:12133) [FSTWRN002] FastifyWarning: The application-schemas plugin being registered mixes async and callback styles, which will result in an error in fastify@5 File in question: Chapter 8/schemas/loader.js

Eomm commented 1 month ago

Hi, thanks for reading the book.

The FSTWRN002 warning spots wrong plugin interface declaration such as:

WRONG declaration

// async function with next
async function plugin(fastify, opts, next) {}

// sync function and missing `next`
function plugin(fastify, opts) {} 

If I remove the "next" callback, the warning does not display.

I assume the plugin function is an async function, for this reason removing the next callback argument is correct.


In the book I checked that the spelling is correct and the warning is not there:

https://github.com/PacktPublishing/Accelerating-Server-Side-Development-with-Fastify/blob/3335e1297a717a0ff8d1170436d09b9f8693fefe/Chapter%208/schemas/loader.js#L5-L11