Skip to content

Commit

Permalink
Better Evolution Proposal error handling (#258)
Browse files Browse the repository at this point in the history
* Better Evolution Proposal error handling

* Update EvolutionChecker.swift

* Update EvolutionChecker.swift

* Update EvolutionChecker.swift
  • Loading branch information
MahdiBM authored Oct 26, 2024
1 parent 900f84d commit ab76de7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
27 changes: 23 additions & 4 deletions Sources/Penny/EvolutionChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ actor EvolutionChecker {

var storage = Storage()

var reportedProposalIDsThatContainErrors: Set<String> = []

/// The minimum time to wait before sending a queued-proposal
let queuedProposalsWaitTime: Double

Expand Down Expand Up @@ -57,6 +59,23 @@ actor EvolutionChecker {
return
}

let proposalIDsWithError = proposals.filter {
!($0.errors ?? []).isEmpty
}.map(\.id)
if !proposalIDsWithError.isEmpty {
let allAreAlreadyReported = self.reportedProposalIDsThatContainErrors
.isSuperset(of: proposalIDsWithError)
self.reportedProposalIDsThatContainErrors.formUnion(proposalIDsWithError)
self.logger.log(
level: allAreAlreadyReported ? .debug : .warning,
"Will not continue checking proposals because there are errors in some of them",
metadata: [
"proposalsWithError": .stringConvertible(proposalIDsWithError)
]
)
return
}

/// Queue newly-added proposals
let currentIds = Set(self.storage.previousProposals.map(\.id))
let (olds, news) = proposals.divided({ currentIds.contains($0.id) })
Expand Down Expand Up @@ -208,7 +227,7 @@ actor EvolutionChecker {
\(upcomingFeatureFlag)
\(authorsString)
\(reviewManagersString)
""".replaceDoubleNewlinesWithSingleNewline(),
""".replaceTripleNewlinesWithDoubleNewlines(),
url: proposalLink,
color: proposal.status.color
)],
Expand Down Expand Up @@ -269,7 +288,7 @@ actor EvolutionChecker {
\(upcomingFeatureFlag)
\(authorsString)
\(reviewManagersString)
""".replaceDoubleNewlinesWithSingleNewline(),
""".replaceTripleNewlinesWithDoubleNewlines(),
url: proposalLink,
color: proposal.status.color
)],
Expand Down Expand Up @@ -445,7 +464,7 @@ private extension Collection {
}

private extension String {
func replaceDoubleNewlinesWithSingleNewline() -> String {
self.replacingOccurrences(of: "\n\n", with: "\n")
func replaceTripleNewlinesWithDoubleNewlines() -> String {
self.replacingOccurrences(of: "\n\n\n", with: "\n\n")
}
}
4 changes: 2 additions & 2 deletions Tests/PennyTests/Tests/GatewayProcessingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ extension SerializationNamespace.GatewayProcessingTests {

let embed = try #require(message.embeds?.first)
#expect(embed.title == "[SE-0051] Withdrawn: Conventionalizing stride semantics")
#expect(embed.description == "> \n**Status: Withdrawn**\n\n**Author(s):** [Erica Sadun](http://github.com/erica)\n")
#expect(embed.description == "> \n\n**Status: Withdrawn**\n\n**Author(s):** [Erica Sadun](http://github.com/erica)\n")
#expect(embed.color == .brown)
}

Expand Down Expand Up @@ -355,7 +355,7 @@ extension SerializationNamespace.GatewayProcessingTests {

let embed = try #require(message.embeds?.first)
#expect(embed.title == "[SE-0001] In Active Review: Allow (most) keywords as argument labels")
#expect(embed.description == "> Argument labels are an important part of the interface of a Swift function, describing what particular arguments to the function do and improving readability. Sometimes, the most natural label for an argument coincides with a language keyword, such as `in`, `repeat`, or `defer`. Such keywords should be allowed as argument labels, allowing better expression of these interfaces.\n**Status:** Implemented -> **Active Review**\n\n**Author(s):** [Doug Gregor](https://github.com/DougGregor)\n")
#expect(embed.description == "> Argument labels are an important part of the interface of a Swift function, describing what particular arguments to the function do and improving readability. Sometimes, the most natural label for an argument coincides with a language keyword, such as `in`, `repeat`, or `defer`. Such keywords should be allowed as argument labels, allowing better expression of these interfaces.\n\n**Status:** Implemented -> **Active Review**\n\n**Author(s):** [Doug Gregor](https://github.com/DougGregor)\n")
#expect(embed.color == .orange)
}
}
Expand Down

0 comments on commit ab76de7

Please sign in to comment.