aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/FirrtlException.scala
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/FirrtlException.scala
parent0f6b9615213a2a9770974ff71b3da3f6b770a772 (diff)
Refactor exceptions to remove stack trace from user errors (#1157)
Diffstat (limited to 'src/main/scala/firrtl/FirrtlException.scala')
-rw-r--r--src/main/scala/firrtl/FirrtlException.scala43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/FirrtlException.scala b/src/main/scala/firrtl/FirrtlException.scala
new file mode 100644
index 00000000..20d984a1
--- /dev/null
+++ b/src/main/scala/firrtl/FirrtlException.scala
@@ -0,0 +1,43 @@
+// See LICENSE for license details.
+
+package firrtl
+
+import scala.util.control.NoStackTrace
+
+@deprecated("External users should use either FirrtlUserException or their own hierarchy", "1.2")
+object FIRRTLException {
+ def defaultMessage(message: String, cause: Throwable) = {
+ if (message != null) {
+ message
+ } else if (cause != null) {
+ cause.toString
+ } else {
+ null
+ }
+ }
+}
+@deprecated("External users should use either FirrtlUserException or their own hierarchy", "1.2")
+class FIRRTLException(val str: String, cause: Throwable = null)
+ extends RuntimeException(FIRRTLException.defaultMessage(str, cause), cause)
+
+/** Exception indicating user error
+ *
+ * These exceptions indicate a problem due to bad input and thus do not include a stack trace.
+ * This can be extended by custom transform writers.
+ */
+class FirrtlUserException(message: String, cause: Throwable = null)
+ extends RuntimeException(message, cause) with NoStackTrace
+
+/** Wraps exceptions from CustomTransforms so they can be reported appropriately */
+case class CustomTransformException(cause: Throwable) extends Exception("", cause)
+
+/** Exception indicating something went wrong *within* Firrtl itself
+ *
+ * These exceptions indicate a problem inside the compiler and include a stack trace to help
+ * developers debug the issue.
+ *
+ * This class is private because these are issues within Firrtl itself. Exceptions thrown in custom
+ * transforms are treated differently and should thus have their own structure
+ */
+private[firrtl] class FirrtlInternalException(message: String, cause: Throwable = null)
+ extends Exception(message, cause)