Skip to content

Commit

Permalink
Removes asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jun 25, 2019
1 parent 1d82d56 commit fd83617
Show file tree
Hide file tree
Showing 30 changed files with 277 additions and 109 deletions.
8 changes: 6 additions & 2 deletions contribs/gmf/examples/objecteditinghub.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ function MainController($http, $q, $scope, gmfThemes, gmfXSDAttributes) {
const groupNode = theme.children[0];

// (4) Set OGC server, which must support WFS for this example to work
console.assert(groupNode.ogcServer);
if (!groupNode.ogcServer) {
throw new Error('Missing groupNode.ogcServer');
}
if (!this.gmfServers_) {
throw new Error('Missing gmfServers');
}
Expand Down Expand Up @@ -234,7 +236,9 @@ MainController.prototype.runEditor = function() {
const feature = this.selectedFeature;
const layer = this.selectedGmfLayerNode.id;
const property = this.selectedGmfLayerNode.metadata.identifierAttributeField;
console.assert(property !== undefined);
if (!property) {
throw new Error('Missing property');
}
const id = feature.get(property);

/** @type {Object<string, *>} */
Expand Down
4 changes: 3 additions & 1 deletion contribs/gmf/src/contextualdata/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ ContextualdataController.prototype.init = function() {
}

const mapDiv = this.map.getTargetElement();
console.assert(mapDiv);
if (!mapDiv) {
throw new Error('Missing mapDiv');
}
mapDiv.addEventListener('contextmenu', this.handleMapContextMenu_.bind(this));

this.map.on('pointerdown', this.hidePopover.bind(this));
Expand Down
13 changes: 9 additions & 4 deletions contribs/gmf/src/controllers/AbstractAppController.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ export function AbstractAppController(config, map, $scope, $injector) {
* @type {import("ol/Map.js").default}
*/
this.map = map;

console.assert(this.map instanceof olMap);
if (!(this.map instanceof olMap)) {
throw new Error('Wrong map type');
}

/**
* Collection of features for the draw interaction
Expand Down Expand Up @@ -699,7 +700,9 @@ function getLayerByLabels(layers, labels) {
* @param {string} lang Language code.
*/
AbstractAppController.prototype.switchLanguage = function(lang) {
console.assert(lang in this.langUrls);
if (!(lang in this.langUrls)) {
throw new Error('Missing lang URL');
}
this.gettextCatalog.setCurrentLanguage(lang);
this.gettextCatalog.loadRemote(this.langUrls[lang]);
this.tmhDynamicLocale.set(lang);
Expand Down Expand Up @@ -762,7 +765,9 @@ AbstractAppController.prototype.setDefaultBackground_ = function(theme) {
layer = layers[layers.length > 1 ? 1 : 0];
}

console.assert(layer);
if (!layer) {
throw new Error('Missing layer');
}
this.backgroundLayerMgr_.set(this.map, layer);
});
};
Expand Down
19 changes: 12 additions & 7 deletions contribs/gmf/src/datasource/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ export class DatasourceManager {
// Create a DataSources for each theme
for (const theme of themes) {
for (const child of theme.children) {
console.assert(child);
this.createDataSource_(child, child, ogcServers);
}
}
Expand Down Expand Up @@ -449,7 +448,6 @@ export class DatasourceManager {
// group node itself is **skipped**.
if (children) {
for (const child of children) {
console.assert(child);
this.createDataSource_(firstLevelGroup, child, ogcServers);
}
return;
Expand Down Expand Up @@ -545,7 +543,6 @@ export class DatasourceManager {
// OGC Server
const ogcServerName = (!firstLevelGroup || firstLevelGroup.mixed) ?
gmfLayerWMS.ogcServer : firstLevelGroup.ogcServer;
console.assert(ogcServerName);
ogcServer = ogcServers[ogcServerName];
ogcImageType = ogcServer.imageType;

Expand Down Expand Up @@ -690,7 +687,9 @@ export class DatasourceManager {

const id = olUtilGetUid(treeCtrl.node);
const dataSource = this.dataSourcesCache_[id];
console.assert(dataSource, 'DataSource should be set');
if (!dataSource) {
throw new Error('Missing dataSource');
}
treeCtrl.setDataSource(dataSource);

const stateWatcherUnregister = this.rootScope_.$watch(
Expand Down Expand Up @@ -872,7 +871,9 @@ export class DatasourceManager {
const params = source.getParams();
const layersParam = params.LAYERS;
const layersList = layersParam.split(',');
console.assert(layersList.length >= 1);
if (!layersList.length) {
throw new Error('Missing layersList');
}

const filterParam = 'FILTER';
const filterParamValues = [];
Expand All @@ -896,7 +897,9 @@ export class DatasourceManager {

const id = olUtilGetUid(dataSource.gmfLayer);
const item = this.treeCtrlCache_[id];
console.assert(item);
if (!item) {
throw new Error('Missing item');
}
const treeCtrl = item.treeCtrl;
const projCode = treeCtrl.map.getView().getProjection().getCode();

Expand Down Expand Up @@ -970,7 +973,9 @@ export class DatasourceManager {

const id = olUtilGetUid(dataSource.gmfLayer);
const item = this.treeCtrlCache_[id];
console.assert(item);
if (!item) {
throw new Error('Missing item');
}
const wmsLayer = item.wmsLayer;
const wmsSource = wmsLayer.getSource();

Expand Down
9 changes: 7 additions & 2 deletions contribs/gmf/src/disclaimer/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ DisclaimerController.prototype.handleLayersAdd_ = function(evt) {
if (evt instanceof CollectionEvent) {
this.timeout_(() => {
const layer = evt.element;
console.assert(layer instanceof olLayerBase);
if (!(layer instanceof olLayerBase)) {
throw new Error('Wrong layer type');
}
this.registerLayer_(layer);
});
}
Expand All @@ -182,7 +184,10 @@ DisclaimerController.prototype.handleLayersAdd_ = function(evt) {
DisclaimerController.prototype.handleLayersRemove_ = function(evt) {
if (evt instanceof CollectionEvent) {
const layer = evt.element;
console.assert(layer instanceof olLayerBase);
if (!(layer instanceof olLayerBase)) {
throw new Error('Wrong layer type');
}

this.unregisterLayer_(layer);
}
};
Expand Down
9 changes: 6 additions & 3 deletions contribs/gmf/src/drawing/drawFeatureComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,9 @@ Controller.prototype.handleMapSelectActiveChange_ = function(active) {
}

const mapDiv = this.map.getViewport();
console.assert(mapDiv);
if (!mapDiv) {
throw new Error('Missing mapDiv');
}

if (active) {
olEvents.listen(this.map, 'click', this.handleMapClick_, this);
Expand Down Expand Up @@ -734,8 +736,9 @@ Controller.prototype.handleMenuActionClick_ = function(vertexInfo, evt) {

switch (action) {
case 'delete':
console.assert(
this.selectedFeature, 'Selected feature should be truthy');
if (!this.selectedFeature) {
throw new Error('Missing selectedFeature');
}
if (vertexInfo) {
this.featureHelper_.removeVertex(this.selectedFeature, vertexInfo);
} else {
Expand Down
10 changes: 6 additions & 4 deletions contribs/gmf/src/editing/Snapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ EditingSnappingService.prototype.getWFSConfig_ = function(treeCtrl) {
// At this point, every requirements have been met.
// Create and return the configuration.
const urlWfs = ogcServer.urlWfs;
console.assert(urlWfs, 'urlWfs should be defined.');
if (!urlWfs) {
throw new Error('Missing urlWfs');
}

return {
featureTypes: featureTypes.join(','),
Expand Down Expand Up @@ -413,7 +415,6 @@ EditingSnappingService.prototype.activateItem_ = function(item) {
}

const map = this.map_;
console.assert(map);

const interaction = new olInteractionSnap({
edge: item.snappingConfig.edge,
Expand Down Expand Up @@ -512,11 +513,12 @@ EditingSnappingService.prototype.loadItemFeatures_ = function(item) {
}

const map = this.map_;
console.assert(map);

const view = map.getView();
const size = map.getSize();
console.assert(size);
if (!size) {
throw new Error('Missing size');
}

const extent = view.calculateExtent(size);
const projCode = view.getProjection().getCode();
Expand Down
12 changes: 9 additions & 3 deletions contribs/gmf/src/editing/editFeatureComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,9 @@ Controller.prototype.handleFeatureAdd_ = function(evt) {
throw new Error('Missing attributes');
}
const feature = evt.element;
console.assert(feature instanceof olFeature);
if (!(feature instanceof olFeature)) {
throw new Error('Wrong feature type');
}
const dateFormatter = new DateFormatter();
for (const attribute of this.attributes) {
if (attribute.format) {
Expand All @@ -963,7 +965,9 @@ Controller.prototype.handleFeatureAdd_ = function(evt) {
jsonFormat = 'H:i:s';
}
const name = feature.get(attribute.name);
console.assert(typeof name == 'string');
if (typeof name != 'string') {
throw new Error('Wrong name type');
}
value = dateFormatter.parseDate(name, jsonFormat);
}
feature.set(attribute.name, dateFormatter.formatDate(value, attribute.format));
Expand Down Expand Up @@ -1073,7 +1077,9 @@ Controller.prototype.handleMapSelectActiveChange_ = function(active) {
}

const mapDiv = this.map.getViewport();
console.assert(mapDiv);
if (!mapDiv) {
throw new Error('Missing mapDiv');
}

if (active) {
olEvents.listen(this.map, 'click', this.handleMapClick_, this);
Expand Down
1 change: 0 additions & 1 deletion contribs/gmf/src/editing/editFeatureSelectorComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ function Controller($scope, $timeout, gmfThemes, gmfTreeManager) {
this.gmfTreeManager_.rootCtrl.traverseDepthFirst((treeCtrl) => {
const gmfLayer = /** @type {import('gmf/themes.js').GmfLayer} */(treeCtrl.node);
if (gmfLayer.editable) {
console.assert(treeCtrl.children.length === 0);
editables.push(treeCtrl);
}
});
Expand Down
4 changes: 3 additions & 1 deletion contribs/gmf/src/filters/SavedFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ export class SavedFilter {
loadItemsFromLocalStorage_() {
if (window.localStorage[this.localStorageKey_]) {
const items = JSON.parse(window.localStorage[this.localStorageKey_]);
console.assert(Array.isArray(items));
if (!Array.isArray(items)) {
throw new Error('Wrong items type');
}
this.items_ = items;
}
}
Expand Down
8 changes: 6 additions & 2 deletions contribs/gmf/src/import/importdatasourceComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,13 @@ class Controller {
* @return {string[]} List of datum tokenizers.
*/
datumTokenizer: (datum) => {
console.assert(typeof datum == 'string');
if (typeof datum != 'string') {
throw new Error('Wrong datum type');
}
const originalDatumTokenizers = Bloodhound.tokenizers.whitespace(datum);
console.assert(originalDatumTokenizers);
if (!originalDatumTokenizers) {
throw new Error('Missing originalDatumTokenizers');
}
const datumTokenizers = [];
for (const originalDatumTokenizer of originalDatumTokenizers) {
let i = 0;
Expand Down
60 changes: 45 additions & 15 deletions contribs/gmf/src/layertree/SyncLayertreeMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ SyncLayertreeMap.prototype.updateLayerState_ = function(layer, treeCtrl) {
layer.setVisible(active);
} else if (!gmfGroup.mixed && treeCtrl.depth === 1) {
// First level non mixed group
console.assert(layer instanceof olLayerImage);
if (!(layer instanceof olLayerImage)) {
throw new Error('Wrong dataSource type');
}
/** @type {string[]} */
const names = [];
/** @type {string[]} */
Expand All @@ -156,7 +158,9 @@ SyncLayertreeMap.prototype.updateLayerState_ = function(layer, treeCtrl) {
}
} else {
// WMS mixed layer
console.assert(layer instanceof olLayerImage);
if (!(layer instanceof olLayerImage)) {
throw new Error('Wrong dataSource type');
}
layer.setVisible(active);
}
};
Expand Down Expand Up @@ -233,10 +237,18 @@ SyncLayertreeMap.prototype.createLayerFromGroup_ = function(treeCtrl, mixed) {
}
const timeParam = this.getTimeParam_(treeCtrl);
const ogcServer = this.ogcServersObject_[groupNode.ogcServer || ''];
console.assert(ogcServer);
console.assert(ogcServer.url);
console.assert(ogcServer.type);
console.assert(ogcServer.imageType);
if (!ogcServer) {
throw new Error('Missing ogcServer');
}
if (!ogcServer.url) {
throw new Error('Missing ogcServer.url');
}
if (!ogcServer.type) {
throw new Error('Missing ogcServer.type');
}
if (!ogcServer.imageType) {
throw new Error('Missing ogcServer.imageType');
}
layer = this.layerHelper_.createBasicWMSLayer(
ogcServer.url,
'',
Expand Down Expand Up @@ -284,11 +296,21 @@ SyncLayertreeMap.prototype.createLeafInAMixedGroup_ = function(treeCtrl, map) {
const gmfLayerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */(gmfLayer);
const timeParam = this.getTimeParam_(treeCtrl);
const ogcServer = this.ogcServersObject_[gmfLayerWMS.ogcServer];
console.assert(ogcServer);
console.assert(ogcServer.url);
console.assert(ogcServer.type);
console.assert(gmfLayerWMS.layers);
console.assert(ogcServer.imageType);
if (!ogcServer) {
throw new Error('Missing ogcServer');
}
if (!ogcServer.url) {
throw new Error('Missing ogcServer.url');
}
if (!ogcServer.type) {
throw new Error('Missing ogcServer.type');
}
if (!ogcServer.imageType) {
throw new Error('Missing ogcServer.imageType');
}
if (!gmfLayerWMS.layers) {
throw new Error('Missing gmfLayerWMS.layers');
}

const opt_params = {STYLES: gmfLayerWMS.style};

Expand Down Expand Up @@ -329,12 +351,16 @@ SyncLayertreeMap.prototype.createLeafInAMixedGroup_ = function(treeCtrl, map) {
SyncLayertreeMap.prototype.initGmfLayerInANotMixedGroup_ = function(treeCtrl, map) {
const leafNode = /** @type {import('gmf/themes.js').GmfLayer} */(treeCtrl.node);
const firstLevelGroup = this.getFirstLevelGroupCtrl_(treeCtrl);
console.assert(firstLevelGroup);
if (!firstLevelGroup) {
throw new Error('Missing firstLevelGroup');
}
const layer = firstLevelGroup.layer;
if (!(layer instanceof olLayerImage)) {
throw new Error('Wrong layer type');
}
console.assert(layer instanceof olLayerImage);
if (!(layer instanceof olLayerImage)) {
throw new Error('Wrong dataSource type');
}
// Update layer information and tree state.
this.updateLayerReferences_(leafNode, layer);
if (leafNode.metadata.isChecked) {
Expand All @@ -355,8 +381,12 @@ SyncLayertreeMap.prototype.initGmfLayerInANotMixedGroup_ = function(treeCtrl, ma
*/
SyncLayertreeMap.prototype.createWMTSLayer_ = function(gmfLayerWMTS) {
const newLayer = new olLayerTile();
console.assert(gmfLayerWMTS.url);
console.assert(gmfLayerWMTS.layer);
if (!gmfLayerWMTS.url) {
throw new Error('Missing gmfLayerWMTS.url');
}
if (!gmfLayerWMTS.layer) {
throw new Error('Missing gmfLayerWMTS.layer');
}
this.layerHelper_.createWMTSLayerFromCapabilitites(gmfLayerWMTS.url,
gmfLayerWMTS.layer, gmfLayerWMTS.matrixSet, gmfLayerWMTS.dimensions).then((layer) => {
newLayer.setSource(layer.getSource());
Expand Down

0 comments on commit fd83617

Please sign in to comment.