Last active
October 28, 2018 17:46
-
-
Save hyperreality/34251031feb336517febcf0670f7658a to your computer and use it in GitHub Desktop.
Automatic Stack Overflow debugging (joke)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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