mapbox / mapbox/mapbox-directions-swift

DecodingError: ManeuverDirection "reverse" not found

Open
#594 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug jira-sync-complete needs more information
Dominant language
Swift
Stars
206
Forks
99
Avg merge
7h 54m
Merged PRs (30d)
3

Description

Hi there

We are frequently getting an error from mapbox when trying to calculate a route using the MapboxDirections API:

 ▿ underlying : Optional<Error>
      ▿ some : DecodingError
        ▿ dataCorrupted : Context
          ▿ codingPath : 10 elements
            - 0 : CodingKeys(stringValue: "routes", intValue: nil)
            ▿ 1 : _JSONKey(stringValue: "Index 0", intValue: 0)
              - stringValue : "Index 0"
              ▿ intValue : Optional<Int>
                - some : 0
            - 2 : CodingKeys(stringValue: "legs", intValue: nil)
            ▿ 3 : _JSONKey(stringValue: "Index 9", intValue: 9)
              - stringValue : "Index 9"
              ▿ intValue : Optional<Int>
                - some : 9
            - 4 : CodingKeys(stringValue: "steps", intValue: nil)
            ▿ 5 : _JSONKey(stringValue: "Index 0", intValue: 0)
              - stringValue : "Index 0"
              ▿ intValue : Optional<Int>
                - some : 0
            - 6 : CodingKeys(stringValue: "bannerInstructions", intValue: nil)
            ▿ 7 : _JSONKey(stringValue: "Index 0", intValue: 0)
              - stringValue : "Index 0"
              ▿ intValue : Optional<Int>
                - some : 0
            - 8 : CodingKeys(stringValue: "primary", intValue: nil)
            - 9 : CodingKeys(stringValue: "modifier", intValue: nil)
          - debugDescription : "Cannot initialize ManeuverDirection from invalid String value reverse"
          - underlyingError : nil
    - code : nil
    - message : nil

When diving in to this further, it looks like this enum value indeed does not exist in the code:

https://github.com/mapbox/mapbox-directions-swift/blob/main/Sources/MapboxDirections/RouteStep.swift

Here is a snippet of an example of one of the offending JSON responses:

                            "bannerInstructions": [
                                {
                                    "primary": {
                                        "components": [
                                            {
                                                "type": "text",
                                                "text": "Enter Winwick Interchange and take the 3rd exit"
                                            }
                                        ],
                                        "degrees": 307,
                                        "driving_side": "left",
                                        "type": "roundabout",
                                        "modifier": "reverse",  <---- ???? 
                                        "text": "Enter Winwick Interchange and take the 3rd exit"
                                    },
                                    "distanceAlongGeometry": 0
                                }
                            ],

Unless i am mistaken it appears the library is not equipped to decode this object.

Keen to hear of a solution, hope this is helpful!

Thanks.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Sources/MapboxDirections/RouteStep.swift, especially the ManeuverDirection enum, and compare its accepted values with the reported Mapbox JSON containing modifier "reverse". Reproduce decoding with the example response and confirm that the route can be decoded successfully without the DecodingError.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.