{"record":{"id":"a097edfea7299990","repo":"hexojs/hexo","slug":"name-must-be-a-string","errorCode":null,"errorMessage":"name must be a string!","messagePattern":"name must be a string!","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/hexo/locals.ts","lineNumber":13,"sourceCode":"import { Cache } from 'hexo-util';\n\nclass Locals {\n  public cache: InstanceType<typeof Cache>;\n  public getters: Record<string, () => any>;\n\n  constructor() {\n    this.cache = new Cache();\n    this.getters = {};\n  }\n\n  get(name: string): any {\n    if (typeof name !== 'string') throw new TypeError('name must be a string!');\n\n    return this.cache.apply(name, () => {\n      const getter = this.getters[name];\n      if (!getter) return;\n\n      return getter();\n    });\n  }\n\n  set(name: string, value: any): this {\n    if (typeof name !== 'string') throw new TypeError('name must be a string!');\n    if (value == null) throw new TypeError('value is required!');\n\n    const getter = typeof value === 'function' ? value : () => value;\n\n    this.getters[name] = getter;\n    this.cache.del(name);\n","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/hexojs/hexo/blob/059cb17494d0632a053c24077f5bcb6ae92acc51/lib/hexo/locals.ts#L1-L31","documentation":"Thrown by Locals.get when 'name' is not a string. Hexo locals are memoized computed values keyed by name; the cache.apply call requires a string key, so a non-string name is rejected before lookup.","triggerScenarios":"Calling hexo.locals.get(undefined), get(null), get(123), or get(someObject) where name is not a string.","commonSituations":"A plugin/theme iterates over object keys but passes the value instead of the key, or a variable meant to hold a name is uninitialized.","solutions":["Ensure the name argument is a string before calling get.","When iterating keys, pass the key (string), not the value.","Validate dynamic name sources with typeof checks."],"exampleFix":"// before\nhexo.locals.get(maybeName);\n// after\nif (typeof maybeName === 'string') hexo.locals.get(maybeName);","handlingStrategy":"validation","validationCode":"if (typeof name !== 'string') throw new Error('locals.get name must be a string');\nhexo.locals.get(name);","typeGuard":"const isStringName = (n: unknown): n is string => typeof n === 'string';","tryCatchPattern":null,"preventionTips":["When iterating getters, pass the key string, not the value.","Initialize name variables explicitly.","Add type annotations so non-string names fail at compile time."],"tags":["locals","cache","validation","typescript"],"backgroundTag":null,"analyzedSha":"059cb17494d0632a053c24077f5bcb6ae92acc51","analyzedAt":"2026-08-12T20:52:05.731Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}