Skip to content

Commit a993f6a

Browse files
committed
Simplify events printing
1 parent ef6d280 commit a993f6a

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

src/message.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const { inspect } = require('util')
44

5-
const { printMultiline, print, prettify } = require('./serialize')
5+
const { serialize, prettify } = require('./serialize')
66

77
// Retrieve `message` which sums up all information that can be gathered about
88
// the event.
@@ -37,24 +37,22 @@ const defaultGetMessage = function({
3737
}
3838

3939
const uncaughtException = function({ error }) {
40-
return `An exception was thrown but not caught
41-
${print(error)}`
40+
return `This exception was thrown but not caught: ${serialize(error)}`
4241
}
4342

4443
const warning = function({ error, error: { code, detail = '' } }) {
4544
const codeMessage = code === undefined ? '' : `(${code}) `
46-
return `${codeMessage}${detail}
47-
${print(error)}`
45+
return `${codeMessage}${detail}${serialize(error)}`
4846
}
4947

5048
const unhandledRejection = function({ promiseValue }) {
51-
return `A promise was rejected but not handled
52-
Promise was rejected with: ${printMultiline(promiseValue)}`
49+
return `This promise was rejected but not handled: ${serialize(promiseValue)}`
5350
}
5451

5552
const rejectionHandled = function({ promiseValue }) {
56-
return `A promise was rejected and handled too late
57-
Promise was rejected with: ${printMultiline(promiseValue)}`
53+
return `This promise was rejected and handled too late: ${serialize(
54+
promiseValue,
55+
)}`
5856
}
5957

6058
const multipleResolves = function({
@@ -64,9 +62,10 @@ const multipleResolves = function({
6462
secondPromiseValue,
6563
}) {
6664
const again = promiseState === secondPromiseState ? ' again' : ''
67-
return `A promise was resolved/rejected multiple times
68-
Promise was initially ${promiseState} with: ${printMultiline(promiseValue)}
69-
Promise was then ${secondPromiseState}${again} with: ${printMultiline(
65+
return `A promise was resolved/rejected multiple times. It was initially ${promiseState} with: ${serialize(
66+
promiseValue,
67+
)}
68+
It was then ${secondPromiseState}${again} with: ${serialize(
7069
secondPromiseValue,
7170
)}`
7271
}

src/serialize.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@ const { inspect } = require('util')
44

55
const { LEVELS } = require('./level')
66

7-
const printMultiline = function(value) {
8-
const valueA = print(value)
9-
// Print multiline values on the next line
10-
const valueB = valueA.includes('\n') ? `\n${valueA}` : valueA
11-
return valueB
12-
}
13-
14-
const print = function(value) {
7+
const serialize = function(value) {
158
if (value instanceof Error) {
169
return value.stack
1710
}
@@ -34,16 +27,16 @@ const prettify = function({
3427
`${bold(inverse(` ${SIGN} ${eventName} `))} ${header}`,
3528
)
3629
// Add gray color and indentation to other lines.
37-
const linesA = lines.map(line => dim(`\t${VERTICAL_BAR} ${line}`))
30+
const linesA = lines.map(line => dim(`${INDENT}${line}`))
3831

3932
const messageA = [headerA, ...linesA].join('\n')
4033
return messageA
4134
}
4235

43-
const VERTICAL_BAR = '\u2016'
36+
const INDENT_SIZE = 4
37+
const INDENT = ' '.repeat(INDENT_SIZE)
4438

4539
module.exports = {
46-
printMultiline,
47-
print,
40+
serialize,
4841
prettify,
4942
}

0 commit comments

Comments
 (0)