Skip to content

Commit

Permalink
fix(cli): don't log internal fields in error detail
Browse files Browse the repository at this point in the history
  • Loading branch information
thsig committed Jun 24, 2019
1 parent b6bdf87 commit 5e02c5d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions garden-service/src/logger/renderers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import hasAnsi = require("has-ansi")

import { LogEntry, EmojiName } from "./log-entry"
import { JsonLogEntry } from "./writers/json-terminal-writer"
import { highlightYaml } from "../util/util"
import { highlightYaml, deepFilter } from "../util/util"
import { isNumber } from "util"

export type ToRender = string | ((...args: any[]) => string)
export type Renderer = [ToRender, any[]] | ToRender[]
Expand Down Expand Up @@ -90,10 +91,14 @@ export function renderError(entry: LogEntry) {
const { detail, message, stack } = error
let out = stack || message

const sanitized = JSON.parse(CircularJSON.stringify(detail))
// We recursively filter out internal fields (i.e. having names starting with _).
const filteredDetail = deepFilter(detail, (_, key: string | number) => {
return isNumber(key) || !key.startsWith("_")
})

if (!isEmpty(detail)) {
if (!isEmpty(filteredDetail)) {
try {
const sanitized = JSON.parse(CircularJSON.stringify(filteredDetail))
const yamlDetail = yaml.safeDump(sanitized, { noRefs: true, skipInvalid: true })
out += `\nError Details:\n${yamlDetail}`
} catch (err) {
Expand Down

0 comments on commit 5e02c5d

Please sign in to comment.