Skip to content

Commit e21ab25

Browse files
committed
Remap processing failures to ingestionError, which get recorded and advance the state
1 parent c835250 commit e21ab25

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

Sources/App/Commands/Common.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func recordError(database: Database,
115115
break
116116
case let .genericError(id, _):
117117
try await setStatus(id: id, status: .ingestionFailed)
118+
case let .ingestionError(id, _):
119+
try await setStatus(id: id, status: .ingestionFailed)
118120
case let .invalidPackageCachePath(id, _):
119121
try await setStatus(id: id, status: .invalidCachePath)
120122
case let .cacheDirectoryDoesNotExist(id, _):

Sources/App/Commands/Ingest.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ func ingest(client: Client,
142142
}
143143

144144
do {
145+
let result = result.mapError {
146+
AppError.ingestionError(pkg.model.id, $0.localizedDescription) as Error
147+
}
145148
try await updatePackage(client: client, database: database, result: result, stage: .ingestion)
146149
} catch {
147150
Current.logger().report(error: error)

Sources/App/Core/AppError.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum AppError: LocalizedError {
2020
case envVariableNotSet(_ variable: String)
2121
case invalidPackageCachePath(Package.Id?, _ path: String)
2222
case cacheDirectoryDoesNotExist(Package.Id?, _ path: String)
23+
case ingestionError(Package.Id?, _ message: String)
2324
case invalidRevision(Version.Id?, _ revision: String?)
2425
case noValidVersions(Package.Id?, _ url: String)
2526
case shellCommandFailed(_ command: String, _ path: String, _ message: String)
@@ -32,6 +33,8 @@ enum AppError: LocalizedError {
3233
return "Analysis failed: \(message) (id: \(id))"
3334
case let .envVariableNotSet(value):
3435
return "Environment variable not set: \(value)"
36+
case let .ingestionError(id, message):
37+
return "Ingestion error: \(message) (id: \(id))"
3538
case let .invalidPackageCachePath(id, value):
3639
return "Invalid packge cache path: \(value) (id: \(id))"
3740
case let .cacheDirectoryDoesNotExist(id, value):

Tests/AppTests/ErrorReportingTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ErrorReportingTests: AppTestCase {
3333

3434
func test_Ingestor_error_reporting() async throws {
3535
// setup
36-
try await Package(url: "1", processingStage: .reconciliation).save(on: app.db)
36+
try await Package(id: .id0, url: "1", processingStage: .reconciliation).save(on: app.db)
3737
Current.fetchMetadata = { _, _, _ in throw Github.Error.invalidURI(nil, "1") }
3838

3939
// MUT
@@ -42,7 +42,7 @@ class ErrorReportingTests: AppTestCase {
4242
// validation
4343
logger.logs.withValue {
4444
XCTAssertEqual($0, [.init(level: .warning,
45-
message: #"App.Github.Error.invalidURI(nil, "1")"#)])
45+
message: #"App.AppError.ingestionError(Optional(\#(UUID.id0)), "invalid URL: 1 (id: nil)")"#)])
4646
}
4747
}
4848

0 commit comments

Comments
 (0)