qgis / qgis-js

QGIS core ported to WebAssembly to run it on the web platform

Home Page:https://qgis.github.io/qgis-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

qgis-js/utils - loadLocalProject does not handle promise rejections

amuedespacher opened this issue · comments

Steps to reproduce:

  • Use the loadLocalProject function of @qgis-js/utils
  • When the system dialog to select a folder pops up, cancel it

Actual result:

  • Error "Uncaught (in promise) DOMException: The user aborted a request." appears
  • Rejected promise is not handled

Expected result:

  • Promise rejection is handled

Hints:

const loadLocalProject = async (): Promise<LocalProject> => {
  try {
    const entries: LocalEntries = await openLocalDirectory({
      recursive: true,
      mode: "read",
    }) as LocalEntries;
    const localProject = new LocalProject(fs, entries);
    return localProject;
  } catch (error) {
    console.error(error);
    throw error;
  }
};
  • This would allow to better handle e.g. user abortions in the UI.

Will have a look at this and fix it for the next release.

Probably we should add a a try-catch and reject the Promise of loadLocalProject in the catch clause. So it's up to the user of loadLocalProject if/how to handle this (e.g. do another call of loadLocalProject)

Thanks for the fix; this solves the issue.