Comparing version 4.7.3 to 4.8.0
(function() { | ||
'use strict'; | ||
var CND, FS, PATH, alert, badge, debug, echo, get_context, help, info, log, rpr, show_error_with_source_context, stackman, urge, warn, whisper; | ||
var CND, FS, PATH, alert, badge, bold, cyan, debug, echo, get_context, gold, green, grey, help, info, isa_text, log, red, reverse, rpr, show_error_with_source_context, stackman, steel, urge, warn, whisper, white, yellow; | ||
@@ -10,3 +10,3 @@ //########################################################################################################### | ||
badge = 'exception-handler'; | ||
badge = 'cndxh'; | ||
@@ -38,4 +38,3 @@ log = CND.get_logger('plain', badge); | ||
// error = new Error('Oops!') | ||
// debug '^4461^' | ||
({isa_text, red, green, steel, grey, cyan, bold, gold, reverse, white, yellow, reverse} = CND); | ||
@@ -45,3 +44,3 @@ //----------------------------------------------------------------------------------------------------------- | ||
/* TAINT use stackman.sourceContexts() instead */ | ||
var R, delta, error, first_idx, idx, last_idx, line, lines; | ||
var R, delta, error, first_idx, i, idx, last_idx, len, line, lines, lnr, ref, this_linenr; | ||
try { | ||
@@ -54,14 +53,16 @@ lines = (FS.readFileSync(path, { | ||
last_idx = Math.min(lines.length - 1, linenr - 1 + delta); | ||
R = (function() { | ||
var i, len, ref, results; | ||
ref = lines.slice(first_idx, +last_idx + 1 || 9e9); | ||
results = []; | ||
for (idx = i = 0, len = ref.length; i < len; idx = ++i) { | ||
line = ref[idx]; | ||
results.push(`${first_idx + idx + 1} ${line}`); | ||
R = []; | ||
ref = lines.slice(first_idx, +last_idx + 1 || 9e9); | ||
for (idx = i = 0, len = ref.length; i < len; idx = ++i) { | ||
line = ref[idx]; | ||
this_linenr = first_idx + idx + 1; | ||
lnr = (this_linenr.toString().padStart(4)) + '│ '; | ||
if (this_linenr === linenr) { | ||
R.push(`${grey(lnr)}${cyan(line)}`); | ||
} else { | ||
R.push(`${grey(lnr)}${grey(line)}`); | ||
} | ||
return results; | ||
})(); | ||
R = R.join('\n'); | ||
} | ||
} catch (error1) { | ||
// R = R.join '\n' | ||
error = error1; | ||
@@ -71,3 +72,3 @@ if (error.code !== 'ENOENT') { | ||
} | ||
return './.'; | ||
return [grey('./.')]; | ||
} | ||
@@ -84,15 +85,22 @@ return R; | ||
callsites.forEach(function(callsite) { | ||
var linenr, path, relpath, source; | ||
path = callsite.getFileName(); | ||
if (!CND.isa_text(path)) { | ||
return debug('^3736^', rpr(path)); | ||
} else { | ||
relpath = PATH.relative(process.cwd(), path); | ||
linenr = callsite.getLineNumber(); | ||
echo(CND.white(`${relpath} #${linenr}:`)); | ||
if (!path.startsWith('internal/')) { | ||
source = get_context(path, linenr); | ||
return echo(CND.yellow(source)); | ||
} | ||
var i, len, line, linenr, path, relpath, source; | ||
if (!isa_text((path = callsite.getFileName()))) { | ||
alert(grey('—'.repeat(108))); | ||
return null; | ||
} | ||
relpath = PATH.relative(process.cwd(), path); | ||
linenr = callsite.getLineNumber(); | ||
if (path.startsWith('internal/')) { | ||
alert(grey(`${relpath} #${linenr}`)); | ||
return null; | ||
} | ||
alert(); | ||
// alert steel bold reverse ( "#{relpath} ##{linenr}:" ).padEnd 108 | ||
alert(gold(`${bold(relpath)} #${linenr}:`.padEnd(108))); | ||
source = get_context(path, linenr); | ||
for (i = 0, len = source.length; i < len; i++) { | ||
line = source[i]; | ||
alert(line); | ||
} | ||
return null; | ||
}); | ||
@@ -107,5 +115,4 @@ return null; | ||
var head, i, len, line, message, print, ref, ref1, tail; | ||
// debug '55567', rpr exception | ||
print = alert; | ||
message = 'ROGUE EXCEPTION: ' + ((ref = exception != null ? exception.message : void 0) != null ? ref : "an unrecoverable condition occurred"); | ||
message = ' EXCEPTION: ' + ((ref = exception != null ? exception.message : void 0) != null ? ref : "an unrecoverable condition occurred"); | ||
if ((exception != null ? exception.where : void 0) != null) { | ||
@@ -115,3 +122,3 @@ message += '\n--------------------\n' + exception.where + '\n--------------------'; | ||
[head, ...tail] = message.split('\n'); | ||
print(CND.reverse(' ' + head + ' ')); | ||
print(reverse(' ' + head + ' ')); | ||
for (i = 0, len = tail.length; i < len; i++) { | ||
@@ -121,35 +128,12 @@ line = tail[i]; | ||
} | ||
/* TAINT should have a way to set exit code explicitly */ | ||
debug('^55663^', exception); | ||
if ((exception != null ? exception.stack : void 0) != null) { | ||
return show_error_with_source_context(exception); | ||
show_error_with_source_context(exception); | ||
} else { | ||
return whisper((ref1 = exception != null ? exception.stack : void 0) != null ? ref1 : "(exception undefined, no stack)"); | ||
whisper((ref1 = exception != null ? exception.stack : void 0) != null ? ref1 : "(exception undefined, no stack)"); | ||
} | ||
return process.exitCode = 1; | ||
}; | ||
// setImmediate -> process.exit 1 | ||
this.exit_handler = this.exit_handler.bind(this); | ||
// debug 'µ55531', __filename | ||
// debug 'µ55531', "app:", typeof app | ||
// check for process.type: | ||
// if process.type is 'renderer' | ||
// # if typeof app is 'undefined' | ||
// process.on 'uncaughtException', @exit_handler | ||
// process.on 'unhandledRejection', @exit_handler | ||
// else | ||
// urge "µ55531 using electron-unhandled" | ||
// ( require 'electron-unhandled' ) { showDialog: true, logger: @exit_handler, } | ||
// if process.type is 'renderer' | ||
// window.addEventListener 'error', ( event ) => | ||
// event.preventDefault() | ||
// warn 'µ44333', "error:", ( k for k of event ) | ||
// window.addEventListener 'unhandledrejection', ( event ) => | ||
// event.preventDefault() | ||
// # warn 'µ44333', "unhandled rejection:", ( k for k of event ) | ||
// warn 'µ44333', "unhandled rejection:", event.reason?.message ? "(no message)" | ||
//########################################################################################################### | ||
@@ -156,0 +140,0 @@ if (global[Symbol.for('cnd-exception-handler')] == null) { |
{ | ||
"name": "cnd", | ||
"version": "4.7.3", | ||
"version": "4.8.0", | ||
"description": "a grab-bag NodeJS package mainly for functionalities that used to live in coffeenode-trm, coffeenode-bitsnpieces, and coffeenode-types", | ||
"main": "lib/main.js", | ||
"bin": { | ||
"nodexh": "lib/nodexh.js" | ||
}, | ||
"scripts": { | ||
@@ -7,0 +10,0 @@ "build": "coffee --map -o lib -c src", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
428770
48
3258
5