aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/annotations
diff options
context:
space:
mode:
authorJack Koenig2019-08-19 23:45:07 -0700
committerGitHub2019-08-19 23:45:07 -0700
commitd1a682f47935009215f56664cefae0de26e2eabf (patch)
tree2dac347abf87dcfd0018cb4e42d563c2bd78050d /src/main/scala/firrtl/annotations
parent0f6b9615213a2a9770974ff71b3da3f6b770a772 (diff)
Refactor exceptions to remove stack trace from user errors (#1157)
Diffstat (limited to 'src/main/scala/firrtl/annotations')
-rw-r--r--src/main/scala/firrtl/annotations/AnnotationUtils.scala10
-rw-r--r--src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala3
-rw-r--r--src/main/scala/firrtl/annotations/JsonProtocol.scala7
-rw-r--r--src/main/scala/firrtl/annotations/LoadMemoryAnnotation.scala4
-rw-r--r--src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala4
5 files changed, 13 insertions, 15 deletions
diff --git a/src/main/scala/firrtl/annotations/AnnotationUtils.scala b/src/main/scala/firrtl/annotations/AnnotationUtils.scala
index 241c7a08..9a7a8fd2 100644
--- a/src/main/scala/firrtl/annotations/AnnotationUtils.scala
+++ b/src/main/scala/firrtl/annotations/AnnotationUtils.scala
@@ -11,13 +11,13 @@ import firrtl.annotations.AnnotationYamlProtocol._
import firrtl.ir._
-case class InvalidAnnotationFileException(file: File, cause: Throwable = null)
- extends FIRRTLException(s"$file, see cause below", cause)
-case class InvalidAnnotationJSONException(msg: String) extends FIRRTLException(msg)
-case class AnnotationFileNotFoundException(file: File) extends FIRRTLException(
+case class InvalidAnnotationFileException(file: File, cause: FirrtlUserException = null)
+ extends FirrtlUserException(s"$file", cause)
+case class InvalidAnnotationJSONException(msg: String) extends FirrtlUserException(msg)
+case class AnnotationFileNotFoundException(file: File) extends FirrtlUserException(
s"Annotation file $file not found!"
)
-case class AnnotationClassNotFoundException(className: String) extends FIRRTLException(
+case class AnnotationClassNotFoundException(className: String) extends FirrtlUserException(
s"Annotation class $className not found! Please check spelling and classpath"
)
diff --git a/src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala b/src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala
index e0337d6e..4bb643b3 100644
--- a/src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala
+++ b/src/main/scala/firrtl/annotations/AnnotationYamlProtocol.scala
@@ -31,9 +31,6 @@ object AnnotationYamlProtocol extends DefaultYamlProtocol {
case annotationException: AnnotationException =>
Utils.error(
s"Error: ${annotationException.getMessage} while parsing annotation from yaml\n${yamlValue.prettyPrint}")
- case annotationException: FIRRTLException =>
- Utils.error(
- s"Error: ${annotationException.getMessage} while parsing annotation from yaml\n${yamlValue.prettyPrint}")
}
}
def toTarget(string: String): Named = string.split("""\.""", -1).toSeq match {
diff --git a/src/main/scala/firrtl/annotations/JsonProtocol.scala b/src/main/scala/firrtl/annotations/JsonProtocol.scala
index 5270c26f..b09155d8 100644
--- a/src/main/scala/firrtl/annotations/JsonProtocol.scala
+++ b/src/main/scala/firrtl/annotations/JsonProtocol.scala
@@ -37,7 +37,7 @@ object JsonProtocol {
try {
Class.forName(s).asInstanceOf[Class[_ <: Transform]].newInstance()
} catch {
- case e: java.lang.InstantiationException => throw new FIRRTLException(
+ case e: java.lang.InstantiationException => throw new FirrtlInternalException(
"NoSuchMethodException during construction of serialized Transform. Is your Transform an inner class?", e)
case t: Throwable => throw t
}},
@@ -113,10 +113,11 @@ object JsonProtocol {
// Translate some generic errors to specific ones
case e: java.lang.ClassNotFoundException =>
Failure(new AnnotationClassNotFoundException(e.getMessage))
- case e: org.json4s.ParserUtil.ParseException =>
+ // Eat the stack traces of json4s exceptions
+ case e @ (_: org.json4s.ParserUtil.ParseException | _: org.json4s.MappingException) =>
Failure(new InvalidAnnotationJSONException(e.getMessage))
}.recoverWith { // If the input is a file, wrap in InvalidAnnotationFileException
- case e => in match {
+ case e: FirrtlUserException => in match {
case FileInput(file) =>
Failure(new InvalidAnnotationFileException(file, e))
case _ => Failure(e)
diff --git a/src/main/scala/firrtl/annotations/LoadMemoryAnnotation.scala b/src/main/scala/firrtl/annotations/LoadMemoryAnnotation.scala
index c52bf5f6..64c30bdb 100644
--- a/src/main/scala/firrtl/annotations/LoadMemoryAnnotation.scala
+++ b/src/main/scala/firrtl/annotations/LoadMemoryAnnotation.scala
@@ -4,7 +4,7 @@ package firrtl.annotations
import java.io.File
-import firrtl.FIRRTLException
+import firrtl.FirrtlUserException
/** Representation of the two types of `readmem` statements available in Verilog.
*/
@@ -21,7 +21,7 @@ object MemoryLoadFileType {
def deserialize(s: String): MemoryLoadFileType = s match {
case "h" => MemoryLoadFileType.Hex
case "b" => MemoryLoadFileType.Binary
- case _ => throw new FIRRTLException(s"Unrecognized MemoryLoadFileType: $s")
+ case _ => throw new FirrtlUserException(s"Unrecognized MemoryLoadFileType: $s")
}
}
diff --git a/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala b/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala
index 8f604c9f..f6bab6ea 100644
--- a/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala
+++ b/src/main/scala/firrtl/annotations/transforms/EliminateTargetPaths.scala
@@ -8,7 +8,7 @@ import firrtl.annotations.TargetToken.{Instance, OfModule}
import firrtl.annotations.analysis.DuplicationHelper
import firrtl.annotations._
import firrtl.ir._
-import firrtl.{CircuitForm, CircuitState, FIRRTLException, HighForm, RenameMap, Transform, WDefInstance}
+import firrtl.{CircuitForm, CircuitState, FirrtlInternalException, HighForm, RenameMap, Transform, WDefInstance}
import scala.collection.mutable
@@ -23,7 +23,7 @@ case class ResolvePaths(targets: Seq[CompleteTarget]) extends Annotation {
}
}
-case class NoSuchTargetException(message: String) extends FIRRTLException(message)
+case class NoSuchTargetException(message: String) extends FirrtlInternalException(message)
/** For a set of non-local targets, modify the instance/module hierarchy of the circuit such that
* the paths in each non-local target can be removed