Skip to content

Commit

Permalink
refactor(core): add exception handling for regex compilation
Browse files Browse the repository at this point in the history
Add try-catch block to handle exceptions when compiling regular expressions in CustomActionBaseIntention. Additionally, simplify the flows function in TeamPromptsBuilder by directly returning the filtered result.
  • Loading branch information
phodal committed Oct 20, 2024
1 parent d0270d5 commit 3112821
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@ class CustomActionBaseIntention(private val intentionConfig: CustomIntentionConf

val builder = StringBuilder()

val customPattern = Pattern.compile(regex)
val matcher = customPattern.matcher(input)
while (matcher.find()) {
builder.append(matcher.group()).append("\n")
try {
val pattern = Pattern.compile(regex)
val matcher = pattern.matcher(input)
while (matcher.find()) {
builder.append(matcher.group()).append("\n")
}
} catch (e: Exception) {
logger.error("Failed to compile regex: $regex", e)
}

return builder.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ class TeamPromptsBuilder(private val project: Project) {
fun flows(): List<VirtualFile> {
val promptsDir = basePromptDir ?: return emptyList()
val promptDir = promptsDir.findChild("flows") ?: return emptyList()
val devinFiles = promptDir.children.filter { it.name.endsWith(".devin") }

return devinFiles
return promptDir.children.filter { it.name.endsWith(".devin") }
}

private fun buildPrompts(prompts: List<VirtualFile>): List<TeamPromptAction> {
Expand Down

0 comments on commit 3112821

Please sign in to comment.