Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#9943 closed task (duplicate)

Replace "error" with "errorWithStackTrace" from GHC.Stack in base libs

Reported by: spacekitteh Owned by:
Priority: normal Milestone: 8.0.1
Component: Core Libraries Version:
Keywords: Cc: core-libraries-committee@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #5273 Differential Rev(s):
Wiki Page:


It is basically the same as the standard error function but outputs a stack trace if one is available.

Change History (8)

comment:1 Changed 5 years ago by spacekitteh


comment:2 Changed 5 years ago by hvr

Btw, it's not as simple as just set error = errorWithStackTrace; there needs to be a way to recover the string passed to error w/o the additional stack-trace from the ErrorCall exception value (which currently provides the originally passed error-message as its payload).

-- |This is thrown when the user calls 'error'. The @String@ is the
-- argument given to 'error'.
newtype ErrorCall = ErrorCall String
    deriving (Eq, Ord, Typeable)

instance Exception ErrorCall

instance Show ErrorCall where
    showsPrec _ (ErrorCall err) = showString err

See also this short conversation for some ideas:

hvr> carter: btw, was my concern regarding modifying the payload of the ErrorCall exception ever addressed?
carter> nopeee! :)
carter> maybe we expose a pattern synonym as the constructor name
carter> and have the real constructor have an extra field for the trace?
hvr> could work
carter> so show will still render the full mess
carter> but everyone's old code wont break
carter> because unless youre explicity catching it
carter> it ends up just being showed right?
carter> error "fix me"
carter> hvr: pattern synonyms dont need to be eneabled in the use sites right?
carter> hvr: err, the only reason for that change would be backwards compat right?
hvr> carter: well, actually it's a nice property to be able to recover the exact string you pass to 'error'
carter> hvr: i wasn't arguing against it :)
hvr> carter: regardless of backward compat
carter> ok
carter> so breaking change to make it have two args?
carter> or hide it with patternsyn?
carter> or wait a year and try again?
hvr> carter: you've got one year to figure out the perfect way :)
carter> fineeeee
carter> solution: break everything
hvr> carter: otoh, maybe by then we may have some other facility which makes this redundant

comment:3 Changed 5 years ago by spacekitteh

Milestone: 7.12.1
Resolution: invalid
Status: newclosed

comment:4 Changed 5 years ago by spacekitteh

Closed ticket in light of this thread, which subsumes this.

comment:5 Changed 5 years ago by carter

Owner: spacekitteh deleted
Resolution: invalid
Status: closednew

this ticket is still valid for tracking this.

comment:6 Changed 5 years ago by carter

Chris and I spent some time working on this, its actually pretty tricky to implement even a nominally simple patch for this because you quickly run into navigating figuring out where to write the boot file for cutting a recursive module loop

comment:7 Changed 4 years ago by thomie

Milestone: 7.12.1
Resolution: duplicate
Status: newclosed

This program:

import Control.Exception

main = do Left (ex@(ErrorCallWithLocation a b)) <- try $ print (head [] :: ())
          putStrLn a
          putStrLn b
          throwIO ex

Now prints:

Prelude.head: empty list
  error, called at libraries/base/GHC/List.hs:1009:3 in base:GHC.List
Test: Prelude.head: empty list

I'm not sure why the custom exception handler is needed. Perhaps that will be cleared up later.

I think this ticket can be closed.

comment:8 Changed 4 years ago by thoughtpolice


Milestone renamed

Note: See TracTickets for help on using tickets.