diff options
author | Kavon Farvardin <kavon@farvard.in> | 2018-09-23 15:29:37 -0500 |
---|---|---|
committer | Kavon Farvardin <kavon@farvard.in> | 2018-09-23 15:29:37 -0500 |
commit | 84c2ad99582391005b5e873198b15e9e9eb4f78d (patch) | |
tree | caa8c2f2ec7e97fbb4977263c6817c9af5025cf4 /compiler/utils/Panic.hs | |
parent | 8ddb47cfcf5776e9a3c55fd37947c8a95e00fa12 (diff) | |
parent | e68b439fe5de61b9a2ca51af472185c62ccb8b46 (diff) | |
download | haskell-wip/T13904.tar.gz |
update to current master againwip/T13904
Diffstat (limited to 'compiler/utils/Panic.hs')
-rw-r--r-- | compiler/utils/Panic.hs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/compiler/utils/Panic.hs b/compiler/utils/Panic.hs index 0a21f251fb..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, @@ -27,6 +29,8 @@ module Panic ( ) where #include "HsVersions.h" +import GhcPrelude + import {-# SOURCE #-} Outputable (SDoc, showSDocUnsafe) import Config @@ -193,8 +197,19 @@ 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 an failed assertion exception for a given filename and line number. +-- | Throw a failed assertion exception for a given filename and line number. assertPanic :: String -> Int -> a assertPanic file line = Exception.throw (Exception.AssertionFailed |