
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600Ć Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Ć faster than humans.
@jill64/attempt
Advanced tools
š Type safe error handling in one-line
npm i @jill64/attempt
Include error objects in the return value with a syntax similar to Lodash.attempt
.
Objects other than error instances are not captured.
import { attempt } from '@jill64/attempt'
// object | Error
const result = attempt(() => JSON.parse('Invalid JSON'))
Asynchronous functions can also be used.
Objects other than error instances are not captured.
Errors may be returned either synchronously or asynchronously.
See here for details.
import { attempt } from '@jill64/attempt'
// Promise<object> | Promise<Error> | Error
const result = attempt(async () => JSON.parse('Invalid JSON'))
Returns the object specified as the second argument when an error is caught.
Objects other than error instances are not captured.
import { attempt } from '@jill64/attempt'
// object | null
const result = attempt(() => JSON.parse('Invalid JSON'), null)
Executes the callback specified in the second argument when an error is caught.
The item filtered as an error instance is passed as the first argument of the callback.
import { attempt } from '@jill64/attempt'
// object | (string(error.message) | undefined)
const result = attempt(
() => JSON.parse('Invalid JSON'),
(error) => error?.message
)
The raw thrown object is passed as the second argument to the callback.
import { attempt } from '@jill64/attempt'
// object | 'Syntax Error' | null
const result = attempt(
() => JSON.parse('Invalid JSON'),
(error, projectile) => {
if (error instanceof SyntaxError) {
return 'Syntax Error'
}
console.error('Unknown Object', projectile)
return null
}
)
Promise<Error>
when specified?Asynchronous function to Reject
// () => Promise<object>
const func = async () => {
try {
JSON.parse('Invalid JSON')
} catch {
throw new Error('Error')
}
}
// Assign `null` by catch reject
const result = func().catch(() => null)
// `null`
return result
Asynchronous function that throws an error immediately (does not Reject)
// () => Promise<object>
const func = () => {
try {
const obj = JSON.parse('Invalid JSON')
return new Promise(
(resolve) => resolve(obj),
(reject) => reject('Reject')
)
} catch {
throw new Error('Error')
}
}
// Error: Not Reject Error (Can't catch)
const result = func().catch(() => null)
return result
Although this is catchable in JavaScript syntax, it is actually thrown synchronously and cannot be caught.
Also, there is no way to check if a Promise
is returned before the function is executed.
Therefore, the error return value of an asynchronous function is always Error | Promise<Error>
.
FAQs
š Type safe error handling in one-line
The npm package @jill64/attempt receives a total of 33 weekly downloads. As such, @jill64/attempt popularity was classified as not popular.
We found that @jill64/attempt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 1 open source maintainer 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
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Ć faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.