{"record":{"id":"e1252a4a86b97d80","repo":"petkaantonov/bluebird","slug":"generatorfunction-must-be-a-function-see-http","errorCode":null,"errorMessage":"generatorFunction must be a function\n\n    See http://goo.gl/MqrFmX\n","messagePattern":"generatorFunction must be a function\n\n    See http://goo\\.gl/MqrFmX\n","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/generators.js","lineNumber":195,"sourceCode":"        } else if (BIT_FIELD_CHECK(IS_FULFILLED)) {\n            Promise._async.invoke(\n                this._promiseFulfilled, this, maybePromise._value()\n            );\n        } else if (BIT_FIELD_CHECK(IS_REJECTED)) {\n            Promise._async.invoke(\n                this._promiseRejected, this, maybePromise._reason()\n            );\n        } else {\n            this._promiseCancelled();\n        }\n    }\n};\n\nPromise.coroutine = function (generatorFunction, options) {\n    //Throw synchronously because Promise.coroutine is semantically\n    //something you call at \"compile time\" to annotate static functions\n    if (typeof generatorFunction !== \"function\") {\n        throw new TypeError(NOT_GENERATOR_ERROR);\n    }\n    var yieldHandler = Object(options).yieldHandler;\n    var PromiseSpawn$ = PromiseSpawn;\n    var stack = new Error().stack;\n    return function () {\n        var generator = generatorFunction.apply(this, arguments);\n        var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler,\n                                      stack);\n        var ret = spawn.promise();\n        spawn._generator = generator;\n        spawn._promiseFulfilled(undefined);\n        return ret;\n    };\n};\n\nPromise.coroutine.addYieldHandler = function(fn) {\n    if (typeof fn !== \"function\") {\n        throw new TypeError(FUNCTION_ERROR + util.classString(fn));","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/petkaantonov/bluebird/blob/c220cfe480868e2f5c5de4fe8bb3b04b97588d7f/src/generators.js#L177-L213","documentation":"Promise.coroutine() wraps a generator function so it can be awaited like async/await. Because it is meant to run at 'compile time' (module load) to annotate static functions, it validates its argument synchronously and throws TypeError when generatorFunction is not a function (NOT_GENERATOR_ERROR).","triggerScenarios":"Promise.coroutine(notAFunction) — passing undefined (misnamed import), a generator object instead of the generator function itself (gen() vs gen), or a string/arbitrary value; also default imports that resolve to undefined in CommonJS/ESM interop.","commonSituations":"Wrong import style making the target undefined; calling Promise.coroutine(generatorInstance) instead of the function; using it on a regular (non-generator) function expecting it to work; babel/TS transforms removing generator syntax so the identifier no longer exists.","solutions":["Pass the generator function itself: Promise.coroutine(function* () { ... })","Fix the import so the identifier is defined (check for undefined before calling)","If targeting modern Node, drop Promise.coroutine and use native async/await","Ensure your transpiler (babel regenerator etc.) preserves generator functions","Validate typeof fn === 'function' at call sites building coroutines dynamically"],"exampleFix":"// before\nconst gen = Promise.coroutine(myGen()); // passes generator object\n// after\nconst wrapped = Promise.coroutine(myGen); // pass the function\nconst result = wrapped();","handlingStrategy":"type-guard","validationCode":"function makeCoroutine(genFn, options) {\n  if (typeof genFn !== 'function') throw new TypeError('generatorFunction must be a function, got ' + typeof genFn);\n  return Promise.coroutine(genFn, options);\n}","typeGuard":"function isGeneratorFunction(fn) {\n  return typeof fn === 'function' &&\n    fn.constructor && fn.constructor.name === 'GeneratorFunction';\n}","tryCatchPattern":"let wrapped;\ntry {\n  wrapped = Promise.coroutine(myGen);\n} catch (e) {\n  if (e instanceof Promise.TypeError) throw new Error('myGen must be a generator function, got: ' + typeof myGen);\n  throw e;\n}","preventionTips":["Pass the generator function, not an invoked generator object","Verify imports resolve (guard against undefined identifiers)","Prefer native async/await on modern runtimes instead of coroutine","Check that your transpiler preserves generator functions"],"tags":["typeerror","coroutine","generator"],"backgroundTag":"generator-function-expected","analyzedSha":"c220cfe480868e2f5c5de4fe8bb3b04b97588d7f","analyzedAt":"2026-09-02T02:30:20.863Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}