{"record":{"id":"738349e4ddff610c","repo":"pinojs/pino","slug":"unknown-mixin-type-typeof-mixin-expected-f","errorCode":null,"errorMessage":"Unknown mixin type \"${typeof mixin}\" - expected \"function\"","messagePattern":"Unknown mixin type \"(.+?)\" - expected \"function\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pino.js","lineNumber":165,"sourceCode":"    [formattersSym]: allFormatters\n  })\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    }","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/pinojs/pino/blob/5aa62305c57709ebd6f6b7c328e8830eeb29b297/pino.js#L147-L183","documentation":"The mixin option must be a function that returns an object merged into each log line. If opts.mixin is truthy but not a function, Pino throws with the actual typeof found. This fails fast at logger creation rather than per-log-call.","triggerScenarios":"pino({ mixin: someObject }) or mixin set to a string/number/boolean; passing the result of calling the mixin (mixin: myMixin()) instead of the function itself; config deserialized from JSON where functions can't survive.","commonSituations":"Loading logger options from JSON/YAML config files (functions lost); wrapping mistakes like mixin: mixinFactory() returning an object; typos assigning an object where a callback is expected.","solutions":["Pass a function: mixin: () => ({ ... }) or mixin: (context) => ({ ...context }).","If the mixin is generated, pass the factory's returned function, not an intermediate object.","If options come from config files, re-attach functions in code after loading the config.","Check typeof opts.mixin === 'function' before calling pino in wrapper code."],"exampleFix":"// before\nconst logger = pino({ mixin: { requestId: 'abc' } })\n// after\nconst logger = pino({ mixin: () => ({ requestId: 'abc' }) })","handlingStrategy":"type-guard","validationCode":"function validateMixin(opts) {\n  if (opts && opts.mixin && typeof opts.mixin !== 'function') {\n    throw new TypeError(`mixin must be a function, got ${typeof opts.mixin}`)\n  }\n  return true\n}","typeGuard":"const isMixinFn = (opts) => !opts.mixin || typeof opts.mixin === 'function'","tryCatchPattern":"try {\n  const logger = pino(opts)\n} catch (err) {\n  if (err.message.startsWith('Unknown mixin type')) {\n    logger = pino({ ...opts, mixin: undefined }) // or wrap: mixin: () => opts.mixin\n  } else throw err\n}","preventionTips":["Never call the mixin when assigning it: mixin: myMixin, not mixin: myMixin()","Re-hydrate function options after loading config from JSON/YAML files","Type-check options in wrappers: assert typeof opts.mixin === 'function'"],"tags":["pino","configuration","mixin","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"}