Skip to content

Commit 287338b

Browse files
committed
Handle ManifestErrors
1 parent ed861ea commit 287338b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Sources/App/Controllers/ValidateSPIManifestController.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ enum ValidateSPIManifestController {
3838
static func validationResult(manifest: String) -> ValidateSPIManifest.ValidationResult {
3939
do {
4040
return .valid(try SPIManifest.Manifest.load(data: Data(manifest.utf8)))
41-
} catch let error as DecodingError {
42-
return .invalid("\(error)")
41+
} catch let ManifestError.decodingError(error) {
42+
return .invalid("Decoding failed: \(error)")
43+
} catch let ManifestError.fileTooLarge(size: size) {
44+
return .invalid("File must not exceed \(SPIManifest.Manifest.maxByteSize) bytes. File size: \(size) bytes.")
4345
} catch {
4446
return .invalid(error.localizedDescription)
4547
}

Tests/AppTests/ValidateSPIManifestControllerTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ final class ValidateSPIManifestControllerTests: XCTestCase {
4040
let res = ValidateSPIManifestController.validationResult(manifest: yml)
4141

4242
// validate
43-
XCTAssertEqual(res.isValid, false)
43+
XCTAssertEqual(res, .invalid("Decoding failed: Key not found: 'version'."))
4444
}
4545

4646
func test_validationResult_tooLarge() throws {
@@ -58,6 +58,7 @@ final class ValidateSPIManifestControllerTests: XCTestCase {
5858

5959
// validate
6060
XCTAssertEqual(res.isValid, false)
61+
XCTAssertEqual(res, .invalid("File must not exceed \(SPIManifest.Manifest.maxByteSize) bytes. File size: \(yml.count) bytes."))
6162
}
6263

6364
}

0 commit comments

Comments
 (0)