Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@twreporter/errors
Advanced tools
[![NPM version](https://img.shields.io/npm/v/@twreporter/core.svg)](https://www.npmjs.com/package/@twreporter/errors)
This package provides the helpers for handling errors in the The Reporter website.
Inspired by package errors
for Go language and the related article by Dave Cheney.
Reference:
Annotate the error with name
, message
and payload
. It will return a new error that is an instance of errors.AnnotatingError
.
See source code and JSDoc for all parameters
Example:
import errors from '@twreporter/error'
function doSomething() {
try {
const someArguments = {
/* ... */
}
invokeSomethingWithError(...someArguments)
} catch (error) {
console.error(
errors.helpers.wrap(
error,
'ErrorType',
'failed to invoke something',
{ args: someArguments },
invokeSomethingWithError
)
)
}
}
It will return the previous error in the chain that the input error belongs to.
If there is no pointer of previous error saved in the input error, it will return null
.
It works like the Unwrap
method of errors in Go@^1.13.
See source code and JSDoc for all parameters
Example:
import errors from '@twreporter/error'
function doSomething() {
try {
const someArguments = {
/* ... */
}
invokeSomethingWithError(...someArguments)
} catch (error) {
/* list all error.name in errors chain */
let _error = error
const chain = []
while (_error) {
chain.push(_error)
_error = errors.helpers.unwrap(_error)
}
/* ... handle the chain */
}
}
It will return the earliest error in the chain that the input error belongs to.
See source code and JSDoc for all parameters
import errors from '@twreporter/error'
function nestedFailedTask() {
throw new Error('nested failure')
}
function invokeSomething() {
const someArguments = { bar: 'bar' }
try {
nestedFailedTask()
} catch (error) {
throw errors.helpers.wrap(
error,
'ErrorType',
'failed to invoke nested task',
{ args: someArguments }
)
}
}
function doSomething() {
const someArguments = { foo: 'foo' }
try {
invokeSomething(someArguments)
} catch (error) {
const annotatingError = errors.helpers.wrap(
error,
'ErrorType',
'failed to invoke something',
{ args: someArguments }
)
errors.helpers.cause(annotatingError) === 'nested failure' /* true */
}
}
log out:
ErrorType: failed to invoke something
at doSomething (/test.js:12:44)
payload {"args":{"foo":"foo"}}
See source code and JSDoc for all parameters
import errors from '@twreporter/error'
function nestedFailedTask() {
throw new Error('nested failure')
}
function invokeSomething() {
const someArguments = { bar: 'bar' }
try {
nestedFailedTask()
} catch (error) {
throw errors.helpers.wrap(
error,
'ErrorType',
'failed to invoke nested task',
{ args: someArguments }
)
}
}
function doSomething() {
const someArguments = { foo: 'foo' }
try {
invokeSomething(someArguments)
} catch (error) {
const annotatingError = errors.helpers.wrap(
error,
'ErrorType',
'failed to invoke something',
{ args: someArguments }
)
const message = errors.helpers.printAll(annotatingError, {
withStack: true,
withPayload: true,
})
console.error(message)
}
}
doSomething()
log out:
Error: nested failure
at nestedFailedTask (/test.js:4:9)
ErrorType: failed to invoke nested task
at invokeSomething (/test.js:12:26)
> payload {"args":{"bar":"bar"}}
ErrorType: failed to invoke something
at doSomething (/test.js:21:44)
> payload {"args":{"foo":"foo"}}
See source code and JSDoc for all parameters
import errors from '@twreporter/error'
function invokeSomethingWithError() {
throw new Error('nested error')
}
function doSomething() {
const someArguments = { foo: 'foo' }
try {
invokeSomethingWithError(someArguments)
} catch (error) {
const annotatingError = errors.helpers.wrap(
error,
'ErrorType',
'failed to invoke something',
{ args: someArguments }
)
const message = errors.helpers.printOne(annotatingError, {
withStack: true,
withPayload: true,
})
console.error(message)
}
}
doSomething()
log out:
ErrorType: failed to invoke something
at doSomething (/test.js:12:44)
> payload {"args":{"foo":"foo"}}
See source code and JSDoc for all parameters
import errors from '@twreporter/error'
import axios from 'axios'
async function doSomething() {
try {
const someArguments = {
/* ... */
}
await axios.get(someArguments)
} catch (axiosError) {
throw errors.helpers.annotateAxiosError(axiosError)
}
}
name
{string} the name of this errormessage
{string} the message of this errorpayload
{Object} the context information for better debuggingstack
{string} the stack trace from where the error be constructed. it contains the name and message of the error in the V8 engineSee source code and JSDoc for all parameters
make dev
make build
make publish
FAQs
[![NPM version](https://img.shields.io/npm/v/@twreporter/core.svg)](https://www.npmjs.com/package/@twreporter/errors)
The npm package @twreporter/errors receives a total of 39 weekly downloads. As such, @twreporter/errors popularity was classified as not popular.
We found that @twreporter/errors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.