Skip to content

Commit 3d76d22

Browse files
committed
Custom error handler
1 parent 7193eb4 commit 3d76d22

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

Sources/ProjectSpec/Project.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,16 @@ extension Project {
193193
attributes = jsonDictionary.json(atKeyPath: "attributes") ?? [:]
194194
include = jsonDictionary.json(atKeyPath: "include") ?? []
195195
if jsonDictionary["packages"] != nil {
196-
packages = try jsonDictionary.json(atKeyPath: "packages", invalidItemBehaviour: .fail)
196+
packages = try jsonDictionary.json(atKeyPath: "packages", invalidItemBehaviour: .custom({ error in
197+
var pairs = [(String, Any)]()
198+
for item in error.dictionary {
199+
pairs.append((
200+
item.key as? String ?? "",
201+
(item.value as? Double).map { String($0) + ".0" } ?? item.value
202+
))
203+
}
204+
return (try? .value(.init(jsonDictionary: .init(uniqueKeysWithValues: pairs)))) ?? .fail
205+
}))
197206
} else {
198207
packages = [:]
199208
}

Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@
255255
packageReferences = (
256256
5BA91390AE78D2EE15C60091 /* XCRemoteSwiftPackageReference "Codability" */,
257257
348C81C327DB1710B742C370 /* XCRemoteSwiftPackageReference "Prefire" */,
258+
63B845B0C9058076DD19CA85 /* XCRemoteSwiftPackageReference "SwiftLocation" */,
258259
E3887F3CB2C069E70D98092F /* XCRemoteSwiftPackageReference "SwiftRoaring" */,
259260
630A8CE9F2BE39704ED9D461 /* XCLocalSwiftPackageReference "FooFeature" */,
260261
C6539B364583AE96C18CE377 /* XCLocalSwiftPackageReference "../../.." */,
@@ -671,6 +672,14 @@
671672
minimumVersion = 0.2.1;
672673
};
673674
};
675+
63B845B0C9058076DD19CA85 /* XCRemoteSwiftPackageReference "SwiftLocation" */ = {
676+
isa = XCRemoteSwiftPackageReference;
677+
repositoryURL = "https://github.com/malcommac/SwiftLocation";
678+
requirement = {
679+
kind = exactVersion;
680+
version = 6.0.0;
681+
};
682+
};
674683
E3887F3CB2C069E70D98092F /* XCRemoteSwiftPackageReference "SwiftRoaring" */ = {
675684
isa = XCRemoteSwiftPackageReference;
676685
repositoryURL = "https://github.com/piotte13/SwiftRoaring";

Tests/Fixtures/SPM/project.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ packages:
99
Prefire:
1010
url: https://github.com/BarredEwe/Prefire
1111
majorVersion: 1.4.1
12+
SwiftLocation:
13+
url: https://github.com/malcommac/SwiftLocation
14+
exactVersion: 6.0
1215
XcodeGen:
1316
path: ../../.. #XcodeGen itself
1417
group: SPM

0 commit comments

Comments
 (0)