Improve script cli diagnostics

This commit is contained in:
Ilya Chernikov
2019-11-29 13:18:16 +01:00
parent 49de5e19fb
commit f2a4a835e7
4 changed files with 11 additions and 5 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
error: source file or directory not found: path/to/nonexistent.kts
error: script file not found: path/to/nonexistent.kts; Specify path to the script file as the first argument
COMPILATION_ERROR
+1 -1
View File
@@ -1,2 +1,2 @@
error: specify path to the script file as the first argument
error: script argument points to a directory: $TESTDATA_DIR$/wrongAbiVersionLib; Specify path to the script file as the first argument
COMPILATION_ERROR
+1 -1
View File
@@ -1,2 +1,2 @@
error: specify path to the script file as the first argument
error: unrecognized script file: $TESTDATA_DIR$/simple.kt; Specify path to the script file as the first argument
COMPILATION_ERROR
@@ -60,11 +60,17 @@ abstract class AbstractScriptEvaluationExtension : ScriptEvaluationExtension {
val scriptFile = File(arguments.freeArgs.first())
val script = scriptFile.toScriptSource()
if (scriptFile.isDirectory || !scriptDefinitionProvider.isScript(script)) {
val error = when {
!scriptFile.exists() -> "Script file not found: ${arguments.freeArgs.first()}"
scriptFile.isDirectory -> "Script argument points to a directory: ${arguments.freeArgs.first()}"
!scriptDefinitionProvider.isScript(script) -> "Unrecognized script file: ${arguments.freeArgs.first()}"
else -> null
}
if (error != null) {
val extensionHint =
if (configuration.get(ScriptingConfigurationKeys.SCRIPT_DEFINITIONS)?.let { it.size == 1 && it.first().isDefault } == true) " (.kts)"
else ""
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify path to the script file$extensionHint as the first argument")
messageCollector.report(CompilerMessageSeverity.ERROR, "$error; Specify path to the script file$extensionHint as the first argument")
return ExitCode.COMPILATION_ERROR
}
script