
Security News
Node.js TSC Votes to Stop Distributing Corepack
Corepack will be phased out from future Node.js releases following a TSC vote.
@vtex/node-error-report
Advanced tools
This package is used as base for error parsing logic on node-vtex-api and vtex-toolbelt.
$ yarn global add @vtex/node-error-report
The ErrorReportBase
is a wrapper for node errors that provides features like error serialization, sanitization and error parsing (in case of request errors, for example).
It has the following constructor arguments:
This is supposed to be an error code to make error identification on a logs backend easier.
This is the originalError to be wrapped by the ErrorReportBase
- it will try to parse meaningful information on the error and add it to the parsedInfo
instance variable.
Configures error serialization aspects:
ErrorReportBase
uses originalError.message
as default error message. This allows to override it.
This is a object with additional details on the error, can be used in cases like:
try {
content = readFileSync(filename)
} catch(err) {
new ErrorReportBase({
...,
details: {
filename
}
})
}
Note that this is useful because sometimes errors thrown by standard functions doesn't help us to pinpoint the issue.
The serialization task is done by the toObject
method on ErrorReportBase
. It will:
config.maxStringLength
.Also, the toObject
will have error metadata, the details provided by whom instantiated the error, the original error stack, message and parsed info.
For now just axios request errors are parsed - some key information on the request are stripped out to a object (code).
Also it's possible to create parseable errors by implementing the ParseableError
interface, e.g.:
export class EventSourceError extends Error implements ParseableError {
public event: any
public eventSourceInfo: EventSourceInfo
constructor(event: any, eventSourceInfo: EventSourceInfo) {
super(`SSE error on endpoint ${eventSourceInfo.url}`)
this.eventSourceInfo = eventSourceInfo
this.event = { ...event }
}
public getDetailsObject() {
return {
event: this.event,
eventSourceInfo: this.eventSourceInfo,
}
}
}
When instantianting a ErrorReportBase
and providing an EventSourceError
object as the originalError
, the parseInfo
on ErrorReportBase
will be the content returned by getDetailsObject
.
Some typescript type guards implemented are also exported:
isRequestInfo
: Checks if the parsedInfo
instance variable is the result of a request parsing.isInfraErrorData
: Checks if the requestInfo.response.data
is a VTEX IO infra error (these errors can be used to improve the error report).This function abstracts away some instantiation logic, it allows the function user to optionally specify the kind
(if not specified a generic kind will be used - GenericError
or RequestError
) and abstracts away the config
creation. The configs will be provided by:
maxStringLength: ErrorReportBase.MAX_ERROR_STRING_LENGTH
maxSerializationDepth: ErrorReportBase.MAX_SERIALIZATION_DEPTH
The ErrorReportBase
allow these default values to be changed, e.g.:
ErrorReportBase.MAX_ERROR_STRING_LENGTH = 2048
The ErrorReportBase
class is supposed to be extended with functions for reporting the error to a log/tracing backend, for example:
export class ErrorReport extends ErrorReportBase {
public static create(args: ErrorReportCreateArgs) {
return new ErrorReport(createErrorReportBaseArgs(args))
}
constructor(args: ErrorReportBaseConstructorArgs) {
const { workspace, account } = SessionManager.getSingleton()
const env: ErrorEnv = {
account,
workspace,
toolbeltVersion: pkg.version,
nodeVersion: process.version,
platform: getPlatform(),
command: process.argv.slice(2).join(' '),
}
super({
...args,
details: {
...args.details,
env,
},
})
}
public sendToTelemetry() {
if (!this.isErrorReported()) {
TelemetryCollector.getCollector().registerError(this)
this.markErrorAsReported()
}
return this
}
}
The ErrorReportBase
class keeps track of the report state of the error, to avoid sending the same originalError
to the backend twice - that's the role of the methods isErrorReported
and markErrorAsReported
. These functions add metadata to the originalError
as well, so if the same originalError
is passed to another ErrorReportBase
instance, the report state will be maintained.
ErrorReportBase
exposes the following metrics that can be reported to a metrics/logs backend and accessed via errorReporObj.metadata.metrics
:
On its instantiation, the ErrorReportBase
class clones and sanitizes some fields from the arguments provided, for example:
RequestError
s are sanitized and cloned.details
object is sanitized and cloned.
This is done because later uses of these objects (or sub-objects) could be affected if ErrorReportBase
didn't cloned them and changed anything (for example, it could sanitize the Authorization
header, then later uses of the same request config would end up with auth errors).But this may be costly (who knows?). Because of this, ErrorReportBase
exposes the instantiationTime
metric.
FAQs
Error parsing, serialization, sanitizing and reporting
The npm package @vtex/node-error-report receives a total of 3,025 weekly downloads. As such, @vtex/node-error-report popularity was classified as popular.
We found that @vtex/node-error-report demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 63 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
Corepack will be phased out from future Node.js releases following a TSC vote.
Research
Security News
Research uncovers Black Basta's plans to exploit package registries for ransomware delivery alongside evidence of similar attacks already targeting open source ecosystems.
Security News
Oxlint's beta release introduces 500+ built-in linting rules while delivering twice the speed of previous versions, with future support planned for custom plugins and improved IDE integration.