From 9ab24be4621e4988e682686843664a42f4071f3d Mon Sep 17 00:00:00 2001 From: Giulio Davide Carparelli Date: Thu, 23 Nov 2023 18:23:33 +0100 Subject: [PATCH] docs(#5142): aligned errors and warnings documentation (#5162) --- docs/Reference/Errors.md | 568 ++++++++++------------------------ docs/Reference/Warnings.md | 58 +++- test/internals/errors.test.js | 4 +- 3 files changed, 214 insertions(+), 416 deletions(-) diff --git a/docs/Reference/Errors.md b/docs/Reference/Errors.md index b95c3aac36..9590d39fb5 100644 --- a/docs/Reference/Errors.md +++ b/docs/Reference/Errors.md @@ -3,6 +3,95 @@ ## Errors +**Table of contents** +- [Errors](#errors) + - [Error Handling In Node.js](#error-handling-in-node.js) + - [Uncaught Errors](#uncaught-errors) + - [Catching Errors In Promises](#catching-errors-in-promises) + - [Errors In Fastify](#errors-in-fastify) + - [Errors In Input Data](#errors-in-input-data) + - [Catching Uncaught Errors In Fastify](#catching-uncaught-errors-in-fastify) + - [Errors In Fastify Lifecycle Hooks And A Custom Error Handler](#errors-in-fastify-lifecycle-hooks-and-a-custom-error-handler) + - [Fastify Error Codes](#fastify-error-codes) + - [FST_ERR_NOT_FOUND](#fst_err_not_found) + - [FST_ERR_OPTIONS_NOT_OBJ](#fst_err_options_not_obj) + - [FST_ERR_QSP_NOT_FN](#fst_err_qsp_not_fn) + - [FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN](#fst_err_schema_controller_bucket_opt_not_fn) + - [FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN](#fst_err_schema_error_formatter_not_fn) + - [FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ](#fst_err_ajv_custom_options_opt_not_obj) + - [FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR](#fst_err_ajv_custom_options_opt_not_arr) + - [FST_ERR_VERSION_CONSTRAINT_NOT_STR](#fst_err_version_constraint_not_str) + - [FST_ERR_CTP_ALREADY_PRESENT](#fst_err_ctp_already_present) + - [FST_ERR_CTP_INVALID_TYPE](#fst_err_ctp_invalid_type) + - [FST_ERR_CTP_EMPTY_TYPE](#fst_err_ctp_empty_type) + - [FST_ERR_CTP_INVALID_HANDLER](#fst_err_ctp_invalid_handler) + - [FST_ERR_CTP_INVALID_PARSE_TYPE](#fst_err_ctp_invalid_parse_type) + - [FST_ERR_CTP_BODY_TOO_LARGE](#fst_err_ctp_body_too_large) + - [FST_ERR_CTP_INVALID_MEDIA_TYPE](#fst_err_ctp_invalid_media_type) + - [FST_ERR_CTP_INVALID_CONTENT_LENGTH](#fst_err_ctp_invalid_content_length) + - [FST_ERR_CTP_EMPTY_JSON_BODY](#fst_err_ctp_empty_json_body) + - [FST_ERR_CTP_INSTANCE_ALREADY_STARTED](#fst_err_ctp_instance_already_started) + - [FST_ERR_INSTANCE_ALREADY_LISTENING](#fst_err_instance_already_listening) + - [FST_ERR_DEC_ALREADY_PRESENT](#fst_err_dec_already_present) + - [FST_ERR_DEC_DEPENDENCY_INVALID_TYPE](#fst_err_dec_dependency_invalid_type) + - [FST_ERR_DEC_MISSING_DEPENDENCY](#fst_err_dec_missing_dependency) + - [FST_ERR_DEC_AFTER_START](#fst_err_dec_after_start) + - [FST_ERR_HOOK_INVALID_TYPE](#fst_err_hook_invalid_type) + - [FST_ERR_HOOK_INVALID_HANDLER](#fst_err_hook_invalid_handler) + - [FST_ERR_HOOK_INVALID_ASYNC_HANDLER](#fst_err_hook_invalid_async_handler) + - [FST_ERR_HOOK_NOT_SUPPORTED](#fst_err_hook_not_supported) + - [FST_ERR_MISSING_MIDDLEWARE](#fst_err_missing_middleware) + - [FST_ERR_HOOK_TIMEOUT](#fst_err_hook_timeout) + - [FST_ERR_LOG_INVALID_DESTINATION](#fst_err_log_invalid_destination) + - [FST_ERR_LOG_INVALID_LOGGER](#fst_err_log_invalid_logger) + - [FST_ERR_REP_INVALID_PAYLOAD_TYPE](#fst_err_rep_invalid_payload_type) + - [FST_ERR_REP_ALREADY_SENT](#fst_err_rep_already_sent) + - [FST_ERR_REP_SENT_VALUE](#fst_err_rep_sent_value) + - [FST_ERR_SEND_INSIDE_ONERR](#fst_err_send_inside_onerr) + - [FST_ERR_SEND_UNDEFINED_ERR](#fst_err_send_undefined_err) + - [FST_ERR_BAD_STATUS_CODE](#fst_err_bad_status_code) + - [FST_ERR_BAD_TRAILER_NAME](#fst_err_bad_trailer_name) + - [FST_ERR_BAD_TRAILER_VALUE](#fst_err_bad_trailer_value) + - [FST_ERR_FAILED_ERROR_SERIALIZATION](#fst_err_failed_error_serialization) + - [FST_ERR_MISSING_SERIALIZATION_FN](#fst_err_missing_serialization_fn) + - [FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN](#fst_err_missing_contenttype_serialization_fn) + - [FST_ERR_REQ_INVALID_VALIDATION_INVOCATION](#fst_err_req_invalid_validation_invocation) + - [FST_ERR_SCH_MISSING_ID](#fst_err_sch_missing_id) + - [FST_ERR_SCH_ALREADY_PRESENT](#fst_err_sch_already_present) + - [FST_ERR_SCH_CONTENT_MISSING_SCHEMA](#fst_err_sch_content_missing_schema) + - [FST_ERR_SCH_DUPLICATE](#fst_err_sch_duplicate) + - [FST_ERR_SCH_VALIDATION_BUILD](#fst_err_sch_validation_build) + - [FST_ERR_SCH_SERIALIZATION_BUILD](#fst_err_sch_serialization_build) + - [FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX](#fst_err_sch_response_schema_not_nested_2xx) + - [FST_ERR_HTTP2_INVALID_VERSION](#fst_err_http2_invalid_version) + - [FST_ERR_INIT_OPTS_INVALID](#fst_err_init_opts_invalid) + - [FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE](#fst_err_force_close_connections_idle_not_available) + - [FST_ERR_DUPLICATED_ROUTE](#fst_err_duplicated_route) + - [FST_ERR_BAD_URL](#fst_err_bad_url) + - [FST_ERR_ASYNC_CONSTRAINT](#fst_err_async_constraint) + - [FST_ERR_DEFAULT_ROUTE_INVALID_TYPE](#fst_err_default_route_invalid_type) + - [FST_ERR_INVALID_URL](#fst_err_invalid_url) + - [FST_ERR_ROUTE_OPTIONS_NOT_OBJ](#fst_err_route_options_not_obj) + - [FST_ERR_ROUTE_DUPLICATED_HANDLER](#fst_err_route_duplicated_handler) + - [FST_ERR_ROUTE_HANDLER_NOT_FN](#fst_err_route_handler_not_fn) + - [FST_ERR_ROUTE_MISSING_HANDLER](#fst_err_route_missing_handler) + - [FST_ERR_ROUTE_METHOD_INVALID](#fst_err_route_method_invalid) + - [FST_ERR_ROUTE_METHOD_NOT_SUPPORTED](#fst_err_route_method_not_supported) + - [FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED](#fst_err_route_body_validation_schema_not_supported) + - [FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT](#fst_err_route_body_limit_option_not_int) + - [FST_ERR_ROUTE_REWRITE_NOT_STR](#fst_err_route_rewrite_not_str) + - [FST_ERR_REOPENED_CLOSE_SERVER](#fst_err_reopened_close_server) + - [FST_ERR_REOPENED_SERVER](#fst_err_reopened_server) + - [FST_ERR_PLUGIN_VERSION_MISMATCH](#fst_err_plugin_version_mismatch) + - [FST_ERR_PLUGIN_CALLBACK_NOT_FN](#fst_err_plugin_callback_not_fn) + - [FST_ERR_PLUGIN_NOT_VALID](#fst_err_plugin_not_valid) + - [FST_ERR_ROOT_PLG_BOOTED](#fst_err_root_plg_booted) + - [FST_ERR_PARENT_PLUGIN_BOOTED](#fst_err_parent_plugin_booted) + - [FST_ERR_PLUGIN_TIMEOUT](#fst_err_plugin_timeout) + - [FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE](#fst_err_plugin_not_present_in_instance) + - [FST_ERR_VALIDATION](#fst_err_validation) + - [FST_ERR_LISTEN_OPTIONS_INVALID](#fst_err_listen_options_invalid) + ### Error Handling In Node.js @@ -128,401 +217,86 @@ fastify.listen({ port: 3000 }, function (err, address) { }) ``` -#### FST_ERR_NOT_FOUND - - -404 Not Found. - -#### FST_ERR_OPTIONS_NOT_OBJ - - -Fastify options must be an object. - -#### FST_ERR_QSP_NOT_FN - - -QueryStringParser option should be a function. - -#### FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN - - -SchemaController.bucket option should be a function. - -#### FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN - - -SchemaErrorFormatter option should be a non async function. - -#### FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ - - -ajv.customOptions option should be an object. - -#### FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR - - -ajv.plugins option should be an array. - -#### FST_ERR_VERSION_CONSTRAINT_NOT_STR - - -Version constraint should be a string. - -#### FST_ERR_CTP_ALREADY_PRESENT - - -The parser for this content type was already registered. - -#### FST_ERR_CTP_INVALID_TYPE - - -The `Content-Type` should be a string. - -#### FST_ERR_CTP_EMPTY_TYPE - - -The content type cannot be an empty string. - -#### FST_ERR_CTP_INVALID_HANDLER - - -An invalid handler was passed for the content type. - -#### FST_ERR_CTP_INVALID_PARSE_TYPE - - -The provided parse type is not supported. Accepted values are `string` or -`buffer`. - -#### FST_ERR_CTP_BODY_TOO_LARGE - - -The request body is larger than the provided limit. - -This setting can be defined in the Fastify server instance: -[`bodyLimit`](./Server.md#bodylimit) - -#### FST_ERR_CTP_INVALID_MEDIA_TYPE - - -The received media type is not supported (i.e. there is no suitable -`Content-Type` parser for it). - -#### FST_ERR_CTP_INVALID_CONTENT_LENGTH - - -Request body size did not match `Content-Length`. - -#### FST_ERR_CTP_EMPTY_JSON_BODY - - -Body cannot be empty when content-type is set to `application/json`. - -#### FST_ERR_CTP_INSTANCE_ALREADY_STARTED - - -Fastify is already started. - -#### FST_ERR_INSTANCE_ALREADY_LISTENING - - -Fastify instance is already listening. - -#### FST_ERR_DEC_ALREADY_PRESENT - - -A decorator with the same name is already registered. - -#### FST_ERR_DEC_DEPENDENCY_INVALID_TYPE - - -The dependencies of decorator must be of type `Array`. - -#### FST_ERR_DEC_MISSING_DEPENDENCY - - -The decorator cannot be registered due to a missing dependency. - -#### FST_ERR_DEC_AFTER_START - - -The decorator cannot be added after start. - -#### FST_ERR_HOOK_INVALID_TYPE - - -The hook name must be a string. - -#### FST_ERR_HOOK_INVALID_HANDLER - - -The hook callback must be a function. - -#### FST_ERR_HOOK_INVALID_ASYNC_HANDLER - - -Async function has too many arguments. Async hooks should not use the `done` argument. - -#### FST_ERR_HOOK_NOT_SUPPORTED - - -The hook is not supported. - -#### FST_ERR_MISSING_MIDDLEWARE - - -You must register a plugin for handling middlewares, -visit [`Middleware`](./Middleware.md) for more info. - -#### FST_ERR_HOOK_TIMEOUT - - -A callback for a hook timed out - -#### FST_ERR_LOG_INVALID_DESTINATION - - -The logger accepts either a `'stream'` or a `'file'` as the destination. - -#### FST_ERR_LOG_INVALID_LOGGER - - -The logger should have all these methods: `'info'`, `'error'`, -`'debug'`, `'fatal'`, `'warn'`, `'trace'`, `'child'`. - -#### FST_ERR_REP_INVALID_PAYLOAD_TYPE - - -Reply payload can be either a `string` or a `Buffer`. - -#### FST_ERR_REP_ALREADY_SENT - - -A response was already sent. - -#### FST_ERR_REP_SENT_VALUE - - -The only possible value for `reply.sent` is `true`. - -#### FST_ERR_SEND_INSIDE_ONERR - - -You cannot use `send` inside the `onError` hook. - -#### FST_ERR_SEND_UNDEFINED_ERR - - -Undefined error has occurred. - -#### FST_ERR_BAD_STATUS_CODE - - -Called `reply` with an invalid status code. - -#### FST_ERR_BAD_TRAILER_NAME - - -Called `reply.trailer` with an invalid header name. - -#### FST_ERR_BAD_TRAILER_VALUE - - -Called `reply.trailer` with an invalid type. Expected a function. - -#### FST_ERR_FAILED_ERROR_SERIALIZATION - - -Failed to serialize an error. - -#### FST_ERR_MISSING_SERIALIZATION_FN - - -Missing serialization function. - -#### FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN - - -Missing serialization function. - -#### FST_ERR_REQ_INVALID_VALIDATION_INVOCATION - - -Invalid validation invocation. Missing validation function for -HTTP part nor schema provided. - -#### FST_ERR_SCH_MISSING_ID - - -The schema provided does not have `$id` property. - -#### FST_ERR_SCH_ALREADY_PRESENT - - -A schema with the same `$id` already exists. - -#### FST_ERR_SCH_CONTENT_MISSING_SCHEMA - - -A schema is missing for the corresponding content type. - -#### FST_ERR_SCH_DUPLICATE - - -Schema with the same `$id` already present! - -#### FST_ERR_SCH_VALIDATION_BUILD - - -The JSON schema provided for validation to a route is not valid. - -#### FST_ERR_SCH_SERIALIZATION_BUILD - - -The JSON schema provided for serialization of a route response is not valid. - -#### FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX - - -Response schemas should be nested under a valid status code (2XX). - -#### FST_ERR_HTTP2_INVALID_VERSION - - -HTTP2 is available only from node >= 8.8.1. - -#### FST_ERR_INIT_OPTS_INVALID - - -Invalid initialization options. - -#### FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE - - -Cannot set forceCloseConnections to `idle` as your HTTP server -does not support `closeIdleConnections` method. - -#### FST_ERR_DUPLICATED_ROUTE - - -The HTTP method already has a registered controller for that URL - -#### FST_ERR_BAD_URL - - -The router received an invalid url. - -#### FST_ERR_ASYNC_CONSTRAINT - - -The router received an error when using asynchronous constraints. - -#### FST_ERR_DEFAULT_ROUTE_INVALID_TYPE - - -The `defaultRoute` type should be a function. - -#### FST_ERR_INVALID_URL - - -URL must be a string. - -#### FST_ERR_ROUTE_OPTIONS_NOT_OBJ - - -Options for the route must be an object. - -#### FST_ERR_ROUTE_DUPLICATED_HANDLER - - -Duplicate handler for the route is not allowed. - -#### FST_ERR_ROUTE_HANDLER_NOT_FN - - -Handler for the route must be a function. - -#### FST_ERR_ROUTE_MISSING_HANDLER - - -Missing handler function for the route. - -#### FST_ERR_ROUTE_METHOD_INVALID - - -Method is not a valid value. - -#### FST_ERR_ROUTE_METHOD_NOT_SUPPORTED - - -Method is not supported for the route. - -#### FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED - - -Body validation schema route is not supported. - -#### FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT - - -BodyLimit option must be an integer. - -#### FST_ERR_ROUTE_REWRITE_NOT_STR - - -Rewrite url needs to be of type "string". - -#### FST_ERR_REOPENED_CLOSE_SERVER - - -Fastify has already been closed and cannot be reopened. - -#### FST_ERR_REOPENED_SERVER - - -Fastify is already listening. - -#### FST_ERR_PLUGIN_VERSION_MISMATCH - - -Installed Fastify plugin mismatched expected version. - -#### FST_ERR_PLUGIN_CALLBACK_NOT_FN - - -Callback for a hook is not a function (mapped directly from `avvio`) - -#### FST_ERR_PLUGIN_NOT_VALID - - -Plugin must be a function or a promise. - -#### FST_ERR_ROOT_PLG_BOOTED - - -Root plugin has already booted (mapped directly from `avvio`) - -#### FST_ERR_PARENT_PLUGIN_BOOTED - - -Impossible to load plugin because the parent (mapped directly from `avvio`) - -#### FST_ERR_PLUGIN_TIMEOUT - - -Plugin did not start in time. Default timeout (in milliseconds): `10000` - -#### FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE - - -The decorator is not present in the instance. - -#### FST_ERR_VALIDATION - - -The Request failed the payload validation. - -#### FST_ERR_LISTEN_OPTIONS_INVALID - +Below is a table with all the error codes that Fastify uses. + +| Code | Description | How to solve | Discussion | +|------|-------------|--------------|------------| +| FST_ERR_NOT_FOUND | 404 Not Found | - | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_OPTIONS_NOT_OBJ | Fastify options wrongly specified. | Fastify options should be an object. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_QSP_NOT_FN | QueryStringParser wrongly specified. | QueryStringParser option should be a function. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_SCHEMA_CONTROLLER_BUCKET_OPT_NOT_FN | SchemaController.bucket wrongly specified. | SchemaController.bucket option should be a function. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_SCHEMA_ERROR_FORMATTER_NOT_FN | SchemaErrorFormatter option wrongly specified. | SchemaErrorFormatter option should be a non async function. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_OBJ | ajv.customOptions wrongly specified. | ajv.customOptions option should be an object. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_AJV_CUSTOM_OPTIONS_OPT_NOT_ARR | ajv.plugins option wrongly specified. | ajv.plugins option should be an array. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_VERSION_CONSTRAINT_NOT_STR | Version constraint wrongly specified. | Version constraint should be a string. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_CTP_ALREADY_PRESENT | The parser for this content type was already registered. | Use a different content type or delete the already registered parser. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_CTP_INVALID_TYPE | `Content-Type` wrongly specified | The `Content-Type` should be a string. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_CTP_EMPTY_TYPE | `Content-Type` is an empty string. | `Content-Type` cannot be an empty string. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_CTP_INVALID_HANDLER | Invalid handler for the content type. | Use a different handler. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_CTP_INVALID_PARSE_TYPE | The provided parse type is not supported. | Accepted values are string or buffer. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_CTP_BODY_TOO_LARGE | The request body is larger than the provided limit. | Increase the limit in the Fastify server instance setting: [bodyLimit](./Server.md#bodylimit) | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_CTP_INVALID_MEDIA_TYPE | The received media type is not supported (i.e. there is no suitable `Content-Type` parser for it). | Use a different content type. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_CTP_INVALID_CONTENT_LENGTH | Request body size did not match Content-Length. | Check the request body size and the Content-Length header. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_CTP_EMPTY_JSON_BODY | Body cannot be empty when content-type is set to application/json. | Check the request body. | [#1253](https://github.com/fastify/fastify/pull/1253) | +| FST_ERR_CTP_INSTANCE_ALREADY_STARTED | Fastify is already started. | - | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_INSTANCE_ALREADY_LISTENING | Fastify instance is already listening. | - | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_DEC_ALREADY_PRESENT | A decorator with the same name is already registered. | Use a different decorator name. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_DEC_DEPENDENCY_INVALID_TYPE | The dependencies of decorator must be of type `Array`. | Use an array for the dependencies. | [#3090](https://github.com/fastify/fastify/pull/3090) | +| FST_ERR_DEC_MISSING_DEPENDENCY | The decorator cannot be registered due to a missing dependency. | Register the missing dependency. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_DEC_AFTER_START | The decorator cannot be added after start. | Add the decorator before starting the server. | [#2128](https://github.com/fastify/fastify/pull/2128) | +| FST_ERR_HOOK_INVALID_TYPE | The hook name must be a string. | Use a string for the hook name. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_HOOK_INVALID_HANDLER | The hook callback must be a function. | Use a function for the hook callback. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_HOOK_INVALID_ASYNC_HANDLER | Async function has too many arguments. Async hooks should not use the `done` argument. | Remove the `done` argument from the async hook. | [#4367](https://github.com/fastify/fastify/pull/4367) | +| FST_ERR_HOOK_NOT_SUPPORTED | The hook is not supported. | Use a supported hook. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_MISSING_MIDDLEWARE | You must register a plugin for handling middlewares, visit [`Middleware`](./Middleware.md) for more info. | Register a plugin for handling middlewares. | [#2014](https://github.com/fastify/fastify/pull/2014) | +| FST_ERR_HOOK_TIMEOUT | A callback for a hook timed out. | Increase the timeout for the hook. | [#3106](https://github.com/fastify/fastify/pull/3106) | +| FST_ERR_LOG_INVALID_DESTINATION | The logger does not accept the specified destination. | Use a `'stream'` or a `'file'` as the destination. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_LOG_INVALID_LOGGER | The logger should have all these methods: `'info'`, `'error'`, `'debug'`, `'fatal'`, `'warn'`, `'trace'`, `'child'`. | Use a logger with all the required methods. | [#4520](https://github.com/fastify/fastify/pull/4520) | +| FST_ERR_REP_INVALID_PAYLOAD_TYPE | Reply payload can be either a `string` or a `Buffer`. | Use a `string` or a `Buffer` for the payload. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_REP_ALREADY_SENT | A response was already sent. | - | [#1336](https://github.com/fastify/fastify/pull/1336) | +| FST_ERR_REP_SENT_VALUE | The only possible value for `reply.sent` is `true`. | - | [#1336](https://github.com/fastify/fastify/pull/1336) | +| FST_ERR_SEND_INSIDE_ONERR | You cannot use `send` inside the `onError` hook. | - | [#1348](https://github.com/fastify/fastify/pull/1348) | +| FST_ERR_SEND_UNDEFINED_ERR | Undefined error has occurred. | - | [#2074](https://github.com/fastify/fastify/pull/2074) | +| FST_ERR_BAD_STATUS_CODE | The status code is not valid. | Use a valid status code. | [#2082](https://github.com/fastify/fastify/pull/2082) | +| FST_ERR_BAD_TRAILER_NAME | Called `reply.trailer` with an invalid header name. | Use a valid header name. | [#3794](https://github.com/fastify/fastify/pull/3794) | +| FST_ERR_BAD_TRAILER_VALUE | Called `reply.trailer` with an invalid type. Expected a function. | Use a function. | [#3794](https://github.com/fastify/fastify/pull/3794) | +| FST_ERR_FAILED_ERROR_SERIALIZATION | Failed to serialize an error. | - | [#4601](https://github.com/fastify/fastify/pull/4601) | +| FST_ERR_MISSING_SERIALIZATION_FN | Missing serialization function. | Add a serialization function. | [#3970](https://github.com/fastify/fastify/pull/3970) | +| FST_ERR_MISSING_CONTENTTYPE_SERIALIZATION_FN | Missing `Content-Type` serialization function. | Add a serialization function. | [#4264](https://github.com/fastify/fastify/pull/4264) | +| FST_ERR_REQ_INVALID_VALIDATION_INVOCATION | Invalid validation invocation. Missing validation function for HTTP part nor schema provided. | Add a validation function. | [#3970](https://github.com/fastify/fastify/pull/3970) | +| FST_ERR_SCH_MISSING_ID | The schema provided does not have `$id` property. | Add a `$id` property. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_SCH_ALREADY_PRESENT | A schema with the same `$id` already exists. | Use a different `$id`. | [#1168](https://github.com/fastify/fastify/pull/1168) | +| FST_ERR_SCH_CONTENT_MISSING_SCHEMA | A schema is missing for the corresponding content type. | Add a schema. | [#4264](https://github.com/fastify/fastify/pull/4264) | +| FST_ERR_SCH_DUPLICATE | Schema with the same attribute already present! | Use a different attribute. | [#1954](https://github.com/fastify/fastify/pull/1954) | +| FST_ERR_SCH_VALIDATION_BUILD | The JSON schema provided for validation to a route is not valid. | Fix the JSON schema. | [#2023](https://github.com/fastify/fastify/pull/2023) | +| FST_ERR_SCH_SERIALIZATION_BUILD | The JSON schema provided for serialization of a route response is not valid. | Fix the JSON schema. | [#2023](https://github.com/fastify/fastify/pull/2023) | +| FST_ERR_SCH_RESPONSE_SCHEMA_NOT_NESTED_2XX | Response schemas should be nested under a valid status code (2XX). | Use a valid status code. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_HTTP2_INVALID_VERSION | HTTP2 is available only from node >= 8.8.1. | Use a higher version of node. | [#1346](https://github.com/fastify/fastify/pull/1346) | +| FST_ERR_INIT_OPTS_INVALID | Invalid initialization options. | Use valid initialization options. | [#1471](https://github.com/fastify/fastify/pull/1471) | +| FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE | Cannot set forceCloseConnections to `idle` as your HTTP server does not support `closeIdleConnections` method. | Use a different value for `forceCloseConnections`. | [#3925](https://github.com/fastify/fastify/pull/3925) | +| FST_ERR_DUPLICATED_ROUTE | The HTTP method already has a registered controller for that URL. | Use a different URL or register the controller for another HTTP method. | [#2954](https://github.com/fastify/fastify/pull/2954) | +| FST_ERR_BAD_URL | The router received an invalid url. | Use a valid URL. | [#2106](https://github.com/fastify/fastify/pull/2106) | +| FST_ERR_ASYNC_CONSTRAINT | The router received an error when using asynchronous constraints. | - | [#4323](https://github.com/fastify/fastify/pull/4323) | +| FST_ERR_DEFAULT_ROUTE_INVALID_TYPE | The `defaultRoute` type should be a function. | Use a function for the `defaultRoute`. | [#2733](https://github.com/fastify/fastify/pull/2733) | +| FST_ERR_INVALID_URL | URL must be a string. | Use a string for the URL. | [#3653](https://github.com/fastify/fastify/pull/3653) | +| FST_ERR_ROUTE_OPTIONS_NOT_OBJ | Options for the route must be an object. | Use an object for the route options. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_ROUTE_DUPLICATED_HANDLER | Duplicate handler for the route is not allowed. | Use a different handler. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_ROUTE_HANDLER_NOT_FN | Handler for the route must be a function. | Use a function for the handler. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_ROUTE_MISSING_HANDLER | Missing handler function for the route. | Add a handler function. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_ROUTE_METHOD_INVALID | Method is not a valid value. | Use a valid value for the method. | [#4750](https://github.com/fastify/fastify/pull/4750) | +| FST_ERR_ROUTE_METHOD_NOT_SUPPORTED | Method is not supported for the route. | Use a supported method. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_ROUTE_BODY_VALIDATION_SCHEMA_NOT_SUPPORTED | Body validation schema route is not supported. | Use a different different method for the route. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_ROUTE_BODY_LIMIT_OPTION_NOT_INT | `bodyLimit` option must be an integer. | Use an integer for the `bodyLimit` option. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_ROUTE_REWRITE_NOT_STR | `rewriteUrl` needs to be of type `string`. | Use a string for the `rewriteUrl`. | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_REOPENED_CLOSE_SERVER | Fastify has already been closed and cannot be reopened. | - | [#2415](https://github.com/fastify/fastify/pull/2415) | +| FST_ERR_REOPENED_SERVER | Fastify is already listening. | - | [#2415](https://github.com/fastify/fastify/pull/2415) | +| FST_ERR_PLUGIN_VERSION_MISMATCH | Installed Fastify plugin mismatched expected version. | Use a compatible version of the plugin. | [#2549](https://github.com/fastify/fastify/pull/2549) | +| FST_ERR_PLUGIN_CALLBACK_NOT_FN | Callback for a hook is not a function. | Use a function for the callback. | [#3106](https://github.com/fastify/fastify/pull/3106) | +| FST_ERR_PLUGIN_NOT_VALID | Plugin must be a function or a promise. | Use a function or a promise for the plugin. | [#3106](https://github.com/fastify/fastify/pull/3106) | +| FST_ERR_ROOT_PLG_BOOTED | Root plugin has already booted. | - | [#3106](https://github.com/fastify/fastify/pull/3106) | +| FST_ERR_PARENT_PLUGIN_BOOTED | Impossible to load plugin because the parent (mapped directly from `avvio`) | - | [#3106](https://github.com/fastify/fastify/pull/3106) | +| FST_ERR_PLUGIN_TIMEOUT | Plugin did not start in time. | Increase the timeout for the plugin. | [#3106](https://github.com/fastify/fastify/pull/3106) | +| FST_ERR_PLUGIN_NOT_PRESENT_IN_INSTANCE | The decorator is not present in the instance. | - | [#4554](https://github.com/fastify/fastify/pull/4554) | +| FST_ERR_VALIDATION | The Request failed the payload validation. | Check the request payload. | [#4824](https://github.com/fastify/fastify/pull/4824) | +| FST_ERR_LISTEN_OPTIONS_INVALID | Invalid listen options. | Check the listen options. | [#4886](https://github.com/fastify/fastify/pull/4886) | -Invalid listen options. diff --git a/docs/Reference/Warnings.md b/docs/Reference/Warnings.md index 34a0fab0e1..35ef423510 100644 --- a/docs/Reference/Warnings.md +++ b/docs/Reference/Warnings.md @@ -1,6 +1,30 @@

Fastify

+**Table of contents** +- [Warnings](#warnings) + - [Warnings In Fastify](#warnings-in-fastify) + - [Fastify Warning Codes](#fastify-warning-codes) + - [FSTWRN001](#FSTWRN001) + - [FSTWRN002](#FSTWRN002) + - [Fastify Deprecation Codes](#fastify-deprecation-codes) + - [FSTDEP005](#FSTDEP005) + - [FSTDEP006](#FSTDEP006) + - [FSTDEP007](#FSTDEP007) + - [FSTDEP008](#FSTDEP008) + - [FSTDEP009](#FSTDEP009) + - [FSTDEP010](#FSTDEP010) + - [FSTDEP011](#FSTDEP011) + - [FSTDEP012](#FSTDEP012) + - [FSTDEP013](#FSTDEP013) + - [FSTDEP014](#FSTDEP014) + - [FSTDEP015](#FSTDEP015) + - [FSTDEP016](#FSTDEP016) + - [FSTDEP017](#FSTDEP017) + - [FSTDEP018](#FSTDEP018) + - [FSTDEP019](#FSTDEP019) + + ## Warnings ### Warnings In Fastify @@ -21,8 +45,8 @@ Only experienced users should consider disabling warnings. | Code | Description | How to solve | Discussion | | ---- | ----------- | ------------ | ---------- | -| **FSTWRN001** | The specified schema for a route is missing. This may indicate the schema is not well specified. | Check the schema for the route. | [#4647](https://github.com/fastify/fastify/pull/4647) | -| **FSTWRN002** | The %s plugin being registered mixes async and callback styles, which will result in an error in `fastify@5`. | Do not mix async and callback style. | [#5139](https://github.com/fastify/fastify/pull/5139) | +| FSTWRN001 | The specified schema for a route is missing. This may indicate the schema is not well specified. | Check the schema for the route. | [#4647](https://github.com/fastify/fastify/pull/4647) | +| FSTWRN002 | The %s plugin being registered mixes async and callback styles, which will result in an error in `fastify@5`. | Do not mix async and callback style. | [#5139](https://github.com/fastify/fastify/pull/5139) | ### Fastify Deprecation Codes @@ -36,18 +60,18 @@ Deprecation codes are further supported by the Node.js CLI options: | Code | Description | How to solve | Discussion | | ---- | ----------- | ------------ | ---------- | -| **FSTDEP005** | You are accessing the deprecated `request.connection` property. | Use `request.socket`. | [#2594](https://github.com/fastify/fastify/pull/2594) | -| **FSTDEP006** | You are decorating Request/Reply with a reference type. This reference is shared amongst all requests. | Do not use Arrays/Objects as values when decorating Request/Reply. | [#2688](https://github.com/fastify/fastify/pull/2688) | -| **FSTDEP007** | You are trying to set a HEAD route using `exposeHeadRoute` route flag when a sibling route is already set. | Remove `exposeHeadRoutes` or explicitly set `exposeHeadRoutes` to `false` | [#2700](https://github.com/fastify/fastify/pull/2700) | -| **FSTDEP008** | You are using route constraints via the route `{version: "..."}` option. | Use `{constraints: {version: "..."}}` option. | [#2682](https://github.com/fastify/fastify/pull/2682) | -| **FSTDEP009** | You are using a custom route versioning strategy via the server `{versioning: "..."}` option. | Use `{constraints: {version: "..."}}` option. | [#2682](https://github.com/fastify/fastify/pull/2682) | -| **FSTDEP010** | Modifying the `reply.sent` property is deprecated. | Use the `reply.hijack()` method. | [#3140](https://github.com/fastify/fastify/pull/3140) | -| **FSTDEP011** | Variadic listen method is deprecated. | Use `.listen(optionsObject)`. | [#3712](https://github.com/fastify/fastify/pull/3712) | -| **FSTDEP012** | You are trying to access the deprecated `request.context` property. | Use `request.routeOptions.config` or `request.routeOptions.schema`. | [#4216](https://github.com/fastify/fastify/pull/4216) [#5084](https://github.com/fastify/fastify/pull/5084) | -| **FSTDEP013** | Direct return of "trailers" function is deprecated. | Use "callback" or "async-await" for return value. | [#4380](https://github.com/fastify/fastify/pull/4380) | -| **FSTDEP014** | You are trying to set/access the default route. This property is deprecated. | Use `setNotFoundHandler` if you want to custom a 404 handler or the wildcard (`*`) to match all routes. | [#4480](https://github.com/fastify/fastify/pull/4480) | -| **FSTDEP015** | You are accessing the deprecated `request.routeSchema` property. | Use `request.routeOptions.schema`. | [#4470](https://github.com/fastify/fastify/pull/4470) | -| **FSTDEP016** | You are accessing the deprecated `request.routeConfig` property. | Use `request.routeOptions.config`. | [#4470](https://github.com/fastify/fastify/pull/4470) | -| **FSTDEP017** | You are accessing the deprecated `request.routerPath` property. | Use `request.routeOptions.url`. | [#4470](https://github.com/fastify/fastify/pull/4470) | -| **FSTDEP018** | You are accessing the deprecated `request.routerMethod` property. | Use `request.routeOptions.method`. | [#4470](https://github.com/fastify/fastify/pull/4470) | -| **FSTDEP019** | You are accessing the deprecated `reply.context` property. | Use `reply.routeOptions.config` or `reply.routeOptions.schema`. | [#5032](https://github.com/fastify/fastify/pull/5032) [#5084](https://github.com/fastify/fastify/pull/5084) | +| FSTDEP005 | You are accessing the deprecated `request.connection` property. | Use `request.socket`. | [#2594](https://github.com/fastify/fastify/pull/2594) | +| FSTDEP006 | You are decorating Request/Reply with a reference type. This reference is shared amongst all requests. | Do not use Arrays/Objects as values when decorating Request/Reply. | [#2688](https://github.com/fastify/fastify/pull/2688) | +| FSTDEP007 | You are trying to set a HEAD route using `exposeHeadRoute` route flag when a sibling route is already set. | Remove `exposeHeadRoutes` or explicitly set `exposeHeadRoutes` to `false` | [#2700](https://github.com/fastify/fastify/pull/2700) | +| FSTDEP008 | You are using route constraints via the route `{version: "..."}` option. | Use `{constraints: {version: "..."}}` option. | [#2682](https://github.com/fastify/fastify/pull/2682) | +| FSTDEP009 | You are using a custom route versioning strategy via the server `{versioning: "..."}` option. | Use `{constraints: {version: "..."}}` option. | [#2682](https://github.com/fastify/fastify/pull/2682) | +| FSTDEP010 | Modifying the `reply.sent` property is deprecated. | Use the `reply.hijack()` method. | [#3140](https://github.com/fastify/fastify/pull/3140) | +| FSTDEP011 | Variadic listen method is deprecated. | Use `.listen(optionsObject)`. | [#3712](https://github.com/fastify/fastify/pull/3712) | +| FSTDEP012 | You are trying to access the deprecated `request.context` property. | Use `request.routeOptions.config` or `request.routeOptions.schema`. | [#4216](https://github.com/fastify/fastify/pull/4216) [#5084](https://github.com/fastify/fastify/pull/5084) | +| FSTDEP013 | Direct return of "trailers" function is deprecated. | Use "callback" or "async-await" for return value. | [#4380](https://github.com/fastify/fastify/pull/4380) | +| FSTDEP014 | You are trying to set/access the default route. This property is deprecated. | Use `setNotFoundHandler` if you want to custom a 404 handler or the wildcard (`*`) to match all routes. | [#4480](https://github.com/fastify/fastify/pull/4480) | +| FSTDEP015 | You are accessing the deprecated `request.routeSchema` property. | Use `request.routeOptions.schema`. | [#4470](https://github.com/fastify/fastify/pull/4470) | +| FSTDEP016 | You are accessing the deprecated `request.routeConfig` property. | Use `request.routeOptions.config`. | [#4470](https://github.com/fastify/fastify/pull/4470) | +| FSTDEP017 | You are accessing the deprecated `request.routerPath` property. | Use `request.routeOptions.url`. | [#4470](https://github.com/fastify/fastify/pull/4470) | +| FSTDEP018 | You are accessing the deprecated `request.routerMethod` property. | Use `request.routeOptions.method`. | [#4470](https://github.com/fastify/fastify/pull/4470) | +| FSTDEP019 | You are accessing the deprecated `reply.context` property. | Use `reply.routeOptions.config` or `reply.routeOptions.schema`. | [#5032](https://github.com/fastify/fastify/pull/5032) [#5084](https://github.com/fastify/fastify/pull/5084) | diff --git a/test/internals/errors.test.js b/test/internals/errors.test.js index dbd1789689..5f94ab61ab 100644 --- a/test/internals/errors.test.js +++ b/test/internals/errors.test.js @@ -824,7 +824,7 @@ test('Ensure that all errors are in Errors.md documented', t => { const exportedKeys = Object.keys(errors) for (const key of exportedKeys) { if (errors[key].name === 'FastifyError') { - t.ok(errorsMd.includes(`#### ${key}\n`), key) + t.ok(errorsMd.includes(`${key.toUpperCase()}`), key) } } }) @@ -833,7 +833,7 @@ test('Ensure that non-existing errors are not in Errors.md documented', t => { t.plan(78) const errorsMd = readFileSync(resolve(__dirname, '../../docs/Reference/Errors.md'), 'utf8') - const matchRE = /#### ([0-9a-zA-Z_]+)\n/g + const matchRE = /([0-9a-zA-Z_]+)<\/a>/g const matches = errorsMd.matchAll(matchRE) const exportedKeys = Object.keys(errors)