From 60b64a127d0e50664968273ddcd6ed26db867c3c Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Thu, 6 Jun 2024 19:28:44 +0200 Subject: [PATCH] Add more missing awaits Add missing awaits in all places I could find them, except for the two places where the tests fail with the awaits in place. Add FIXMEs for the two places where I couldn't add await so it is clear what is happening. --- lib/ModelMixins/ExportWebCoverageServiceMixin.ts | 2 +- lib/ModelMixins/TileErrorHandlerMixin.ts | 4 ++-- lib/ModelMixins/TimeFilterMixin.ts | 2 +- .../Catalog/Ows/WebProcessingServiceCatalogFunction.ts | 2 +- lib/Models/Catalog/addUserCatalogMember.ts | 2 +- lib/Models/Catalog/addUserFiles.ts | 2 +- lib/Models/GlobeOrMap.ts | 2 +- lib/Models/ItemSearchProviders/IndexedItemSearchProvider.ts | 1 + lib/Models/Terria.ts | 5 +++-- lib/Models/Workbench.ts | 2 +- lib/ReactViewModels/ViewState.ts | 2 +- lib/ReactViews/DragDropFile.tsx | 4 ++-- lib/ReactViews/ExplorerWindow/Tabs.jsx | 2 +- lib/ReactViews/Map/Panels/ToolsPanel/CountDatasets.tsx | 2 +- lib/ReactViews/Tools/DiffTool/DiffTool.tsx | 2 +- lib/ReactViews/Workbench/Controls/ViewingControls.tsx | 2 +- 16 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/ModelMixins/ExportWebCoverageServiceMixin.ts b/lib/ModelMixins/ExportWebCoverageServiceMixin.ts index 622d01fb9ab..4a1f75895b9 100644 --- a/lib/ModelMixins/ExportWebCoverageServiceMixin.ts +++ b/lib/ModelMixins/ExportWebCoverageServiceMixin.ts @@ -412,7 +412,7 @@ function ExportWebCoverageServiceMixin< ); }); - pendingWorkbenchItem.terria.workbench.add(pendingWorkbenchItem); + await pendingWorkbenchItem.terria.workbench.add(pendingWorkbenchItem); // Load WCS metadata (DescribeCoverage request) (await this.loadWcsMetadata()).throwIfError(); diff --git a/lib/ModelMixins/TileErrorHandlerMixin.ts b/lib/ModelMixins/TileErrorHandlerMixin.ts index d3bbffd3e17..66e3022968c 100644 --- a/lib/ModelMixins/TileErrorHandlerMixin.ts +++ b/lib/ModelMixins/TileErrorHandlerMixin.ts @@ -224,14 +224,14 @@ function TileErrorHandlerMixin>( // Browsers don't tell us much about a failed image load, so we do an // XHR to get more error information if needed. - const maybeXhr = + const maybeXhr: Promise | undefined = attemptNumber === 1 ? Promise.reject(tileProviderError.error) : fetchTileImage(tile, imageryProvider); if (this.handleTileError && maybeXhr) { // Give the catalog item a chance to handle this error. - this.handleTileError(maybeXhr as any, tile); + await this.handleTileError(maybeXhr as any, tile); } try { diff --git a/lib/ModelMixins/TimeFilterMixin.ts b/lib/ModelMixins/TimeFilterMixin.ts index 8794caf278e..ea22f3e570b 100644 --- a/lib/ModelMixins/TimeFilterMixin.ts +++ b/lib/ModelMixins/TimeFilterMixin.ts @@ -65,7 +65,7 @@ function TimeFilterMixin>(Base: T) { const coords = coordinatesFromTraits(this.timeFilterCoordinates); if (coords) { - this.setTimeFilterFromLocation(coords); + await this.setTimeFilterFromLocation(coords); } disposeListener(); }) diff --git a/lib/Models/Catalog/Ows/WebProcessingServiceCatalogFunction.ts b/lib/Models/Catalog/Ows/WebProcessingServiceCatalogFunction.ts index 2ac05f34368..fe71e2756be 100644 --- a/lib/Models/Catalog/Ows/WebProcessingServiceCatalogFunction.ts +++ b/lib/Models/Catalog/Ows/WebProcessingServiceCatalogFunction.ts @@ -348,7 +348,7 @@ export default class WebProcessingServiceCatalogFunction extends XmlRequestMixin return; } - const inputValue = await Promise.resolve(result.inputValue); + const inputValue = await result.inputValue; if (!isDefined(inputValue)) { return; } diff --git a/lib/Models/Catalog/addUserCatalogMember.ts b/lib/Models/Catalog/addUserCatalogMember.ts index edaef8fb030..7fa0cdc7ca8 100644 --- a/lib/Models/Catalog/addUserCatalogMember.ts +++ b/lib/Models/Catalog/addUserCatalogMember.ts @@ -23,7 +23,7 @@ export default async function addUserCatalogMember( newCatalogMemberOrPromise: BaseModel | Promise, options: AddUserCatalogMemberOptions = {} ): Promise { - const promise = + const promise: Promise = newCatalogMemberOrPromise instanceof Promise ? newCatalogMemberOrPromise : Promise.resolve(newCatalogMemberOrPromise); diff --git a/lib/Models/Catalog/addUserFiles.ts b/lib/Models/Catalog/addUserFiles.ts index 719c6430e23..7411007ff81 100644 --- a/lib/Models/Catalog/addUserFiles.ts +++ b/lib/Models/Catalog/addUserFiles.ts @@ -89,7 +89,7 @@ export default async function addUserFiles( } tempCatalogItem.loadPromise = loadPromise; - terria.workbench.add(tempCatalogItem); + await terria.workbench.add(tempCatalogItem); tempCatalogItemList.push(tempCatalogItem); } diff --git a/lib/Models/GlobeOrMap.ts b/lib/Models/GlobeOrMap.ts index a50b43e2874..d1b98ec75c8 100644 --- a/lib/Models/GlobeOrMap.ts +++ b/lib/Models/GlobeOrMap.ts @@ -411,7 +411,7 @@ export default abstract class GlobeOrMap { }) ); - this.terria.overlays.add(catalogItem); + await this.terria.overlays.add(catalogItem); this._highlightPromise = catalogItem.loadMapItems(); const removeCallback = (this._removeHighlightCallback = () => { diff --git a/lib/Models/ItemSearchProviders/IndexedItemSearchProvider.ts b/lib/Models/ItemSearchProviders/IndexedItemSearchProvider.ts index f2840cfa569..e37b1a9c820 100644 --- a/lib/Models/ItemSearchProviders/IndexedItemSearchProvider.ts +++ b/lib/Models/ItemSearchProviders/IndexedItemSearchProvider.ts @@ -105,6 +105,7 @@ export default class IndexedItemSearchProvider extends ItemSearchProvider { const json = await loadJson5(indexRootUrl); try { this.indexRoot = parseIndexRoot(json); + // FIXME: missing await. this.getOrLoadResultsData(); } catch (parseError) { console.warn(parseError); diff --git a/lib/Models/Terria.ts b/lib/Models/Terria.ts index ea1e1b2fdb5..6f1629d832b 100644 --- a/lib/Models/Terria.ts +++ b/lib/Models/Terria.ts @@ -1422,6 +1422,7 @@ export default class Terria { // Zoom to workbench items if any of the init sources specifically requested it if (this.focusWorkbenchItemsAfterLoadingInitSources) { + // FIXME: missing await. this.doZoomToWorkbenchItems(); } @@ -1731,7 +1732,7 @@ export default class Terria { // - If there are multiple initSources, the setting from the last source takes effect try { const initialCamera = CameraView.fromJson(initData.initialCamera); - this.currentViewer.zoomTo(initialCamera, 2.0); + await this.currentViewer.zoomTo(initialCamera, 2.0); // reset in case this was enabled by a previous initSource this.focusWorkbenchItemsAfterLoadingInitSources = false; } catch (error) { @@ -1768,7 +1769,7 @@ export default class Terria { ); } if (isJsonString(initData.settings.baseMapId)) { - this.mainViewer.setBaseMap( + await this.mainViewer.setBaseMap( this.baseMapsModel.baseMapItems.find( (item) => item.item.uniqueId === initData.settings!.baseMapId )?.item diff --git a/lib/Models/Workbench.ts b/lib/Models/Workbench.ts index cce7dbc2686..890ffa9985c 100644 --- a/lib/Models/Workbench.ts +++ b/lib/Models/Workbench.ts @@ -219,7 +219,7 @@ export default class Workbench { if (!error && MappableMixin.isMixedInto(item)) { error = (await item.loadMapItems()).error; if (!error && item.zoomOnAddToWorkbench && !item.disableZoomTo) { - item.terria.currentViewer.zoomTo(item); + await item.terria.currentViewer.zoomTo(item); } } diff --git a/lib/ReactViewModels/ViewState.ts b/lib/ReactViewModels/ViewState.ts index 77a1975d62c..a5daccbc25a 100644 --- a/lib/ReactViewModels/ViewState.ts +++ b/lib/ReactViewModels/ViewState.ts @@ -502,7 +502,7 @@ export default class ViewState { ); result.throwIfError(); const model = result.throwIfUndefined(); - this.viewCatalogMember(model); + await this.viewCatalogMember(model); } catch (e) { terria.raiseErrorToUser(e, { message: `Couldn't find model \`${previewedItemId}\` for preview` diff --git a/lib/ReactViews/DragDropFile.tsx b/lib/ReactViews/DragDropFile.tsx index 2dec3623ea3..bc91724f161 100644 --- a/lib/ReactViews/DragDropFile.tsx +++ b/lib/ReactViews/DragDropFile.tsx @@ -96,9 +96,9 @@ class DragDropFile extends React.Component { ); isDefined(firstZoomableItem) && - runInAction(() => + (await runInAction(() => props.viewState.terria.currentViewer.zoomTo(firstZoomableItem, 1) - ); + )); } runInAction(() => (props.viewState.isDraggingDroppingFile = false)); diff --git a/lib/ReactViews/ExplorerWindow/Tabs.jsx b/lib/ReactViews/ExplorerWindow/Tabs.jsx index 021414241ca..0d49178dce4 100644 --- a/lib/ReactViews/ExplorerWindow/Tabs.jsx +++ b/lib/ReactViews/ExplorerWindow/Tabs.jsx @@ -28,7 +28,7 @@ class Tabs extends React.Component { result.raiseError(this.props.terria); } else { if (!file.disableZoomTo) { - this.props.terria.currentViewer.zoomTo(file, 1); + await this.props.terria.currentViewer.zoomTo(file, 1); } } } diff --git a/lib/ReactViews/Map/Panels/ToolsPanel/CountDatasets.tsx b/lib/ReactViews/Map/Panels/ToolsPanel/CountDatasets.tsx index e2e8e8d3e98..afc0def13b4 100644 --- a/lib/ReactViews/Map/Panels/ToolsPanel/CountDatasets.tsx +++ b/lib/ReactViews/Map/Panels/ToolsPanel/CountDatasets.tsx @@ -81,7 +81,7 @@ const CountDatasets: React.FC = observer((props) => { path.push(member.name!); const loadPromise = member.loadMembers(); - const countPromise = member.isLoading + const countPromise: Promise = member.isLoading ? loadPromise .then((result) => result.throwIfError()) .then( diff --git a/lib/ReactViews/Tools/DiffTool/DiffTool.tsx b/lib/ReactViews/Tools/DiffTool/DiffTool.tsx index 4422e018fac..217044cef8c 100644 --- a/lib/ReactViews/Tools/DiffTool/DiffTool.tsx +++ b/lib/ReactViews/Tools/DiffTool/DiffTool.tsx @@ -443,7 +443,7 @@ class Main extends React.Component { const imageryProvider = part && ImageryParts.is(part) && part.imageryProvider; if (imageryProvider) { - const promises = [ + const promises: Promise[] = [ setTimeFilterFromLocation( this.props.leftItem, markerLocation, diff --git a/lib/ReactViews/Workbench/Controls/ViewingControls.tsx b/lib/ReactViews/Workbench/Controls/ViewingControls.tsx index 2fba40ff7d3..b13c83c0d2a 100644 --- a/lib/ReactViews/Workbench/Controls/ViewingControls.tsx +++ b/lib/ReactViews/Workbench/Controls/ViewingControls.tsx @@ -262,7 +262,7 @@ class ViewingControls extends React.Component< }); // Add it to terria.catalog, which is required so the new item can be shared. - addUserCatalogMember(terria, splitRef, { + await addUserCatalogMember(terria, splitRef, { open: false }); });