Skip to content

Commit 8ce54d0

Browse files
committed
fix(compiler): use consistent error message format across commands
The commit message above follows the Conventional Commits specification, indicating that it is a fix to the compiler package. It describes the change as using a consistent error message format across all commands. This suggests that previously, different commands were using different formats for error messages, which has now been standardized. The message is concise and to the point, providing enough information for developers to understand the nature of the change without going into unnecessary detail.
1 parent 1e86b1d commit 8ce54d0

File tree

9 files changed

+28
-17
lines changed

9 files changed

+28
-17
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package cc.unitmesh.devti.language.compiler.error
2+
3+
val DEVINS_ERROR = "<DevInsError>"

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cc.unitmesh.devti.language.compiler.exec
22

3+
import cc.unitmesh.devti.language.compiler.error.DEVINS_ERROR
34
import cc.unitmesh.devti.language.completion.dataprovider.FileFunc
45
import cc.unitmesh.devti.language.utils.canBeAdded
56
import com.intellij.openapi.project.Project
@@ -13,14 +14,14 @@ class FileFuncInsCommand(val myProject: Project, val prop: String) : InsCommand
1314
|Example: @file-func:regex(".*\.kt")
1415
""".trimMargin()
1516

16-
val fileFunction = FileFunc.fromString(functionName) ?: return "<DevInsError>: Unknown function: $functionName"
17+
val fileFunction = FileFunc.fromString(functionName) ?: return "$DEVINS_ERROR: Unknown function: $functionName"
1718
when (fileFunction) {
1819
FileFunc.Regex -> {
1920
try {
2021
val regex = Regex(args[0])
2122
return regexFunction(regex, myProject).joinToString(", ")
2223
} catch (e: Exception) {
23-
return "<DevInsError>: ${e.message}"
24+
return DEVINS_ERROR + ": ${e.message}"
2425
}
2526
}
2627
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cc.unitmesh.devti.language.compiler.exec
22

3+
import cc.unitmesh.devti.language.compiler.error.DEVINS_ERROR
34
import cc.unitmesh.devti.language.utils.lookupFile
45
import cc.unitmesh.devti.provider.AutoTestService
56
import com.intellij.openapi.project.Project
@@ -15,17 +16,17 @@ import com.intellij.psi.PsiManager
1516
*/
1617
class RunInsCommand(val myProject: Project, private val argument: String) : InsCommand {
1718
override suspend fun execute(): String? {
18-
val virtualFile = myProject.lookupFile(argument.trim()) ?: return "<DevInsError>: File not found: $argument"
19+
val virtualFile = myProject.lookupFile(argument.trim()) ?: return "$DEVINS_ERROR: File not found: $argument"
1920
try {
2021
val psiFile: PsiFile =
21-
PsiManager.getInstance(myProject).findFile(virtualFile) ?: return "<DevInsError>: File not found: $argument"
22+
PsiManager.getInstance(myProject).findFile(virtualFile) ?: return "$DEVINS_ERROR: File not found: $argument"
2223
val testService =
23-
AutoTestService.context(psiFile) ?: return "<DevInsError>: No test service found for file: $argument"
24+
AutoTestService.context(psiFile) ?: return "$DEVINS_ERROR: No test service found for file: $argument"
2425
testService.runFile(myProject, virtualFile, null)
2526

2627
return "Running tests for file: $argument"
2728
} catch (e: Exception) {
28-
return "<DevInsError>: ${e.message}"
29+
return "$DEVINS_ERROR: ${e.message}"
2930
}
3031
}
3132
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cc.unitmesh.devti.language.compiler.exec
22

3+
import cc.unitmesh.devti.language.compiler.error.DEVINS_ERROR
34
import cc.unitmesh.devti.language.compiler.service.ShellRunService
45
import cc.unitmesh.devti.language.utils.lookupFile
56
import com.intellij.execution.RunnerAndConfigurationSettings
@@ -20,7 +21,7 @@ import com.intellij.sh.run.ShRunner
2021
*/
2122
class ShellInsCommand(val myProject: Project, private val argument: String) : InsCommand {
2223
override suspend fun execute(): String? {
23-
val virtualFile = myProject.lookupFile(argument.trim()) ?: return "<DevInsError>: File not found: $argument"
24+
val virtualFile = myProject.lookupFile(argument.trim()) ?: return "$DEVINS_ERROR: File not found: $argument"
2425
val psiFile = PsiManager.getInstance(myProject).findFile(virtualFile) as? ShFile
2526
val settings: RunnerAndConfigurationSettings? = ShellRunService().createRunSettings(myProject, virtualFile, psiFile)
2627

@@ -31,7 +32,7 @@ class ShellInsCommand(val myProject: Project, private val argument: String) : In
3132

3233
val workingDirectory = virtualFile.parent.path
3334
val shRunner = ApplicationManager.getApplication().getService(ShRunner::class.java)
34-
?: return "<DevInsError>: Shell runner not found"
35+
?: return "$DEVINS_ERROR: Shell runner not found"
3536

3637
if (shRunner.isAvailable(myProject)) {
3738
shRunner.run(myProject, virtualFile.path, workingDirectory, "RunDevInsShell", true)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cc.unitmesh.devti.language.compiler.exec
22

3+
import cc.unitmesh.devti.language.compiler.error.DEVINS_ERROR
34
import cc.unitmesh.devti.provider.devins.DevInsSymbolProvider
45
import com.intellij.openapi.project.Project
56

@@ -13,7 +14,7 @@ class SymbolInsCommand(val myProject: Project, val prop: String) :
1314
}
1415

1516
if (result.isEmpty()) {
16-
return "<DevInsError> No symbol found: $prop"
17+
return "$DEVINS_ERROR No symbol found: $prop"
1718
}
1819

1920
return result.joinToString("\n")

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cc.unitmesh.devti.language.compiler.exec
22

3+
import cc.unitmesh.devti.language.compiler.error.DEVINS_ERROR
34
import cc.unitmesh.devti.language.compiler.model.LineInfo
45
import cc.unitmesh.devti.language.utils.lookupFile
56
import cc.unitmesh.devti.util.parser.Code
@@ -15,11 +16,11 @@ class WriteInsCommand(val myProject: Project, val argument: String, val content:
1516
val range: LineInfo? = LineInfo.fromString(argument)
1617
val filename = argument.split("#")[0]
1718

18-
val virtualFile = myProject.lookupFile(filename) ?: return "<DevInsError>: File not found: $argument"
19+
val virtualFile = myProject.lookupFile(filename) ?: return "$DEVINS_ERROR: File not found: $argument"
1920
val psiFile = PsiManager.getInstance(myProject).findFile(virtualFile)
20-
?: return "<DevInsError>: File not found: $argument"
21+
?: return "$DEVINS_ERROR: File not found: $argument"
2122
val document = PsiDocumentManager.getInstance(myProject).getDocument(psiFile)
22-
?: return "<DevInsError>: File not found: $argument"
23+
?: return "$DEVINS_ERROR: File not found: $argument"
2324

2425
val resultMsg = WriteAction.computeAndWait<String, Throwable> {
2526
val startLine = range?.startLine ?: 0
@@ -31,7 +32,7 @@ class WriteInsCommand(val myProject: Project, val argument: String, val content:
3132
try {
3233
document.replaceString(startOffset, endOffset, content)
3334
} catch (e: Exception) {
34-
return@computeAndWait "<DevInsError>: ${e.message}"
35+
return@computeAndWait "$DEVINS_ERROR: ${e.message}"
3536
}
3637

3738
return@computeAndWait "Writing to file: $argument"

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/documentation/DevInsDocumentationProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cc.unitmesh.devti.language.documentation
22

33
import cc.unitmesh.devti.agent.model.CustomAgentConfig
44
import cc.unitmesh.devti.custom.compile.CustomVariable
5+
import cc.unitmesh.devti.language.DevInLanguage
56
import cc.unitmesh.devti.language.completion.dataprovider.BuiltinCommand
67
import cc.unitmesh.devti.language.psi.DevInTypes
78
import cc.unitmesh.devti.util.parser.convertMarkdownToHtml
@@ -27,7 +28,8 @@ class DevInsDocumentationProvider : AbstractDocumentationProvider() {
2728
DevInTypes.COMMAND_ID -> {
2829
val command = BuiltinCommand.all().find { it.commandName == element.text } ?: return null
2930
val example = BuiltinCommand.example(command)
30-
"${command.description}\nExample:\n```devin\n$example\n```\n "
31+
val lang = DevInLanguage.displayName
32+
"${command.description}\nExample:\n```$lang\n$example\n```\n "
3133
}
3234

3335
DevInTypes.VARIABLE_ID -> {

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/psi/DevInFile.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DevInFile(viewProvider: FileViewProvider) : PsiFileBase(viewProvider, DevI
2323
* Create a temp DevInFile from a string.
2424
*/
2525
fun fromString(project: Project, text: String): DevInFile {
26-
val filename = "DevIns-${UUID.randomUUID()}.devin"
26+
val filename = DevInLanguage.displayName + "-${UUID.randomUUID()}.devin"
2727
val devInFile = PsiFileFactory.getInstance(project)
2828
.createFileFromText(filename, DevInLanguage, text) as DevInFile
2929

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import cc.unitmesh.devti.agent.CustomAgentExecutor
44
import cc.unitmesh.devti.agent.model.CustomAgentConfig
55
import cc.unitmesh.devti.language.compiler.DevInsCompiler
66
import cc.unitmesh.devti.language.psi.DevInFile
7+
import cc.unitmesh.devti.language.compiler.error.DEVINS_ERROR
78
import cc.unitmesh.devti.language.run.flow.DevInsConversationService
89
import cc.unitmesh.devti.language.status.DevInsRunListener
910
import cc.unitmesh.devti.llms.LLMProvider
@@ -103,7 +104,7 @@ open class DevInsRunConfigurationProfileState(
103104
val agent = compileResult.executeAgent
104105

105106
output.split("\n").forEach {
106-
if (it.contains("<DevInsError>")) {
107+
if (it.contains(DEVINS_ERROR)) {
107108
console.print(it, ConsoleViewContentType.LOG_ERROR_OUTPUT)
108109
} else {
109110
console.print(it, ConsoleViewContentType.USER_INPUT)
@@ -114,7 +115,7 @@ open class DevInsRunConfigurationProfileState(
114115
console.print("\n--------------------\n", ConsoleViewContentType.NORMAL_OUTPUT)
115116

116117
// throw error if contains any <DevInsError>
117-
if (output.contains("<DevInsError>")) {
118+
if (output.contains(DEVINS_ERROR)) {
118119
processHandler.exitWithError()
119120
return DefaultExecutionResult(console, processHandler)
120121
}

0 commit comments

Comments
 (0)