Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
strk opened this issue Feb 19, 2016 · 10 comments
Closed

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

strk opened this issue Feb 19, 2016 · 10 comments

Comments

@strk
Copy link

strk commented Feb 19, 2016

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
Copy link
Author

strk commented Feb 19, 2016

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
Copy link
Author

strk commented Feb 19, 2016

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
├─┬ [email protected]
│ ├─┬ [email protected]

@strk
Copy link
Author

strk commented Feb 19, 2016

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

@strk
Copy link
Author

strk commented Feb 19, 2016

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

@strk
Copy link
Author

strk commented Feb 19, 2016

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
Copy link
Author

strk commented Feb 19, 2016

Filed upstream (as I think carto should not throw in any case): mapbox/carto#430

@strk
Copy link
Author

strk commented Feb 19, 2016

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
Copy link
Author

strk commented Feb 19, 2016

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
Copy link
Author

strk commented Feb 19, 2016

Confirmed:

> a = { x : undefined }
{ x: undefined }
> JSON.stringify(a);
'{}'

strk pushed a commit that referenced this issue Feb 19, 2016
strk pushed a commit that referenced this issue Feb 19, 2016
... do not pretend it isn't !

See #18
@strk
Copy link
Author

strk commented Feb 19, 2016

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)

@strk strk closed this as completed Feb 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant