diff --git a/lib/logger/config-serializer.ts b/lib/logger/config-serializer.ts index 240cbd2f73c22df529ba62a868e8ddfd3f6fecb2..cc54936e583c4031d58c5c8847d4897139bb3b74 100644 --- a/lib/logger/config-serializer.ts +++ b/lib/logger/config-serializer.ts @@ -14,15 +14,17 @@ export default function configSerializer( const arrayFields = ['packageFiles', 'upgrades']; return traverse(config).map(function scrub(val: string) { - if (val && templateFields.includes(this.key)) { - this.update('[Template]'); - } - if (val && contentFields.includes(this.key)) { - this.update('[content]'); - } - // istanbul ignore if - if (val && arrayFields.includes(this.key)) { - this.update('[Array]'); + if (this.key && val) { + if (templateFields.includes(this.key)) { + this.update('[Template]'); + } + if (contentFields.includes(this.key)) { + this.update('[content]'); + } + // istanbul ignore if + if (arrayFields.includes(this.key)) { + this.update('[Array]'); + } } }); } diff --git a/lib/logger/index.spec.ts b/lib/logger/index.spec.ts index d55c13a68b667c569f4519c13e7fda0ea0d7e5fa..3a3e10966360e143246d034b19f71fad20de159b 100644 --- a/lib/logger/index.spec.ts +++ b/lib/logger/index.spec.ts @@ -92,10 +92,10 @@ describe('logger/index', () => { }); it('supports file-based logging', () => { - let chunk = null; + let chunk = ''; fs.createWriteStream.mockReturnValueOnce({ writable: true, - write(x) { + write(x: string) { chunk = x; }, }); @@ -112,10 +112,10 @@ describe('logger/index', () => { }); it('handles cycles', () => { - let logged = null; + let logged: Record<string, any> = {}; fs.createWriteStream.mockReturnValueOnce({ writable: true, - write(x) { + write(x: string) { logged = JSON.parse(x); }, }); @@ -126,7 +126,7 @@ describe('logger/index', () => { level: 'error', }); - const meta = { foo: null, bar: [] }; + const meta: Record<string, any> = { foo: null, bar: [] }; meta.foo = meta; meta.bar.push(meta); logger.error(meta, 'foo'); @@ -137,10 +137,10 @@ describe('logger/index', () => { }); it('sanitizes secrets', () => { - let logged = null; + let logged: Record<string, any> = {}; fs.createWriteStream.mockReturnValueOnce({ writable: true, - write(x) { + write(x: string) { logged = JSON.parse(x); }, }); diff --git a/lib/logger/index.ts b/lib/logger/index.ts index 5dbd16ff66e8b061461ba6b1ddae47854c98f6b6..66f91378fdc23644a2d22cd88cc09a10d12780f4 100644 --- a/lib/logger/index.ts +++ b/lib/logger/index.ts @@ -9,7 +9,7 @@ import type { BunyanRecord, Logger } from './types'; import { ProblemStream, withSanitizer } from './utils'; let logContext: string = process.env.LOG_CONTEXT ?? nanoid(); -let curMeta = {}; +let curMeta: Record<string, unknown> = {}; const problems = new ProblemStream(); diff --git a/lib/logger/types.ts b/lib/logger/types.ts index a7d081e0a28055e2fb7b59793a24c61c97ddc62e..a4fa07fe2da407b4488bb32de2d7b8fb435ff6cd 100644 --- a/lib/logger/types.ts +++ b/lib/logger/types.ts @@ -30,5 +30,9 @@ export interface BunyanRecord extends Record<string, any> { export type BunyanStream = (NodeJS.WritableStream | Stream) & { writable?: boolean; - write: (chunk: BunyanRecord, enc, cb) => void; + write: ( + chunk: BunyanRecord, + enc: BufferEncoding, + cb: (err?: Error | null) => void + ) => void; }; diff --git a/lib/logger/utils.ts b/lib/logger/utils.ts index ab00f9746e5b4dda7f04d0f804202b065bf73ece..0bb5ffdaf317d31851ac50e9e26d641b6f09804d 100644 --- a/lib/logger/utils.ts +++ b/lib/logger/utils.ts @@ -71,9 +71,10 @@ export default function prepareError(err: Error): Record<string, unknown> { }; response.options = options; - for (const k of ['username', 'password', 'method', 'http2']) { - options[k] = err.options[k]; - } + options.username = err.options.username; + options.password = err.options.password; + options.method = err.options.method; + options.http2 = err.options.http2; // istanbul ignore else if (err.response) { @@ -174,7 +175,11 @@ export function withSanitizer(streamConfig: bunyan.Stream): bunyan.Stream { const stream = streamConfig.stream as BunyanStream; if (stream?.writable) { - const write = (chunk: BunyanRecord, enc, cb): void => { + const write = ( + chunk: BunyanRecord, + enc: BufferEncoding, + cb: (err?: Error | null) => void + ): void => { const raw = sanitizeValue(chunk); const result = streamConfig.type === 'raw' diff --git a/tsconfig.strict.json b/tsconfig.strict.json index dbadb581e39e05fa98d070abdae10215e60ebf06..2f67feec4ce983fcfc815599b4dc02b950c3fca7 100644 --- a/tsconfig.strict.json +++ b/tsconfig.strict.json @@ -46,6 +46,12 @@ "./lib/globals.d.ts", "./lib/logger/__mocks__/index.ts", "./lib/logger/cmd-serializer.ts", + "./lib/logger/config-serializer.ts", + "./lib/logger/err-serializer.ts", + "./lib/logger/index.ts", + "./lib/logger/pretty-stdout.ts", + "./lib/logger/types.ts", + "./lib/logger/utils.ts", "./lib/manager/argocd/types.ts", "./lib/manager/azure-pipelines/types.ts", "./lib/manager/bazel/types.ts",