[JS IR] Commonize CLI error reporting

Use general `AnalysisResult.CompilationErrorException` instead of
custom JsIrCompilationError to indicate about unsuccessful compilation

- Drop JsIrCompilationError
This commit is contained in:
Roman Artemev
2021-01-25 15:59:19 +03:00
parent ba5193870e
commit 24d82c63e0
2 changed files with 28 additions and 38 deletions
@@ -192,7 +192,6 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
require(outputFile.extension == KLIB_FILE_EXTENSION) { "Please set up .klib file as output" } require(outputFile.extension == KLIB_FILE_EXTENSION) { "Please set up .klib file as output" }
} }
try {
generateKLib( generateKLib(
project = config.project, project = config.project,
files = sourcesFiles, files = sourcesFiles,
@@ -204,9 +203,6 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
outputKlibPath = outputFile.path, outputKlibPath = outputFile.path,
nopack = arguments.irProduceKlibDir nopack = arguments.irProduceKlibDir
) )
} catch (e: JsIrCompilationError) {
return COMPILATION_ERROR
}
} }
if (arguments.irProduceJs) { if (arguments.irProduceJs) {
@@ -252,8 +248,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
return OK return OK
} }
val compiledModule = try { val compiledModule = compile(
compile(
projectJs, projectJs,
mainModule, mainModule,
AnalyzerWithCompilerReport(config.configuration), AnalyzerWithCompilerReport(config.configuration),
@@ -269,9 +264,6 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
relativeRequirePath = true, relativeRequirePath = true,
propertyLazyInitialization = arguments.irPropertyLazyInitialization, propertyLazyInitialization = arguments.irPropertyLazyInitialization,
) )
} catch (e: JsIrCompilationError) {
return COMPILATION_ERROR
}
val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.dceJsCode!! else compiledModule.jsCode!! val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.dceJsCode!! else compiledModule.jsCode!!
outputFile.writeText(jsCode.mainModule) outputFile.writeText(jsCode.mainModule)
@@ -363,8 +363,6 @@ fun getModuleDescriptorByLibrary(current: KotlinLibrary, mapping: Map<String, Mo
return md return md
} }
object JsIrCompilationError : Throwable()
sealed class MainModule { sealed class MainModule {
class SourceFiles(val files: List<KtFile>) : MainModule() class SourceFiles(val files: List<KtFile>) : MainModule()
class Klib(val lib: KotlinLibrary) : MainModule() class Klib(val lib: KotlinLibrary) : MainModule()
@@ -416,7 +414,7 @@ private class ModulesStructure(
var hasErrors = false var hasErrors = false
if (analyzer.hasErrors() || analysisResult !is JsAnalysisResult) { if (analyzer.hasErrors() || analysisResult !is JsAnalysisResult) {
if (!errorPolicy.allowErrors) if (!errorPolicy.allowErrors)
throw JsIrCompilationError throw AnalysisResult.CompilationErrorException()
else hasErrors = true else hasErrors = true
} }