From 7fe10aaea993c701c9cc518730e0d50d655dcbe0 Mon Sep 17 00:00:00 2001 From: Miguel Branco Date: Fri, 7 Jul 2023 15:22:08 +0200 Subject: [PATCH] Fix exception handling for the Compiler API. (#26) Ensure Compiler throws CompilerException or children. Change test infra and CLI to capture those instead. --- raw-cli/src/main/scala/raw/cli/RawCli.scala | 10 +--------- .../raw/compiler/rql2/tests/CompilerTestContext.scala | 6 +++--- raw-compiler/src/main/scala/raw/compiler/Errors.scala | 2 +- raw-compiler/src/main/scala/raw/compiler/Program.scala | 2 +- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/raw-cli/src/main/scala/raw/cli/RawCli.scala b/raw-cli/src/main/scala/raw/cli/RawCli.scala index 2e34f7368..d5782810e 100644 --- a/raw-cli/src/main/scala/raw/cli/RawCli.scala +++ b/raw-cli/src/main/scala/raw/cli/RawCli.scala @@ -26,14 +26,7 @@ import raw.compiler.base.source.BaseProgram import raw.compiler.common.CompilerService import raw.compiler.rql2.SyntaxAnalyzer import raw.compiler.rql2.source.Rql2Program -import raw.compiler.{ - CompilerException, - CompilerExecutionException, - ErrorMessage, - ProgramDefinition, - ProgramEnvironment, - ProgramOutputWriter -} +import raw.compiler.{CompilerException, ErrorMessage, ProgramDefinition, ProgramEnvironment, ProgramOutputWriter} import raw.config.RawSettings import raw.utils.RawUtils @@ -97,7 +90,6 @@ class RawCli(writer: PrintWriter) extends StrictLogging { } } catch { case ex: CompilerException => printError(ex.getMessage) - case ex: CompilerExecutionException => printError(ex.getMessage) case ex: InterruptedException => printError("program interrupted") throw ex diff --git a/raw-compiler-rql2/src/test/scala/raw/compiler/rql2/tests/CompilerTestContext.scala b/raw-compiler-rql2/src/test/scala/raw/compiler/rql2/tests/CompilerTestContext.scala index 9c039bd3d..82b3e7477 100644 --- a/raw-compiler-rql2/src/test/scala/raw/compiler/rql2/tests/CompilerTestContext.scala +++ b/raw-compiler-rql2/src/test/scala/raw/compiler/rql2/tests/CompilerTestContext.scala @@ -21,7 +21,7 @@ import raw.api.{AuthenticatedUser, InteractiveUser, RawException} import raw.compiler.base.ProgramContext import raw.compiler.base.source.{BaseProgram, Type} import raw.compiler.common.{Compiler, CompilerService} -import raw.compiler.{CompilerExecutionException, LSPRequest, ProgramEnvironment, ProgramOutputWriter} +import raw.compiler.{CompilerException, LSPRequest, ProgramEnvironment, ProgramOutputWriter} import raw.creds._ import raw.creds.mock.MockCredentialsTestContext import raw.inferrer.local.SimpleInferrerTestContext @@ -698,7 +698,7 @@ trait CompilerTestContext } } catch { - case ex: CompilerExecutionException => + case ex: CompilerException => logger.warn("ExecutionException during test.", ex) Left(ex.getMessage) } finally { @@ -765,7 +765,7 @@ trait CompilerTestContext Right(path) } } catch { - case ex: CompilerExecutionException => + case ex: CompilerException => logger.warn("ExecutionException during test.", ex) Left(ex.getMessage) } finally { diff --git a/raw-compiler/src/main/scala/raw/compiler/Errors.scala b/raw-compiler/src/main/scala/raw/compiler/Errors.scala index 818b407bf..3ae5aff9e 100644 --- a/raw-compiler/src/main/scala/raw/compiler/Errors.scala +++ b/raw-compiler/src/main/scala/raw/compiler/Errors.scala @@ -49,4 +49,4 @@ final class CompilerParserException(message: String, val position: ErrorPosition * The message can be safely shared with the user. */ final class CompilerExecutionException(val reason: String, val cause: Throwable = null) - extends RawException(reason, cause) + extends CompilerException(reason, cause) diff --git a/raw-compiler/src/main/scala/raw/compiler/Program.scala b/raw-compiler/src/main/scala/raw/compiler/Program.scala index bd4fde99c..43e4b3bec 100644 --- a/raw-compiler/src/main/scala/raw/compiler/Program.scala +++ b/raw-compiler/src/main/scala/raw/compiler/Program.scala @@ -61,7 +61,7 @@ trait ProgramOutputWriter { * * @param outputStream OutputStream to write results to. */ - @throws[CompilerExecutionException] + @throws[CompilerException] @throws[RawException] // It shouldn't... but can happen and can safely be shared with the user. def writeTo(outputStream: OutputStream): Unit