Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@grimen/mybad
Advanced tools
js-mybad
My friendly error base class - for Node/JavaScript.
One in general always needs a application/library specific error base class, but the native errors are very limited in what meta/debugging information they can hold at time they are raised. For better debugging and error reporting/inspection this error base class allows to attach some additonal error context information that can be used to better understand the issue - without having to create custom error formatters, or run debugger.
Install using npm:
$ npm install @grimen/mybad
Install using yarn:
$ yarn add @grimen/mybad
Very basic example:
const mybad = require('@grimen/mybad')
class ToMuchError extends mybad.Error {}
function printMoney(stash) {
try {
if (typeof stash === 'string' && stash.length > 13) {
throw new RangeError(`Too much money to print: ${stash}`)
}
console.log(`PRINT ${stash.join('')}`)
} catch (error) {
throw new ToMuchError(error, {
message: 'Out of money printing ink...',
id: Date.now(), // well, should maybe be unique...
key: 'too_much',
code: 400,
details: {
stash,
},
})
}
}
let amount = ''
const range = (to) => {
return [...Array(to).keys()]
}
for (let dollar of range(42)) {
amount += '$'
try {
printMoney(amount)
} catch (error) {
console.error(error.toString())
throw error
}
}
Run this with optional environment variables COLORS
/ ERROR_COLORS
and/or VERBOSE
/ ERROR_VERBOSE
set too truthy or falsy values, so see various error info formatting in terminal.
Something like this (imagine some colorized formatting):
PRINT $
PRINT $$
PRINT $$$
PRINT $$$$
PRINT $$$$$
PRINT $$$$$$
PRINT $$$$$$$
PRINT $$$$$$$$
PRINT $$$$$$$$$
PRINT $$$$$$$$$$
PRINT $$$$$$$$$$$
PRINT $$$$$$$$$$$$
PRINT $$$$$$$$$$$$$
===============================
error.toString()
---------------------------
Out of money printing ink... - { stash: '$$$$$$$$$$$$$$' }
===============================
error.stack
---------------------------
ToMuchError: Out of money printing ink...
at printMoney (/Users/grimen/Dev/Private/js-mybad/examples/basic.js:29:15)
at Object.<anonymous> (/Users/grimen/Dev/Private/js-mybad/examples/basic.js:56:9)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
===============================
error.inspect()
---------------------------
Out of money printing ink...
===============================
error.json()
---------------------------
{
"type": "ToMuchError",
"id": 1557522743469,
"code": 400,
"key": "too_much",
"message": "Out of money printing ink...",
"details": {
"stash": "$$$$$$$$$$$$$$"
},
"stack": [
{
"file": "/Users/grimen/Dev/Private/js-mybad/examples/basic.js",
"function": "printMoney",
"line": 29,
"column": 15
},
{
"file": "/Users/grimen/Dev/Private/js-mybad/examples/basic.js",
"function": "Object.<anonymous>",
"line": 56,
"column": 9
},
{
"file": "module.js",
"function": "Module._compile",
"line": 653,
"column": 30
},
{
"file": "module.js",
"function": "Object.Module._extensions..js",
"line": 664,
"column": 10
},
{
"file": "module.js",
"function": "Module.load",
"line": 566,
"column": 32
},
{
"file": "module.js",
"function": "tryModuleLoad",
"line": 506,
"column": 12
},
{
"file": "module.js",
"function": "Function.Module._load",
"line": 498,
"column": 3
},
{
"file": "module.js",
"function": "Function.Module.runMain",
"line": 694,
"column": 10
},
{
"file": "bootstrap_node.js",
"function": "startup",
"line": 204,
"column": 16
},
{
"file": "625",
"function": "bootstrap_node.js",
"line": 3
}
]
}
Clone down source code:
$ make install
Run colorful tests using jest:
$ make test
python-mybad
- "My friendly error base class - for Python"This project was mainly initiated - in lack of solid existing alternatives - to be used at our work at Markable.ai to have common code conventions between various programming environments where Node.js (for I/O heavy operations) is heavily used.
Released under the MIT license.
FAQs
My friendly error base class - for Node/JavaScript.
The npm package @grimen/mybad receives a total of 4 weekly downloads. As such, @grimen/mybad popularity was classified as not popular.
We found that @grimen/mybad demonstrated a not healthy version release cadence and project activity because the last version was released 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.