{"record":{"id":"2ae273d95c1d1aa5","repo":"hexojs/hexo","slug":"fn-must-be-a-function-2ae273","errorCode":null,"errorMessage":"fn must be a function","messagePattern":"fn must be a function","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/extend/processor.ts","lineNumber":38,"sourceCode":"  public store: Store;\n\n  constructor() {\n    this.store = [];\n  }\n\n  list(): Store {\n    return this.store;\n  }\n\n  register(fn: StoreFunction): void;\n  register(pattern: patternType, fn: StoreFunction): void;\n  register(pattern: patternType | StoreFunction, fn?: StoreFunction): void {\n    if (!fn) {\n      if (typeof pattern === 'function') {\n        fn = pattern;\n        pattern = /(.*)/;\n      } else {\n        throw new TypeError('fn must be a function');\n      }\n    }\n\n    if (fn.length > 1) {\n      fn = Promise.promisify(fn);\n    } else {\n      fn = Promise.method(fn);\n    }\n\n    this.store.push({\n      pattern: new Pattern(pattern as patternType),\n      process: fn\n    });\n  }\n}\n\nexport = Processor;\n","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/hexojs/hexo/blob/059cb17494d0632a053c24077f5bcb6ae92acc51/lib/extend/processor.ts#L20-L56","documentation":"Thrown by Processor.register when the resolved processor is not a function. Hexo's source processor supports (fn) and (pattern, fn); if the lone argument is not a function and no fn follows, registration fails.","triggerScenarios":"Calling register('/\\.md$/') with no function, or register(pattern, null) where the second argument is not a function.","commonSituations":"A plugin passes a pattern object/string as the only argument and forgets the handler, or the imported handler is undefined.","solutions":["Pass a function as the processor (register(fn)) or as the second argument (register(pattern, fn)).","Verify imported processor symbols are defined.","Do not pass a config object as the sole argument."],"exampleFix":"// before\nhexo.extend.processor.register(/\\.md$/);\n// after\nhexo.extend.processor.register(/\\.md$/, file => { /* ... */ });","handlingStrategy":"type-guard","validationCode":"if (typeof fn !== 'function') throw new Error('processor must be a function');\nhexo.extend.processor.register(pattern, fn);","typeGuard":"const isProcessorFn = (x: unknown): x is (...a: any[]) => any => typeof x === 'function';","tryCatchPattern":null,"preventionTips":["Use the explicit (pattern, fn) form over the single-argument form.","Confirm imported processor modules export a function.","Type registration helpers to reject non-functions at compile time."],"tags":["processor","validation","plugin","typescript"],"backgroundTag":null,"analyzedSha":"059cb17494d0632a053c24077f5bcb6ae92acc51","analyzedAt":"2026-08-12T20:52:05.731Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}