Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const addSurroundingCode = lineNumber => {
// get whatever html has rendered at this point
if (!DOMContentLoaded || !html) html = getHtml()
// simulate the raw html
const htmlLines = [ '' ].concat(html.split('\n'))
const zeroBasedLine = lineNumber - 1
const start = Math.max(zeroBasedLine - 3, 0)
const end = Math.min(zeroBasedLine + 3, htmlLines.length)
return reduce(htmlLines.slice(start, end), (accum, line, i) => {
accum[start + 1 + i] = line.length <= MAX_LINE_LENGTH ? line : line.substr(0, MAX_LINE_LENGTH)
return accum
}, {})
}
console[method] = (...args) => {
client.leaveBreadcrumb('Console output', reduce(args, (accum, arg, i) => {
// do the best/simplest stringification of each argument
let stringified = '[Unknown value]'
// this may fail if the input is:
// - an object whose [[Prototype]] is null (no toString)
// - an object with a broken toString or @@toPrimitive implementation
try { stringified = String(arg) } catch (e) {}
// if it stringifies to [object Object] attempt to JSON stringify
if (stringified === '[object Object]') {
// catch stringify errors and fallback to [object Object]
try { stringified = JSON.stringify(arg) } catch (e) {}
}
accum[`[${i}]`] = stringified
return accum
}, {
severity: method.indexOf('group') === 0 ? 'log' : method
}), 'log')
isBluebird = true
}
} catch (e) {}
const handledState = {
severity: 'error',
unhandled: true,
severityReason: { type: 'unhandledPromiseRejection' }
}
let report
if (error && hasStack(error)) {
// if it quacks like an Error…
report = new client.BugsnagReport(error.name, error.message, ErrorStackParser.parse(error), handledState, error)
if (isBluebird) {
report.stacktrace = reduce(report.stacktrace, fixBluebirdStacktrace(error), [])
}
} else {
// if it doesn't…
const msg = 'Rejection reason was not an Error. See "Promise" tab for more detail.'
report = new client.BugsnagReport(
error && error.name ? error.name : 'UnhandledRejection',
error && error.message ? error.message : msg,
[],
handledState,
error
)
// stuff the rejection reason into metaData, it could be useful
report.updateMetaData('promise', 'rejection reason', serializableReason(error))
}
client.notify(report)