Skip to content

Commit

Permalink
Fix exception handling for the Compiler API. (#26)
Browse files Browse the repository at this point in the history
Ensure Compiler throws CompilerException or children.
Change test infra and CLI to capture those instead.
  • Loading branch information
miguelbranco80 authored Jul 7, 2023
1 parent e089560 commit 7fe10aa
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
10 changes: 1 addition & 9 deletions raw-cli/src/main/scala/raw/cli/RawCli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -698,7 +698,7 @@ trait CompilerTestContext
}

} catch {
case ex: CompilerExecutionException =>
case ex: CompilerException =>
logger.warn("ExecutionException during test.", ex)
Left(ex.getMessage)
} finally {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion raw-compiler/src/main/scala/raw/compiler/Errors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion raw-compiler/src/main/scala/raw/compiler/Program.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7fe10aa

Please sign in to comment.