Skip to content

Commit

Permalink
Add error handling when parsing SDK metadata (mapbox#2243)
Browse files Browse the repository at this point in the history
  • Loading branch information
evil159 authored Jul 31, 2024
1 parent ad68bf7 commit 2566f55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 0 additions & 1 deletion Sources/MapboxMaps/Foundation/Events/EventsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ internal final class EventsManager: EventsManagerProtocol {
private enum Constants {
static let MGLAPIClientUserAgentBase = "mapbox-maps-ios"
static let SDKVersion = Bundle.mapboxMapsMetadata.version
static let UserAgent = String(format: "%/%", MGLAPIClientUserAgentBase, SDKVersion)
}

/// Responsible for location and telemetry metrics events
Expand Down
12 changes: 9 additions & 3 deletions Sources/MapboxMaps/Foundation/Extensions/Bundle+MapboxMaps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ extension Bundle {
}

static var mapboxMapsMetadata: MapboxMapsMetadata = {
let metadataPath = Bundle.mapboxMaps.url(forResource: "MapboxMaps", withExtension: "json")!
let data = try! Data(contentsOf: metadataPath)
return try! JSONDecoder().decode(MapboxMapsMetadata.self, from: data)
guard let metadataPath = Bundle.mapboxMaps.url(forResource: "MapboxMaps", withExtension: "json") else {
return MapboxMapsMetadata(version: "unknown.ios-metatadata-failure")
}
do {
let data = try Data(contentsOf: metadataPath)
return try JSONDecoder().decode(MapboxMapsMetadata.self, from: data)
} catch {
return MapboxMapsMetadata(version: "unknown.ios-metatadata-failure")
}
}()
}

0 comments on commit 2566f55

Please sign in to comment.