[Hackage] #510: Don't call exitWith on parse error, instead return error or throw exception

Hackage trac at galois.com
Fri Feb 27 10:46:55 EST 2009


#510: Don't call exitWith on parse error, instead return error or throw exception
----------------------------+-----------------------------------------------
  Reporter:  guest          |        Owner:         
      Type:  enhancement    |       Status:  closed 
  Priority:  normal         |    Milestone:         
 Component:  Cabal library  |      Version:  1.6.0.1
  Severity:  minor          |   Resolution:  invalid
  Keywords:                 |   Difficulty:  unknown
Ghcversion:                 |     Platform:         
----------------------------+-----------------------------------------------
Changes (by duncan):

  * status:  new => closed
  * resolution:  => invalid

Comment:

 If you want to handle the parse errors you can use:
 {{{
 parsePackageDescription :: String -> ParseResult GenericPackageDescription
 }}}
 The `ParseResult` gives you everything about the parsing outcome. It
 includes a structured description of any parse error or warnings. There
 are functions provided to format these errors and warnings into strings if
 you don't want to handle them individually.

 By contrast, `readPackageDescription` is an "all in one" convenience
 function that works in IO, reads the file and throws exceptions in IO if
 reading the file or parsing it fails.
 {{{
 readPackageDescription :: Verbosity -> FilePath -> IO
 GenericPackageDescription
 }}}

 Admitedly, it does use the wrong exception if parsing fails, it uses the
 `ExitWith` exception where it should use `UserError`. It is still
 catchable however. But you clearly don't want to be using exceptions here,
 you want to use the pure function `parsePackageDescription` that gives you
 the chance to handle parse errors yourself.

 I'm closing this ticket but opening a new one about the issue with `die`
 throwing the wrong kind of exception.

-- 
Ticket URL: <http://hackage.haskell.org/trac/hackage/ticket/510#comment:2>
Hackage <http://haskell.org/cabal/>
Hackage: Cabal and related projects


More information about the cabal-devel mailing list