{"record":{"id":"e8414b707d791979","repo":"hexojs/hexo","slug":"name-must-be-a-string-e8414b","errorCode":null,"errorMessage":"name must be a string!","messagePattern":"name must be a string!","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/plugins/helper/partial.ts","lineNumber":11,"sourceCode":"import { dirname, join } from 'path';\nimport type Hexo from '../../hexo';\nimport type { LocalsType } from '../../types';\n\ninterface Options {\n  cache?: boolean | string;\n  only?: boolean;\n}\n\nexport = (ctx: Hexo) => function partial(this: LocalsType, name: string, locals?: any, options: Options = {}) {\n  if (typeof name !== 'string') throw new TypeError('name must be a string!');\n\n  const { cache } = options;\n  const viewDir = this.view_dir;\n  const currentView = this.filename.substring(viewDir.length);\n  const path = join(dirname(currentView), name);\n  const view = ctx.theme.getView(path) || ctx.theme.getView(name);\n\n  if (!view) {\n    throw new Error(`Partial ${name} does not exist. (in ${currentView})`);\n  }\n\n  // Build locals lazily so a fragment cache hit does not copy the render context.\n  const render = () => {\n    const viewLocals: Record<string, any> = {};\n\n    if (options.only) {\n      Object.assign(viewLocals, locals);\n    } else {","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/hexojs/hexo/blob/059cb17494d0632a053c24077f5bcb6ae92acc51/lib/plugins/helper/partial.ts#L1-L29","documentation":"Thrown by the partial helper (lib/plugins/helper/partial.ts:11). partial() renders a theme partial view by name. The name is used to resolve a view under the theme's getView(), so it must be a string. A non-string name is rejected before any file lookup.","triggerScenarios":"Calling <%- partial(undefined) %> or partial(someVar) where someVar is undefined/object/number; a template variable for the partial name that was not defined in locals; passing an object expecting property access.","commonSituations":"Theme refactor where a partial name variable was removed but a template still references it; dynamic partial selection from front-matter with a missing field; typo in the variable name passed to partial().","solutions":["Pass a literal string: <%- partial('header') %>.","Guard dynamic names: <%- partialName ? partial(partialName) : '' %> after verifying typeof partialName === 'string'.","Ensure the variable supplying the name is defined in the render context."],"exampleFix":"<!-- before -->\n<%- partial(dynamicName) %>\n\n<!-- after -->\n<%- typeof dynamicName === 'string' ? partial(dynamicName) : '' %>","handlingStrategy":"type-guard","validationCode":"if (typeof name !== 'string') {\n  throw new TypeError(`partial name must be a string, got ${typeof name}`);\n}\nreturn hexo.extend.helper.get('partial').call(hexo.locals, name);","typeGuard":"const isPartialName = (v: unknown): v is string => typeof v === 'string' && v.length > 0;","tryCatchPattern":null,"preventionTips":["Use literal partial names in templates: <%- partial('header') %>.","For dynamic partials, guard with typeof name === 'string'.","Define partial-name variables in locals before referencing them."],"tags":["helper","partial","type-validation","template","theme"],"backgroundTag":null,"analyzedSha":"059cb17494d0632a053c24077f5bcb6ae92acc51","analyzedAt":"2026-08-12T20:52:05.731Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}