Skip to content

Commit edbb0c5

Browse files
committed
fix(devins-lang): improve error handling and add validation for file-func command
#101
1 parent 8fdbba8 commit edbb0c5

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/FileFuncInsCommand.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import com.intellij.openapi.vfs.VirtualFile
99
class FileFuncInsCommand(val myProject: Project, val prop: String) : InsCommand {
1010
override fun execute(): String? {
1111
val (functionName, args) = parseRegex(prop)
12+
?: return """<DevInsError>: file-func is not in the format @file-func:<functionName>(<arg1>, <arg2>, ...)
13+
|Example: @file-func:regex(".*\.kt")
14+
""".trimMargin()
15+
1216
val fileFunction = FileFunc.fromString(functionName) ?: return "<DevInsError>: Unknown function: $functionName"
1317
when (fileFunction) {
1418
FileFunc.Regex -> {
@@ -46,7 +50,7 @@ class FileFuncInsCommand(val myProject: Project, val prop: String) : InsCommand
4650
* @return The function name and the list of arguments as a Pair object.
4751
* @throws IllegalArgumentException if the property string has invalid regex pattern.
4852
*/
49-
fun parseRegex(prop: String): Pair<String, List<String>> {
53+
fun parseRegex(prop: String): Pair<String, List<String>>? {
5054
val regexPattern = Regex("""(\w+)\(([^)]+)\)""")
5155
val matchResult = regexPattern.find(prop)
5256

@@ -55,6 +59,6 @@ fun parseRegex(prop: String): Pair<String, List<String>> {
5559
val args = matchResult.groupValues[2].split(',').map { it.trim() }
5660
return Pair(functionName, args)
5761
} else {
58-
throw IllegalArgumentException("Invalid regex pattern: $prop")
62+
return null
5963
}
6064
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/run/DevInsRunConfigurationProfileState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ open class DevInsRunConfigurationProfileState(
7575
// contains <DevInsError> means error
7676
output.split("\n").forEach {
7777
if (it.contains("<DevInsError>")) {
78-
console.print(it, ConsoleViewContentType.ERROR_OUTPUT)
78+
console.print(it, ConsoleViewContentType.LOG_ERROR_OUTPUT)
7979
} else {
8080
console.print(it, ConsoleViewContentType.USER_INPUT)
8181
}

0 commit comments

Comments
 (0)