Skip to content

Commit 784c5ae

Browse files
authored
fix: throwing error
1 parent c6d3ca7 commit 784c5ae

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Sources/ArchiveDetective/app.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,47 @@ import Foundation
33
@main
44
struct ArchiveDetective {
55
static func main() async {
6-
print("Fetching JSON from source..."); fflush(stdout)
7-
86
let jsonData: [String: Any]
97
do {
108
jsonData = try await JSONFetcher.fetch()
119
} catch {
12-
print("Failed to fetch JSON: \(error)"); fflush(stdout)
10+
print("Failed to fetch JSON: \(error)")
1311
return
1412
}
1513

16-
print("Extracting GitHub repository links..."); fflush(stdout)
1714
let repoLinks = RepoExtractor.extract(from: jsonData)
18-
print("\(repoLinks.count) repositories to check."); fflush(stdout)
15+
print("\(repoLinks.count) repositories to check.")
1916

20-
let results = try await withThrowingTaskGroup(of: Models.RepoStatus.self) { group -> [Models.RepoStatus] in
21-
for url in repoLinks {
22-
group.addTask {
23-
return await RepoStatusChecker.checkStatus(for: url)
17+
var results: [Models.RepoStatus] = []
18+
do {
19+
results = try await withThrowingTaskGroup(of: Models.RepoStatus.self) { group -> [Models.RepoStatus] in
20+
for url in repoLinks {
21+
group.addTask {
22+
return await RepoStatusChecker.checkStatus(for: url)
23+
}
2424
}
25-
}
2625

27-
var all: [Models.RepoStatus] = []
28-
for try await result in group {
29-
all.append(result)
26+
var all: [Models.RepoStatus] = []
27+
for try await result in group {
28+
all.append(result)
29+
}
30+
return all
3031
}
31-
return all
32+
} catch {
33+
print("Error while checking repository statuses: \(error)")
34+
return
3235
}
3336

34-
print("Updating README..."); fflush(stdout)
37+
3538
do {
3639
try ReadmeUpdater.update(with: results)
3740
} catch {
38-
print("Failed to update README: \(error)"); fflush(stdout)
41+
print("Failed to update README: \(error)")
3942
}
4043

41-
print("\n Summary:"); fflush(stdout)
4244
let archived = results.filter { $0.status == "Archived" }.count
4345
let notFound = results.filter { $0.status == "Not Found" }.count
4446
let forbidden = results.filter { $0.status?.contains("Forbidden") == true }.count
45-
print(" Archived: \(archived)"); fflush(stdout)
46-
print(" Not Found: \(notFound)"); fflush(stdout)
47-
print(" Forbidden: \(forbidden)"); fflush(stdout)
47+
print("Archived: \(archived)", "Not Found: \(notFound)", "Forbidden: \(forbidden)")
4848
}
4949
}

0 commit comments

Comments
 (0)