{"record":{"id":"3314268f258185ed","repo":"pinojs/pino","slug":"unknown-msgprefix-type-typeof-msgprefix-exp","errorCode":null,"errorMessage":"Unknown msgPrefix type \"${typeof msgPrefix}\" - expected \"string\"","messagePattern":"Unknown msgPrefix type \"(.+?)\" - expected \"string\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pino.js","lineNumber":166,"sourceCode":"  })\n\n  let chindings = ''\n  if (base !== null) {\n    if (name === undefined) {\n      chindings = coreChindings(base)\n    } else {\n      chindings = coreChindings(Object.assign({}, base, { name }))\n    }\n  }\n\n  const time = (timestamp instanceof Function)\n    ? timestamp\n    : (timestamp ? epochTime : nullTime)\n  const timeSliceIndex = time().indexOf(':') + 1\n\n  if (useOnlyCustomLevels && !customLevels) throw Error('customLevels is required if useOnlyCustomLevels is set true')\n  if (mixin && typeof mixin !== 'function') throw Error(`Unknown mixin type \"${typeof mixin}\" - expected \"function\"`)\n  if (msgPrefix && typeof msgPrefix !== 'string') throw Error(`Unknown msgPrefix type \"${typeof msgPrefix}\" - expected \"string\"`)\n\n  assertDefaultLevelFound(level, customLevels, useOnlyCustomLevels)\n  const levels = mappings(customLevels, useOnlyCustomLevels)\n\n  if (stream && stream[transportUsesMultistreamSym] === true) {\n    let sampleLabel = typeof level === 'string' ? level : undefined\n    if (!sampleLabel || levels[sampleLabel] === undefined) {\n      sampleLabel = Object.keys(levels)[0]\n    }\n    const sampleNumber = levels[sampleLabel]\n    let ok = false\n    try {\n      const formatted = formatters.level(sampleLabel, sampleNumber)\n      ok = formatted && typeof formatted === 'object' && formatted.level === sampleNumber\n    } catch {\n      ok = false\n    }\n","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/pinojs/pino/blob/5aa62305c57709ebd6f6b7c328e8830eeb29b297/pino.js#L148-L184","documentation":"The msgPrefix option, prepended to every log message, must be a string. If opts.msgPrefix is truthy but of another type (number, object, etc.), Pino throws with the encountered typeof. Fails at logger creation time.","triggerScenarios":"pino({ msgPrefix: 123 }) or msgPrefix: someObject/array; interpolation mistakes like msgPrefix: `[worker] ${id}.` producing a non-string; config from JSON/YAML where the value wasn't quoted/parsed as a string.","commonSituations":"Copy-paste edits changing a string prefix to a template/object; build tooling or env substitution injecting a non-string (e.g. numeric port used as prefix); YAML parsing \"123\" as a number.","solutions":["Pass a string: msgPrefix: 'PID ' + pid or String(template) for dynamic values.","Coerce with String(opts.msgPrefix) before constructing options if the source may be non-string.","Fix quoting in config files so the value parses as a string.","Validate typeof opts.msgPrefix === 'string' in wrapper code before calling pino."],"exampleFix":"// before\nconst logger = pino({ msgPrefix: 42 })\n// after\nconst logger = pino({ msgPrefix: 'worker 42: ' })","handlingStrategy":"validation","validationCode":"function validateMsgPrefix(opts) {\n  if (opts && opts.msgPrefix && typeof opts.msgPrefix !== 'string') {\n    throw new TypeError(`msgPrefix must be a string, got ${typeof opts.msgPrefix}`)\n  }\n  return true\n}","typeGuard":"const hasStringMsgPrefix = (opts) => !opts.msgPrefix || typeof opts.msgPrefix === 'string'","tryCatchPattern":"try {\n  const logger = pino(opts)\n} catch (err) {\n  if (err.message.startsWith('Unknown msgPrefix type')) {\n    logger = pino({ ...opts, msgPrefix: String(opts.msgPrefix) })\n  } else throw err\n}","preventionTips":["Always pass msgPrefix as a string literal or String(...) coerced value","Quote msgPrefix values in YAML/JSON configs so numbers stay strings","Validate option types centrally before constructing loggers in wrapper modules"],"tags":["pino","configuration","msgprefix","type-error"],"backgroundTag":"wrong-option-type","analyzedSha":"5aa62305c57709ebd6f6b7c328e8830eeb29b297","analyzedAt":"2026-09-02T22:05:21.418Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}