Skip to content

Throw an error if serverPlugin is not defined #633

@mbelsky

Description

@mbelsky

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Throw a well described exception if serverPlugin is not defined (node_modules/fastify-cli/util.js, requireServerPluginFromPath)

Motivation

Hi team,

I had followed Getting Started docs page, copied the code from 'You First Server' section and then used command to run a server from 'Run Your Server From CLI' section. The execution failed with the following exception:

TypeError: Cannot read properties of undefined (reading 'length')
    at isInvalidAsyncPlugin (/Users/mbelsky/gh/xox-mm/node_modules/fastify-cli/util.js:45:17)
    at requireServerPluginFromPath (/Users/mbelsky/gh/xox-mm/node_modules/fastify-cli/util.js:84:7)
    at async runFastify (/Users/mbelsky/gh/xox-mm/node_modules/fastify-cli/start.js:90:12)

Then it took me some time to realize the start file must have an exported plugin. "fastify-cli" package version: 5.7.1

I believe adding a well described exception throw can help other users to spot the issue faster. If you find the proposal useful I'd like to implement it.

Example

if (!serverPlugin) {
  throw new Error(`${resolvedModulePath} does not export a plugin function`)
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions