qgis-js/utils - loadLocalProject does not handle promise rejections
amuedespacher opened this issue · comments
Alex Müdespacher commented
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:
- Instead, loadLocalProject could be defined as an async function, like (not tested):
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.
Michael Schmuki commented
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
)
Alex Müdespacher commented
Thanks for the fix; this solves the issue.