
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
process-warning
Advanced tools
A small utility for generating consistent warning objects across your codebase. It also exposes a utility for emitting those warnings, guaranteeing that they are issued only once (unless configured otherwise).
This module is used by the Fastify framework and it was called fastify-warning
prior to version 1.0.0.
npm i process-warning
The module exports two builder functions for creating warnings.
const {
createWarning,
createDeprecation
} = require('process-warning')
const warning = createWarning({
name: 'ExampleWarning',
code: 'EXP_WRN_001',
message: 'Hello %s',
unlimited: true
})
warning('world')
createWarning({ name, code, message[, unlimited] })
name
(string
, required) - The error name, you can access it later with
error.name
. For consistency, we recommend prefixing module error names
with {YourModule}Warning
code
(string
, required) - The warning code, you can access it later with
error.code
. For consistency, we recommend prefixing plugin error codes with
{ThreeLetterModuleName}_
, e.g. FST_
. NOTE: codes should be all uppercase.message
(string
, required) - The warning message. You can also use
interpolated strings for formatting the message.options
(object
, optional) - Optional options with the following
properties:
unlimited
(boolean
, optional) - Should the warning be emitted more than
once? Defaults to false
.createDeprecation({code, message[, options]})
This is a wrapper for createWarning
. It is equivalent to invoking
createWarning
with the name
parameter set to "DeprecationWarning".
Deprecation warnings have extended support for the Node.js CLI options:
--throw-deprecation
, --no-deprecation
, and --trace-deprecation
.
warning([, a [, b [, c]]])
The returned warning
function can used for emitting warnings.
A warning is guaranteed to be emitted at least once.
[, a [, b [, c]]]
(any
, optional) - Parameters for string interpolation.const { createWarning } = require('process-warning')
const FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'message' })
FST_ERROR_CODE()
How to use an interpolated string:
const { createWarning } = require('process-warning')
const FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s'})
FST_ERROR_CODE('world')
The warning
object has methods and properties for managing the warning's state. Useful for testing.
const { createWarning } = require('process-warning')
const FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s'})
console.log(FST_ERROR_CODE.emitted) // false
FST_ERROR_CODE('world')
console.log(FST_ERROR_CODE.emitted) // true
const FST_ERROR_CODE_2 = createWarning('MyAppWarning', 'FST_ERROR_CODE_2', 'Hello %s')
FST_ERROR_CODE_2.emitted = true
FST_ERROR_CODE_2('world') // will not be emitted because it is not unlimited
How to use an unlimited warning:
const { createWarning } = require('process-warning')
const FST_ERROR_CODE = createWarning({ name: 'MyAppWarning', code: 'FST_ERROR_CODE', message: 'Hello %s', unlimited: true })
FST_ERROR_CODE('world') // will be emitted
FST_ERROR_CODE('world') // will be emitted again
It is possible to suppress warnings by utilizing one of node's built-in warning suppression mechanisms.
Warnings can be suppressed:
NODE_NO_WARNINGS
environment variable to 1
--no-warnings
flag to the node processNODE_OPTIONS
environment variableFor more information see node's documentation.
Licensed under MIT.
FAQs
A small utility for creating warnings and emitting them.
The npm package process-warning receives a total of 10,900,742 weekly downloads. As such, process-warning popularity was classified as popular.
We found that process-warning demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 10 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.