尽管我使用尝试捕获

发布于 2025-02-13 17:02:50 字数 4974 浏览 0 评论 0原文

我面临一个非常奇怪的问题。一旦我将节点从14开始更新为节点16,我的测试就停止了工作,我会收到这样的抱怨:

Error: 
    at /src/api/v1/datastore/SearchesDatastore.ts:109:25
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

我的代码显示的行是:

  public async isRemovalNeeded() {

    try {
      this._logger.debug({message: `Checking if any design doc removal needed.`});
      const designDocsName = getDesignDocLists(this.designDocsPath);
      const allDesignDocs = await this._db.list({
        include_docs: true,
        startkey: "_design/",
        endkey: "_design0"
      });

      const toBeRemoved = allDesignDocs.rows.
        filter((row: any) => !designDocsName.includes(row.id.replace("_design/", "")));
      return toBeRemoved.length > 0;
    } catch (e) {
      this._logger.warn({ message: "Failed to retrieve list of documents." });
      this._logger.debug({ message: `Error: ${e}` });
      throw new Error(errors.ERROR_GETTING_DB_LIST.message);
    }
  }

要进行测试,我用节点14运行了相同的内容,并且通过此警告传递。

(node:22352) UnhandledPromiseRejectionWarning: Error: 
    at src/api/v1/datastore/SearchesDatastore.ts:128:19
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:22352) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 43)
(node:22352) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

因此,我认为这是因为Node16是严格的,这是针对未经手的承诺,但是在我的代码中,我看不到任何未兑现的承诺,所以我感到困惑的

任何帮助也

对此表示赞赏,这就是我所说的:

 try {
                    this._loggingService.debug({message: `Checking to see if current pod is a leader`});
                    const isLeader: any = await this._consensusService.isLeader();
                    
                    this._loggingService.debug({message: `current Pod checked for leading and isLeader is: ${isLeader}`});   
                    const isRemovalNeeded = await this._searchesDatastore.isRemovalNeeded();
                    this._loggingService.debug({message: `check occurred to make sure if design doc removal needed and isRemovalNeeded is: ${isRemovalNeeded}`}); 
                    const isUpdateNeeded = await this._searchesDatastore.isUpdateNeeded();
                    this._loggingService.debug({message: `check occurred to make sure if design doc update needed and isUpdateNeeded is: ${isUpdateNeeded}`}); 
                    if (!isRemovalNeeded && !isUpdateNeeded) {
                        shouldWait = false;
                        this._loggingService.info({ message: "All documents are up to date" });
                    } else if (isLeader) {
                        isRemovalNeeded && await this._searchesDatastore.cleanRemovedDesignDocs();
                        isUpdateNeeded && await this._searchesDatastore.syncAllDesignDocs();
                        shouldWait = false;
                    } else {
                        this._loggingService.info({ message: "Design docs are not synced but this pod is not a leader. We need to wait for leader pod to take do the house keeping first." });
                    }
                    if (!shouldWait) {
                        this._loggingService.debug({message: `datastorewatcher is done and we are proceeding to the next step...`});
                        this.watcherFailureCount= 1;
                        resolve(true);
                        break;
                    } else {
                        this._loggingService.debug({message: `datastorewatcher is not done. We will try again after ${config.databaseWatcher.interval}.`})
                        await this.sleep(config.databaseWatcher.interval);
                    }
                } catch (e) {
                    this.watcherFailureCount++;
                    if(this.watcherFailureCount> config.databaseWatcher.toleranceLevel){
                        this._loggingService.warn({message: "App crashed and pod will die soon"})
                        reject(e);
                        break;
                    }
                    const nextIntervalToRun: number= config.databaseWatcher.interval * this.watcherFailureCount;
                    this._loggingService.warn({ message: `DataStoreWatcher failed but still failure is less than tolerance threshold: ${config.databaseWatcher.toleranceLevel}. Watcher will run again in ${nextIntervalToRun}. ${e}` });
                    await this.sleep(nextIntervalToRun);
                }

I am facing a very strange issue. As soon as I updated my node to node 16 from 14 my tests stopped working and I get a complain like this:

Error: 
    at /src/api/v1/datastore/SearchesDatastore.ts:109:25
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

And my code the line it shows is:

  public async isRemovalNeeded() {

    try {
      this._logger.debug({message: `Checking if any design doc removal needed.`});
      const designDocsName = getDesignDocLists(this.designDocsPath);
      const allDesignDocs = await this._db.list({
        include_docs: true,
        startkey: "_design/",
        endkey: "_design0"
      });

      const toBeRemoved = allDesignDocs.rows.
        filter((row: any) => !designDocsName.includes(row.id.replace("_design/", "")));
      return toBeRemoved.length > 0;
    } catch (e) {
      this._logger.warn({ message: "Failed to retrieve list of documents." });
      this._logger.debug({ message: `Error: ${e}` });
      throw new Error(errors.ERROR_GETTING_DB_LIST.message);
    }
  }

just to test I ran the same thing with node 14 and it passed with this warning

(node:22352) UnhandledPromiseRejectionWarning: Error: 
    at src/api/v1/datastore/SearchesDatastore.ts:128:19
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:22352) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 43)
(node:22352) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

so I am thinking it is because of node16 being strict for unhandled promises but in my code I Cannot see any unhandled promise so I am confused

any help is appreciated

Also this is how I call it :

 try {
                    this._loggingService.debug({message: `Checking to see if current pod is a leader`});
                    const isLeader: any = await this._consensusService.isLeader();
                    
                    this._loggingService.debug({message: `current Pod checked for leading and isLeader is: ${isLeader}`});   
                    const isRemovalNeeded = await this._searchesDatastore.isRemovalNeeded();
                    this._loggingService.debug({message: `check occurred to make sure if design doc removal needed and isRemovalNeeded is: ${isRemovalNeeded}`}); 
                    const isUpdateNeeded = await this._searchesDatastore.isUpdateNeeded();
                    this._loggingService.debug({message: `check occurred to make sure if design doc update needed and isUpdateNeeded is: ${isUpdateNeeded}`}); 
                    if (!isRemovalNeeded && !isUpdateNeeded) {
                        shouldWait = false;
                        this._loggingService.info({ message: "All documents are up to date" });
                    } else if (isLeader) {
                        isRemovalNeeded && await this._searchesDatastore.cleanRemovedDesignDocs();
                        isUpdateNeeded && await this._searchesDatastore.syncAllDesignDocs();
                        shouldWait = false;
                    } else {
                        this._loggingService.info({ message: "Design docs are not synced but this pod is not a leader. We need to wait for leader pod to take do the house keeping first." });
                    }
                    if (!shouldWait) {
                        this._loggingService.debug({message: `datastorewatcher is done and we are proceeding to the next step...`});
                        this.watcherFailureCount= 1;
                        resolve(true);
                        break;
                    } else {
                        this._loggingService.debug({message: `datastorewatcher is not done. We will try again after ${config.databaseWatcher.interval}.`})
                        await this.sleep(config.databaseWatcher.interval);
                    }
                } catch (e) {
                    this.watcherFailureCount++;
                    if(this.watcherFailureCount> config.databaseWatcher.toleranceLevel){
                        this._loggingService.warn({message: "App crashed and pod will die soon"})
                        reject(e);
                        break;
                    }
                    const nextIntervalToRun: number= config.databaseWatcher.interval * this.watcherFailureCount;
                    this._loggingService.warn({ message: `DataStoreWatcher failed but still failure is less than tolerance threshold: ${config.databaseWatcher.toleranceLevel}. Watcher will run again in ${nextIntervalToRun}. ${e}` });
                    await this.sleep(nextIntervalToRun);
                }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文