systemapic / pile

PostGIS tile server
0 stars 2 forks source link

TypeError: Cannot call method 'replace' of undefined #18

Closed strk closed 8 years ago

strk commented 8 years ago

An extract from pile logs (trying to serve raster/postgis tiles):

pile_1        | storedLayer:  { layerUuid: 'layer_id-a3d9f852-356a-45e6-a902-7a549fe9ca3a',
pile_1        |   options:
pile_1        |    { sql: '(SELECT * FROM file_jbjmhofguliemzpxifxi) as sub',
pile_1        |      file_id: 'file_jbjmhofguliemzpxifxi',
pile_1        |      database_name: 'bwjagbrzip',
pile_1        |      table_name: 'file_jbjmhofguliemzpxifxi',
pile_1        |      layer_id: 'layer_id-a3d9f852-356a-45e6-a902-7a549fe9ca3a',
pile_1        |      wicked: 'thing',
pile_1        |      data_type: 'raster',
pile_1        |      cartocss_version: '2.0.1',
pile_1        |      geom_column: 'rast',
pile_1        |      geom_type: 'raster',
pile_1        |      raster_band: 0,
pile_1        |      srid: 3857,
pile_1        |      extent: '-58556 6423255,341944 7123755' } }
pile_1        | { err_id: 9,
pile_1        |   err_msg: 'Error rendering raster tile',
pile_1        |   error: { message: [TypeError: Cannot call method 'replace' of undefined] } }
pile_1        | { err_id: 9,
pile_1        |   err_msg: 'Error rendering raster tile',
pile_1        |   error: { message: [TypeError: Cannot call method 'replace' of undefined] } }
pile_1        | { err_id: 9,
pile_1        |   err_msg: 'Error rendering raster tile',
pile_1        |   error: { message: [TypeError: Cannot call method 'replace' of undefined] } }
pile_1        | { err_id: 9,
pile_1        |   err_msg: 'Error rendering raster tile',
pile_1        |   error: { message: [TypeError: Cannot call method 'replace' of undefined] } }

It isn't easy to find the offending replace call. Could that message include a stack trace, for development runs ?

strk commented 8 years ago

I found the actual replace. And I also found that err.stack is undefined (would be good to always print errors via 'new Error')

strk commented 8 years ago

I'm reopening this as I'm still getting it, and I finally think it's happening within "carto" node.js module itself, when trying to render this:

{"srs":"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over","Stylesheet":[{"id":"tile_style"}],"Layer":[{"clear_label_cache":false,"queryable":false,"maximum_scale_denominator":1.7976931348623157e+308,"minimum_scale_denominator":0,"datasource":{"type":"vector"},"styles":["layer"],"srs":"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over","active":true,"name":"layer"}]}

npm ls | grep carto reveals there are two different version being used, one of which seems to be a cartodb version (expected?):

/docker-systemapic/modules/pile(postgis_raster)$ npm ls | grep carto
├─┬ carto@0.14.1
│ ├─┬ carto@0.9.5-cdb2
strk commented 8 years ago

Got it, the inner carto is a dependency of grainstore@1.1.1 -- I didn't know we were using grainstore here, I'm surprised anyone would want to use that :)

strk commented 8 years ago

note to self: I left cartodb while grainstore was at version 0.22.1

strk commented 8 years ago

I think the CSS is missing a full datasource. Expanded:

{
    "srs":"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
    "Stylesheet": [
      {"id":"tile_style"}
    ],
    "Layer": [{
      "clear_label_cache": false,
      "queryable": false,
      "maximum_scale_denominator": 1.7976931348623157e+308,
      "minimum_scale_denominator":0,
      "datasource": {
        "type":"vector"
      },
      "styles": ["layer"],
      "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
      "active": true,
      "name": "layer"
    }]
}
strk commented 8 years ago

Filed upstream (as I think carto should not throw in any case): https://github.com/mapbox/carto/issues/430

strk commented 8 years ago

For comparison, this is the CSS rendered for a vector layer:

{                                                                               
  "srs":"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@n ull +wktext +no_defs +over",
  "Stylesheet":[                                                                
    {"id":"tile_style",                                                         
     "data":"@polygon_opacity: 1;\n#layer {\n\n\tpolygon-opacity: @polygon_opacity;\n\n\tpo lygon-fill: red;\n\n}"}
  ],                                                                            
  "Layer":[{                                                                    
    "clear_label_cache":false,                                                   
    "queryable":false,                                                          
    "maximum_scale_denominator":1.7976931348623157e+308,                        
    "minimum_scale_d enominator":0,                                             
    "datasource":{                                                              
      "type":"vector"                                                           
    },                                                                          
    "styles":["layer"],                                                         
    "srs":"+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1 .0 +units=m +nadgrids=@null +wktext +no_defs +over",
    "active":true,                                                              
    "name":"layer"                                                              
  }]                                                                            
} 

So the problem is not with the datasource, but maybe with the lack of data inside Stylesheet.

strk commented 8 years ago

The data element is set from the cartoRenderer first argument:

  // convert CartoCSS to Mapnik XML                                             
  cartoRenderer : function (css, layer, callback) {                             

    var options = {                                                             
      // srid 3857                                                              
      "srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",

      "Stylesheet": [{                                                          
        "id" : 'tile_style',                                                    
        "data" : css                                                            
      }],                                                                       
      "Layer" : [layer]                                                         
    }               

So I guess it is undefined as a parameter, and disappears on JSON.stringify, I guess ?

strk commented 8 years ago

Confirmed:

> a = { x : undefined }
{ x: undefined }
> JSON.stringify(a);
'{}'
strk commented 8 years ago

Ok, closing this -- I clearly see now that the proiblem is a missing CartoCSS for raster, and it's clear why (needed to be fixed in systemapic.js)