Skip to content

Commit 3419722

Browse files
committed
Fix crash on invalid custom GTFS URL
1 parent bff7a12 commit 3419722

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

macOS/Arrivals.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@
468468
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
469469
CODE_SIGN_STYLE = Manual;
470470
COMBINE_HIDPI_IMAGES = YES;
471-
CURRENT_PROJECT_VERSION = 4;
471+
CURRENT_PROJECT_VERSION = 5;
472472
DEAD_CODE_STRIPPING = YES;
473473
DEVELOPMENT_ASSET_PATHS = "\"Arrivals/Preview Content\"";
474474
DEVELOPMENT_TEAM = "";
@@ -486,7 +486,7 @@
486486
"$(inherited)",
487487
"@executable_path/../Frameworks",
488488
);
489-
MARKETING_VERSION = 0.4;
489+
MARKETING_VERSION = 0.5;
490490
OTHER_LDFLAGS = (
491491
"$(inherited)",
492492
"-framework",
@@ -511,7 +511,7 @@
511511
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
512512
CODE_SIGN_STYLE = Manual;
513513
COMBINE_HIDPI_IMAGES = YES;
514-
CURRENT_PROJECT_VERSION = 4;
514+
CURRENT_PROJECT_VERSION = 5;
515515
DEAD_CODE_STRIPPING = YES;
516516
DEVELOPMENT_ASSET_PATHS = "\"Arrivals/Preview Content\"";
517517
DEVELOPMENT_TEAM = "";
@@ -530,7 +530,7 @@
530530
"$(inherited)",
531531
"@executable_path/../Frameworks",
532532
);
533-
MARKETING_VERSION = 0.4;
533+
MARKETING_VERSION = 0.5;
534534
OTHER_LDFLAGS = (
535535
"$(inherited)",
536536
"-framework",

shared/src/commonMain/kotlin/com/jdamcd/arrivals/gtfs/GtfsArrivals.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@ internal class GtfsArrivals(
3131
throw NoDataException("No arrivals found")
3232
}
3333
} catch (e: Exception) {
34-
throw NoDataException("No connection")
34+
throw NoDataException("Failed to connect")
3535
}
3636
}
3737

3838
private suspend fun updateStops() {
39-
if (!hasFreshStops()) {
40-
stops = GtfsStops(api.downloadStops(settings.gtfsSchedule))
41-
settings.gtfsStopsUpdated = clock.now().epochSeconds
42-
} else if (!::stops.isInitialized) {
43-
stops = GtfsStops(api.readStops())
39+
try {
40+
if (!hasFreshStops()) {
41+
stops = GtfsStops(api.downloadStops(settings.gtfsSchedule))
42+
settings.gtfsStopsUpdated = clock.now().epochSeconds
43+
} else if (!::stops.isInitialized) {
44+
stops = GtfsStops(api.readStops())
45+
}
46+
} catch (e: Exception) {
47+
throw NoDataException("Failed to load stops")
4448
}
4549
}
4650

shared/src/jvmTest/kotlin/com/jdamcd/arrivals/gtfs/GtfsArrivalsTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,14 @@ class GtfsArrivalsTest {
9898
coVerify { api.downloadStops("schedule_url") }
9999
latest.arrivals shouldHaveSize 3
100100
}
101+
102+
@Test
103+
fun `throws NoDataException if stops fail to load`() = runBlocking<Unit> {
104+
every { clock.now() } returns Instant.fromEpochSeconds(fetchTime)
105+
coEvery { api.downloadStops("schedule_url") } throws Exception()
106+
107+
assertFailsWith<NoDataException> {
108+
arrivals.latest()
109+
}
110+
}
101111
}

0 commit comments

Comments
 (0)