Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
trentm committed Oct 25, 2023
1 parent 20beb2f commit 01e159a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
3 changes: 2 additions & 1 deletion packages/ecs-winston-format/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ class EcsWinstonTransform {
// always a string to avoid its type varying depending on the value.
if (err.cause) {
ecsFields.error.cause = err.cause instanceof Error
? err.cause.stack : err.cause.toString()
? err.cause.stack
: err.cause.toString()
}
}

Expand Down
34 changes: 17 additions & 17 deletions packages/ecs-winston-format/test/errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test('log.info("msg", new Error("boom"))', t => {
// Set `convertErr: false` to ensure this form of passing an Error to
// a Winston logger is handled by default.
format: ecsFormat({ convertErr: false }),
defaultMeta: { aField: 'defaultMeta field value'},
defaultMeta: { aField: 'defaultMeta field value' },
transports: [cap]
})

Expand All @@ -53,9 +53,9 @@ test('log.info("msg", new Error("boom"))', t => {
t.equal(rec.aField, undefined)
t.equal(rec.error.type, 'Error')
t.equal(rec.error.message, 'boom')
t.match(rec.error.stack_trace, /^Error: boom\n at/)
t.match(rec.error.stack_trace, /^Error: boom\n {4}at/)
t.equal(rec.error.aField, 'err field value')
t.match(rec.error.cause, /^Error: the cause\n at/)
t.match(rec.error.cause, /^Error: the cause\n {4}at/)
t.end()
})

Expand All @@ -76,7 +76,7 @@ test('uncaughtException winston log error message', t => {
t.equal(rec.message, 'uncaughtException: funcb boom', 'message')
t.equal(rec.error.type, 'Error', 'error.type')
t.equal(rec.error.message, 'funcb boom', 'error.message')
t.match(rec.error.stack_trace, /^Error: funcb boom\n at/, 'error.stack_trace')
t.match(rec.error.stack_trace, /^Error: funcb boom\n {4}at/, 'error.stack_trace')
t.equal(rec.error.code, 42, 'error.code')
t.equal(rec.exception, true, 'exception')
t.end()
Expand All @@ -101,7 +101,7 @@ test('unhandledRejection winston log error message', t => {
t.equal(rec.message, 'unhandledRejection: funcb boom', 'message')
t.equal(rec.error.type, 'Error', 'error.type')
t.equal(rec.error.message, 'funcb boom', 'error.message')
t.match(rec.error.stack_trace, /^Error: funcb boom\n at/, 'error.stack_trace')
t.match(rec.error.stack_trace, /^Error: funcb boom\n {4}at/, 'error.stack_trace')
t.equal(rec.error.code, 42, 'error.code')
t.equal(rec.exception, true, 'exception')
t.end()
Expand All @@ -113,7 +113,7 @@ test('log.info(new Error("boom"))', t => {
const cap = new CaptureTransport()
const log = winston.createLogger({
format: ecsFormat({ convertErr: true }),
defaultMeta: { aField: 'defaultMeta field value'},
defaultMeta: { aField: 'defaultMeta field value' },
transports: [cap]
})

Expand All @@ -129,7 +129,7 @@ test('log.info(new Error("boom"))', t => {
t.equal(rec.aField, 'defaultMeta field value', 'aField')
t.equal(rec.error.type, 'Error', 'error.type')
t.equal(rec.error.message, 'boom', 'error.message')
t.match(rec.error.stack_trace, /^Error: boom\n at/, 'error.stack_trace')
t.match(rec.error.stack_trace, /^Error: boom\n {4}at/, 'error.stack_trace')
// Winston mixes `err` properties and `defaultMeta` at the top-level, so
// conflicts result in lost date.
t.equal(rec.error.aField, 'defaultMeta field value', 'error.aField')
Expand All @@ -141,14 +141,14 @@ test('log.info(new Error("boom"), {...})', t => {
const cap = new CaptureTransport()
const log = winston.createLogger({
format: ecsFormat({ convertErr: true }),
defaultMeta: { aField: 'defaultMeta field value'},
defaultMeta: { aField: 'defaultMeta field value' },
transports: [cap]
})

const errCause = new Error('the cause')
const err = new Error('boom', { cause: errCause })
err.aField = 'err field value'
log.info(err, { aField: 'splat field value'})
log.info(err, { aField: 'splat field value' })

const rec = cap.records[0]
t.ok(validate(rec))
Expand All @@ -157,17 +157,17 @@ test('log.info(new Error("boom"), {...})', t => {
t.equal(rec.aField, 'splat field value', 'aField')
t.equal(rec.error.type, 'Error', 'error.type')
t.equal(rec.error.message, 'boom', 'error.message')
t.match(rec.error.stack_trace, /^Error: boom\n at/, 'error.stack_trace')
t.match(rec.error.stack_trace, /^Error: boom\n {4}at/, 'error.stack_trace')
t.equal(rec.error.aField, 'err field value', 'error.aField')
t.match(rec.error.cause, /^Error: the cause\n at/, 'error.cause')
t.match(rec.error.cause, /^Error: the cause\n {4}at/, 'error.cause')
t.end()
})

test('log.info(new Error("")) with empty err.message', t => {
const cap = new CaptureTransport()
const log = winston.createLogger({
format: ecsFormat({ convertErr: true }),
defaultMeta: { aField: 'defaultMeta field value'},
defaultMeta: { aField: 'defaultMeta field value' },
transports: [cap]
})

Expand All @@ -183,17 +183,17 @@ test('log.info(new Error("")) with empty err.message', t => {
t.equal(rec.aField, 'defaultMeta field value', 'aField')
t.equal(rec.error.type, 'Error', 'error.type')
t.equal(rec.error.message, '', 'error.message')
t.match(rec.error.stack_trace, /^Error: \n at/, 'error.stack_trace')
t.match(rec.error.stack_trace, /^Error: \n {4}at/, 'error.stack_trace')
t.equal(rec.error.aField, 'err field value', 'error.aField')
t.match(rec.error.cause, /^Error: the cause\n at/, 'error.cause')
t.match(rec.error.cause, /^Error: the cause\n {4}at/, 'error.cause')
t.end()
})

test('log.info("msg", { err: new Error("boom") })', t => {
const cap = new CaptureTransport()
const log = winston.createLogger({
format: ecsFormat({ convertErr: true }),
defaultMeta: { aField: 'defaultMeta field value'},
defaultMeta: { aField: 'defaultMeta field value' },
transports: [cap]
})

Expand All @@ -209,8 +209,8 @@ test('log.info("msg", { err: new Error("boom") })', t => {
t.equal(rec.aField, 'splat field value', 'aField')
t.equal(rec.error.type, 'Error', 'error.type')
t.equal(rec.error.message, 'boom', 'error.message')
t.match(rec.error.stack_trace, /^Error: boom\n at/, 'error.stack_trace')
t.match(rec.error.stack_trace, /^Error: boom\n {4}at/, 'error.stack_trace')
t.equal(rec.error.aField, 'err field value', 'error.aField')
t.match(rec.error.cause, /^Error: the cause\n at/, 'error.cause')
t.match(rec.error.cause, /^Error: the cause\n {4}at/, 'error.cause')
t.end()
})
5 changes: 3 additions & 2 deletions packages/ecs-winston-format/test/uncaught-exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
const ecsFormat = require('../') // @elastic/ecs-winston-format
const winston = require('winston')

// eslint-disable-next-line
const log = winston.createLogger({
level: 'info',
format: ecsFormat(),
Expand All @@ -30,13 +31,13 @@ const log = winston.createLogger({
]
})

function funcb() {
function funcb () {
const e = new Error('funcb boom')
e.code = 42
throw e
}

function funca() {
function funca () {
funcb()
}

Expand Down
5 changes: 3 additions & 2 deletions packages/ecs-winston-format/test/unhandled-rejection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
const ecsFormat = require('../') // @elastic/ecs-winston-format
const winston = require('winston')

// eslint-disable-next-line
const log = winston.createLogger({
level: 'info',
format: ecsFormat(),
Expand All @@ -31,13 +32,13 @@ const log = winston.createLogger({
]
})

async function funcb() {
async function funcb () {
const e = new Error('funcb boom')
e.code = 42
throw e
}

async function funca() {
async function funca () {
await funcb()
}

Expand Down
1 change: 0 additions & 1 deletion packages/ecs-winston-format/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ module.exports = {
validate,
CaptureTransport
}

0 comments on commit 01e159a

Please sign in to comment.