diff --git a/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js b/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js index 6cd0241d..9fdd2d09 100644 --- a/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js @@ -107,24 +107,32 @@ AnalysisMapConfigAdapter.prototype.getMapConfig = function(user, requestMapConfi return sourceId2Query; }, {}); - var missingNodesErrors = []; + var analysesErrors = []; requestMapConfig.layers = requestMapConfig.layers.map(function(layer, layerIndex) { if (getLayerSourceId(layer)) { var layerSourceId = getLayerSourceId(layer); var layerNode = sourceId2Node[layerSourceId]; if (layerNode) { - var analysisSql = layerQuery(layerNode); - var sqlQueryWrap = layer.options.sql_wrap; - if (sqlQueryWrap) { - layer.options.sql_raw = analysisSql; - analysisSql = sqlQueryWrap.replace(/<%=\s*sql\s*%>/g, analysisSql); + try { + var analysisSql; + + // it might throw error: Range filter from camshaft, for instance. + analysisSql = layerQuery(layerNode); + + var sqlQueryWrap = layer.options.sql_wrap; + if (sqlQueryWrap) { + layer.options.sql_raw = analysisSql; + analysisSql = sqlQueryWrap.replace(/<%=\s*sql\s*%>/g, analysisSql); + } + layer.options.sql = analysisSql; + layer.options.columns = getDataviewsColumns(getLayerDataviews(layer, dataviews)); + layer.options.affected_tables = getAllAffectedTablesFromSourceNodes(layerNode); + } catch (error) { + analysesErrors.push(error); } - layer.options.sql = analysisSql; - layer.options.columns = getDataviewsColumns(getLayerDataviews(layer, dataviews)); - layer.options.affected_tables = getAllAffectedTablesFromSourceNodes(layerNode); } else { - missingNodesErrors.push( + analysesErrors.push( new Error('Missing analysis node.id="' + layerSourceId +'" for layer='+layerIndex) ); } @@ -133,8 +141,8 @@ AnalysisMapConfigAdapter.prototype.getMapConfig = function(user, requestMapConfi }); var missingDataviewsNodesErrors = getMissingDataviewsSourceIds(dataviews, sourceId2Node); - if (missingNodesErrors.length > 0 || missingDataviewsNodesErrors.length > 0) { - return callback(missingNodesErrors.concat(missingDataviewsNodesErrors)); + if (analysesErrors.length > 0 || missingDataviewsNodesErrors.length > 0) { + return callback(analysesErrors.concat(missingDataviewsNodesErrors)); } // Augment dataviews with sql from analyses