Skip to content

Commit

Permalink
Merge pull request #2403 from mapbox/maxim/2399-route-options-crash
Browse files Browse the repository at this point in the history
Add exception in case if leg in route doesn't contain any steps.
  • Loading branch information
MaximAlien authored Jul 27, 2020
2 parents 5640465 + 1e62b49 commit 45ff7c3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ViewController: UIViewController {

var response: RouteResponse? {
didSet {
guard let routes = response?.routes, let current = routes.first else {
guard let routes = response?.routes, let current = routes.first, let steps = current.legs.first?.steps, !steps.isEmpty else {
startButton.isEnabled = false
mapView?.removeRoutes()
return
Expand Down
3 changes: 3 additions & 0 deletions MapboxCoreNavigation/RouteProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ open class RouteLegProgress {
public init(leg: RouteLeg, stepIndex: Int = 0, spokenInstructionIndex: Int = 0) {
self.leg = leg
self.stepIndex = stepIndex

precondition(leg.steps.indices.contains(stepIndex), "It's not possible to create RouteLegProgress without any steps or when stepIndex is higher than steps count.")

currentStepProgress = RouteStepProgress(step: leg.steps[stepIndex], spokenInstructionIndex: spokenInstructionIndex)
}

Expand Down
1 change: 1 addition & 0 deletions MapboxCoreNavigationTests/RouteProgressTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class RouteProgressTests: XCTestCase {
.init(value: 50, unit: .kilometersPerHour),
.init(value: .infinity, unit: .kilometersPerHour),
]

let legProgress = RouteLegProgress(leg: leg)

XCTAssertEqual(legProgress.distanceTraveled, 0)
Expand Down
2 changes: 1 addition & 1 deletion MapboxNavigationTests/SKUTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SKUTests: XCTestCase {

wait(for: [tokenExpectation], timeout: 5)

XCTAssertEqual(viewController.mapViewToken!.skuId, SkuID.navigationUser.rawValue)
XCTAssertEqual(viewController.mapViewToken?.skuId, SkuID.navigationUser.rawValue)
XCTAssertEqual(viewController.mapViewToken, viewController.directionsToken)
XCTAssertEqual(viewController.mapViewToken, viewController.speechSynthesizerToken)

Expand Down

0 comments on commit 45ff7c3

Please sign in to comment.