
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
fail-nicely
Advanced tools
A one-liner to at least explain why things didn't work out
See demo: fail-nicely
npm install fail-nicely
var createHandler = require('fail-nicely');
var handlerFailure = createHandler(onSuccess, {title: 'Sorry!'});
function onSuccess (message) {
console.log(message);
}
// Execute the callback with a failure:
handlerFailure('This demo requires WebGL 7 support!');
// Execute the onSuccess callback:
handlerFailure(null, 'Loaded successfully!');
You can also just pass it an error:
try {
var y = 7 + g;
} catch (e) {
handlerFailure(e);
}
The factory pattern is just a little convoluted, but the upshot is that intercepting fatal errors becomes a simple one-liner:
var fs = require('fs')
fs.readFile('test.json', createHandler(function (data) {
console.log('loaded data:', data)
}))
require('fail-nicely')(callback[, options])Returns a node-style callback (function (err, data)) that intercepts and handlers errors and otherwise forwards data through to callback.
When err is truthy, appends an overlay to the body element with a short explanation of what happened. Usefulf for making quick and ugly demos a little less ugly. If the first argument is an Error, it will use the error's message. If it's a string, that will be the explanation. Options are:
bg: overlay background color (default: '#333')fg: overlay foreground (text) color (default: '#fff')zIndex: z-index of the overlay (default: 9999)title: heading title (default: 'Sorry!')fontFamily: font family (default: Helvetica, Arial, sans-serif)position: positioning of the overlay element (default: fixed)invert: quick shorthand for swapping the foreground/background colorsReturns: Nothing.
© 2016 Ricky Reusser. MIT License.
FAQs
A one-liner to at least explain why things didn't work out
The npm package fail-nicely receives a total of 10 weekly downloads. As such, fail-nicely popularity was classified as not popular.
We found that fail-nicely 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
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.