Skip to content

Commit

Permalink
Fix crash on invalid custom GTFS URL
Browse files Browse the repository at this point in the history
  • Loading branch information
jdamcd committed Jan 26, 2025
1 parent bff7a12 commit 3419722
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
8 changes: 4 additions & 4 deletions macOS/Arrivals.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Arrivals/Preview Content\"";
DEVELOPMENT_TEAM = "";
Expand All @@ -486,7 +486,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.4;
MARKETING_VERSION = 0.5;
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
Expand All @@ -511,7 +511,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Arrivals/Preview Content\"";
DEVELOPMENT_TEAM = "";
Expand All @@ -530,7 +530,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.4;
MARKETING_VERSION = 0.5;
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ internal class GtfsArrivals(
throw NoDataException("No arrivals found")
}
} catch (e: Exception) {
throw NoDataException("No connection")
throw NoDataException("Failed to connect")
}
}

private suspend fun updateStops() {
if (!hasFreshStops()) {
stops = GtfsStops(api.downloadStops(settings.gtfsSchedule))
settings.gtfsStopsUpdated = clock.now().epochSeconds
} else if (!::stops.isInitialized) {
stops = GtfsStops(api.readStops())
try {
if (!hasFreshStops()) {
stops = GtfsStops(api.downloadStops(settings.gtfsSchedule))
settings.gtfsStopsUpdated = clock.now().epochSeconds
} else if (!::stops.isInitialized) {
stops = GtfsStops(api.readStops())
}
} catch (e: Exception) {
throw NoDataException("Failed to load stops")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,14 @@ class GtfsArrivalsTest {
coVerify { api.downloadStops("schedule_url") }
latest.arrivals shouldHaveSize 3
}

@Test
fun `throws NoDataException if stops fail to load`() = runBlocking<Unit> {
every { clock.now() } returns Instant.fromEpochSeconds(fetchTime)
coEvery { api.downloadStops("schedule_url") } throws Exception()

assertFailsWith<NoDataException> {
arrivals.latest()
}
}
}

0 comments on commit 3419722

Please sign in to comment.