Skip to content

Commit

Permalink
fix: bad timestamp values could crash log command
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed May 24, 2018
1 parent 6ccc9d0 commit 4383d75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,19 @@ export class LogsCommand extends Command<typeof logsArgs, typeof logsOpts> {
// TODO: use basic logger (no need for fancy stuff here, just causes flickering)
stream.forEach((entry) => {
// TODO: color each service differently for easier visual parsing
ctx.log.info({ section: entry.serviceName, msg: [entry.timestamp.toISOString(), chalk.white(entry.msg)] })
let timestamp = " "

// bad timestamp values can cause crash if not caught
if (entry.timestamp) {
try {
timestamp = entry.timestamp.toISOString()
} catch { }
}

ctx.log.info({
section: entry.serviceName,
msg: [timestamp, chalk.white(entry.msg)],
})
})

// NOTE: This will work differently when we have Elasticsearch set up for logging, but is
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/kubernetes/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export async function getServiceLogs(

const namespace = await getAppNamespace(ctx, provider)
const proc = kubectl(context, namespace).spawn(kubectlArgs)
let timestamp: Date

proc.stdout
.pipe(split())
Expand All @@ -352,7 +353,9 @@ export async function getServiceLogs(
return
}
const [timestampStr, msg] = splitFirst(s, " ")
const timestamp = moment(timestampStr).toDate()
try {
timestamp = moment(timestampStr).toDate()
} catch { }
stream.write({ serviceName: service.name, timestamp, msg })
})

Expand Down

0 comments on commit 4383d75

Please sign in to comment.