Error: Cannot compile expression: The first block needs to end with an 'else' (or contain a single unconditional 'if' statement)

I am trying to run graphhopper locally and I have a custom profile I set up named small_truck.json, however when I start up the server, I get the following error:

Profile: name=small_truck|turn_costs={null}|weighting=custom|hints={custom_model_files=[small_truck.json], custom_model=distanceInfluence=null|headingPenalty=null|speedStatements=[{"if": "road_class == MOTORWAY", "multiply_by": 0.8}, {"else": "null", "multiply_by": 1.0}]|priorityStatements=[{"if": "road_class == MOTORWAY", "multiply_by": 0.5}, {"else": "null", "multiply_by": 1.0}]|areas=[]}
Error: Cannot compile expression: The first block needs to end with an 'else' (or contain a single unconditional 'if' statement).

My small_truck.json profile is below:

{
  "priority": [
    {
      "if": "road_class == MOTORWAY",
      "multiply_by": 0.5
    },
    {
      "else_if": "road_class == TRUNK",
      "multiply_by": 0.5
    },
    {
      "else_if": "road_class == PARKWAY",
      "multiply_by": 0.1
    },
    {
      "else": "",
      "multiply_by": 1.0
    }
  ],
  "speed": [
    {
      "if": "road_class == MOTORWAY",
      "multiply_by": 0.8
    },
    {
      "else_if": "road_class == TRUNK",
      "multiply_by": 0.8
    },
    {
      "else_if": "road_class == PARKWAY",
      "multiply_by": 0.5
    },
    {
      "else": "",
      "multiply_by": 1.0
    }
  ]
}

Any help is appreciated, thanks you!

The problem is that you need to limit the speed to a certain value. If you are doing multiply_by you are basically multiplying some unknown speed with a factor leading to an unknown value. You could do e.g. "limit_to": "120" or use "limit_to": "car_average_speed*0.8".

For “priority” this is not necessary as the default priority is 1 and not “unknown”.

Also not that PARKWAY is not a known value of road_class and it’ll fail to compile.

1 Like

Is there a way to figure out and block roads from the navigation that are a parkway? :thinking:

Probably it is the same as road_class == PRIMARY?
Have a look into the different values: Key:highway - OpenStreetMap Wiki