return correct exit code when script execution fails
This commit is contained in:
@@ -19,7 +19,8 @@ package org.jetbrains.kotlin.cli.common;
|
|||||||
public enum ExitCode {
|
public enum ExitCode {
|
||||||
OK(0),
|
OK(0),
|
||||||
COMPILATION_ERROR(1),
|
COMPILATION_ERROR(1),
|
||||||
INTERNAL_ERROR(2);
|
INTERNAL_ERROR(2),
|
||||||
|
SCRIPT_EXECUTION_ERROR(3);
|
||||||
|
|
||||||
private final int code;
|
private final int code;
|
||||||
|
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ open class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
|||||||
|
|
||||||
if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) return COMPILATION_ERROR
|
if (messageSeverityCollector.anyReported(CompilerMessageSeverity.ERROR)) return COMPILATION_ERROR
|
||||||
|
|
||||||
KotlinToJVMBytecodeCompiler.compileAndExecuteScript(configuration, paths, environment, scriptArgs)
|
return KotlinToJVMBytecodeCompiler.compileAndExecuteScript(configuration, paths, environment, scriptArgs)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
environment = createCoreEnvironment(rootDisposable, configuration)
|
environment = createCoreEnvironment(rootDisposable, configuration)
|
||||||
|
|||||||
+5
-2
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.analyzer.AnalysisResult
|
|||||||
import org.jetbrains.kotlin.asJava.FilteredJvmDiagnostics
|
import org.jetbrains.kotlin.asJava.FilteredJvmDiagnostics
|
||||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||||
import org.jetbrains.kotlin.cli.common.CompilerPluginContext
|
import org.jetbrains.kotlin.cli.common.CompilerPluginContext
|
||||||
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
@@ -196,8 +197,8 @@ object KotlinToJVMBytecodeCompiler {
|
|||||||
configuration: CompilerConfiguration,
|
configuration: CompilerConfiguration,
|
||||||
paths: KotlinPaths,
|
paths: KotlinPaths,
|
||||||
environment: KotlinCoreEnvironment,
|
environment: KotlinCoreEnvironment,
|
||||||
scriptArgs: List<String>) {
|
scriptArgs: List<String>): ExitCode {
|
||||||
val scriptClass = compileScript(configuration, paths, environment) ?: return
|
val scriptClass = compileScript(configuration, paths, environment) ?: return ExitCode.COMPILATION_ERROR
|
||||||
val scriptConstructor = getScriptConstructor(scriptClass)
|
val scriptConstructor = getScriptConstructor(scriptClass)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -205,8 +206,10 @@ object KotlinToJVMBytecodeCompiler {
|
|||||||
}
|
}
|
||||||
catch (e: Throwable) {
|
catch (e: Throwable) {
|
||||||
reportExceptionFromScript(e)
|
reportExceptionFromScript(e)
|
||||||
|
return ExitCode.SCRIPT_EXECUTION_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ExitCode.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reportExceptionFromScript(exception: Throwable) {
|
private fun reportExceptionFromScript(exception: Throwable) {
|
||||||
|
|||||||
Reference in New Issue
Block a user