{"record":{"id":"9e7b8699a9feea7a","repo":"apify/crawlee","slug":"requestlist-is-not-initialized-you-must-call-awa","errorCode":null,"errorMessage":"RequestList is not initialized; you must call \"await requestList.initialize()\" before using it!","messagePattern":"RequestList is not initialized; you must call \"await requestList\\.initialize\\(\\)\" before using it!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/storages/request_list.ts","lineNumber":797,"sourceCode":"            throw new Error(\"Request object's uniqueKey must be a non-empty string\");\n        }\n    }\n\n    /**\n     * Checks that a request is currently being processed and throws an error if not.\n     */\n    private ensureInProgress(uniqueKey: string): void {\n        if (!this.inProgress.has(uniqueKey)) {\n            throw new Error(`The request is not being processed (uniqueKey: ${uniqueKey})`);\n        }\n    }\n\n    /**\n     * Throws an error if request list wasn't initialized.\n     */\n    private ensureIsInitialized(): void {\n        if (!this.#isInitialized) {\n            throw new Error(\n                'RequestList is not initialized; you must call \"await requestList.initialize()\" before using it!',\n            );\n        }\n    }\n\n    /**\n     * Returns the total number of unique requests present in the `RequestList`.\n     */\n    async getTotalCount(): Promise<number> {\n        this.ensureIsInitialized();\n\n        return this.requests.length;\n    }\n\n    /**\n     * Returns the number of pending requests in the `RequestList`.\n     */\n    async getPendingCount(): Promise<number> {","sourceCodeStart":779,"sourceCodeEnd":815,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/core/src/storages/request_list.ts#L779-L815","documentation":"Most RequestList accessors (getState, fetchNextRequest, markRequestAsHandled, counts, checkReadiness) require initialize() to have completed, because initialization loads/persists requests and state. Any use before that finds the internal structures empty, so the library throws this explicit reminder.","triggerScenarios":"Calling fetchNextRequest(), getTotalCount(), getPendingCount(), getState(), markRequestAsHandled(), or checkReadiness() before awaiting initialize(); forgetting the await on initialize(); initialize() rejected but code continued.","commonSituations":"Constructing a RequestList in a helper and returning it before initialization; racing initialization in parallel async code; refactoring where the await was dropped; using a list inside a handler registered before startup completes.","solutions":["await requestList.initialize() once before any other usage (open()/static helpers usually do this for you)","Do not pass the list to consumers before initialization resolves","Handle initialize() rejections so failure does not silently lead to later calls","Prefer RequestList.open() which handles initialization internally"],"exampleFix":"// before\nconst requestList = new RequestList({ sources });\nconst request = await requestList.fetchNextRequest(); // throws\n// after\nconst requestList = new RequestList({ sources });\nawait requestList.initialize();\nconst request = await requestList.fetchNextRequest();","handlingStrategy":"validation","validationCode":"if (!requestList.checkReadiness?.().isReady /* or track your own flag */) {\n  throw new Error('Initialize the RequestList before use');\n}","typeGuard":"null","tryCatchPattern":"try {\n  const req = await requestList.fetchNextRequest();\n} catch (err) {\n  if (err.message.includes('not initialized')) {\n    await requestList.initialize();\n    const req = await requestList.fetchNextRequest();\n  } else throw err;\n}","preventionTips":["Always await initialize() (or use RequestList.open()) before any other call","Wrap construction+initialization in a single async factory function","Never share a RequestList instance before its initialization promise resolves"],"tags":["lifecycle","initialization","request-list"],"backgroundTag":"not-initialized","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}