summaryrefslogtreecommitdiff
path: root/compiler/utils
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/utils')
-rw-r--r--compiler/utils/Panic.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/utils/Panic.hs b/compiler/utils/Panic.hs
index ebf830385c..03f095b1a0 100644
--- a/compiler/utils/Panic.hs
+++ b/compiler/utils/Panic.hs
@@ -20,6 +20,8 @@ module Panic (
panic, sorry, assertPanic, trace,
panicDoc, sorryDoc, pgmErrorDoc,
+ cmdLineError, cmdLineErrorIO,
+
Exception.Exception(..), showException, safeShowException,
try, tryMost, throwTo,
@@ -195,6 +197,17 @@ panicDoc x doc = throwGhcException (PprPanic x doc)
sorryDoc x doc = throwGhcException (PprSorry x doc)
pgmErrorDoc x doc = throwGhcException (PprProgramError x doc)
+cmdLineError :: String -> a
+cmdLineError = unsafeDupablePerformIO . cmdLineErrorIO
+
+cmdLineErrorIO :: String -> IO a
+cmdLineErrorIO x = do
+ stack <- ccsToStrings =<< getCurrentCCS x
+ if null stack
+ then throwGhcException (CmdLineError x)
+ else throwGhcException (CmdLineError (x ++ '\n' : renderStack stack))
+
+
-- | Throw a failed assertion exception for a given filename and line number.
assertPanic :: String -> Int -> a