Skip to content

Instantly share code, notes, and snippets.

@hyperreality
Last active October 28, 2018 17:46
Show Gist options
  • Save hyperreality/34251031feb336517febcf0670f7658a to your computer and use it in GitHub Desktop.
Save hyperreality/34251031feb336517febcf0670f7658a to your computer and use it in GitHub Desktop.
Automatic Stack Overflow debugging (joke)
#!/usr/bin/env node
const opn = require('opn');
var path = require('path');
var argv = require('minimist')(process.argv.slice(2));
if (!argv._.length) {
console.log('Usage: so-debug FILE.js [-g search Google] [-b specify which browser to use]');
}
else {
try {
require(path.join(process.cwd(), argv._[0]));
} catch(e) {
if (e.message.substring(0,18) != "Cannot find module") {
var url = 'https://stackoverflow.com/search?q=[js]+';
if (argv.g) url = 'https://www.google.com/search?q=javascript+';
if (argv.b) opn(url + e.name + ' ' + e.message, {app: argv.b});
else opn(url + e.name + ' ' + e.message);
console.log(e.stack);
}
else {
console.log(e.name + ': ' + e.message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment