{"record":{"id":"2cb007e839cced93","repo":"petkaantonov/bluebird","slug":"expecting-a-function-but-got-s-2cb007","errorCode":null,"errorMessage":"expecting a function but got %s","messagePattern":"expecting a function but got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/promisify.js","lineNumber":282,"sourceCode":"                return makeNodePromisified(key, THIS, key,\n                                           fn, suffix, multiArgs);\n            });\n            util.notEnumerableProp(promisified, \"__isPromisified__\", true);\n            obj[promisifiedKey] = promisified;\n        }\n    }\n    util.toFastProperties(obj);\n    return obj;\n}\n\nfunction promisify(callback, receiver, multiArgs) {\n    return makeNodePromisified(callback, receiver, undefined,\n                                callback, null, multiArgs);\n}\n\nPromise.promisify = function (fn, options) {\n    if (typeof fn !== \"function\") {\n        throw new TypeError(FUNCTION_ERROR + util.classString(fn));\n    }\n    if (isPromisified(fn)) {\n        return fn;\n    }\n    options = Object(options);\n    var receiver = options.context === undefined ? THIS : options.context;\n    var multiArgs = !!options.multiArgs;\n    var ret = promisify(fn, receiver, multiArgs);\n    util.copyDescriptors(fn, ret, propsFilter);\n    return ret;\n};\n\nPromise.promisifyAll = function (target, options) {\n    if (typeof target !== \"function\" && typeof target !== \"object\") {\n        throw new TypeError(PROMISIFY_TYPE_ERROR);\n    }\n    options = Object(options);\n    var multiArgs = !!options.multiArgs;","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/petkaantonov/bluebird/blob/c220cfe480868e2f5c5de4fe8bb3b04b97588d7f/src/promisify.js#L264-L300","documentation":"`Promise.promisify(fn)` converts a Node-style callback function into a promise-returning one; it validates that `fn` is a function and throws this TypeError otherwise. Note that a function already promisified is returned as-is rather than throwing.","triggerScenarios":"`Promise.promisify(undefined)`; passing a method name string instead of the function (`Promise.promisify('readFile')`); destructuring/config lookups yielding undefined before the call.","commonSituations":"Wrong import shape (default vs named import) so the target is undefined; promisifying an object method loses `this` and people pass wrong values; old code paths where the module export changed.","solutions":["Pass the function itself: `Promise.promisify(fs.readFile)`.","If promisifying a method needing a receiver, use `Promise.promisify(fn, { context: obj })`.","Verify the value is defined and a function before calling promisify (log typeof)."],"exampleFix":"// before\nconst readFile = Promise.promisify('readFile');\n// after\nconst readFile = Promise.promisify(require('fs').readFile);","handlingStrategy":"type-guard","validationCode":"if (typeof fn !== 'function') {\n  throw new TypeError('promisify expects a function, got ' + typeof fn);\n}\nconst promisified = Promise.promisify(fn);","typeGuard":"const isNodeStyleFn = (v) => typeof v === 'function';","tryCatchPattern":"let promisified;\ntry { promisified = Promise.promisify(fn); } catch (e) {\n  if (e instanceof TypeError) throw new Error('Cannot promisify: target is ' + typeof fn);\n  throw e;\n}","preventionTips":["Confirm the import/require shape so the value is a defined function.","Promisify bound methods or pass `{ context: obj }` for receivers.","Add typeof checks at module boundaries before promisifying."],"tags":["typeerror","promisify","wrong-argument"],"backgroundTag":"callback-not-a-function","analyzedSha":"c220cfe480868e2f5c5de4fe8bb3b04b97588d7f","analyzedAt":"2026-09-02T02:30:20.863Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}