[GHC] #7962: "ghc -e <invalid expression>" should return non-zero exit status

#7962: "ghc -e <invalid expression>" should return non-zero exit status ----------------------------+----------------------------------------------- Reporter: timmaxw | Owner: Type: feature request | Status: new Priority: normal | Component: GHCi Version: 7.6.2 | Keywords: Os: Linux | Architecture: Unknown/Multiple Failure: Other | Blockedby: Blocking: | Related: ----------------------------+----------------------------------------------- When GHC is run in expression-evaluation mode (i.e. with the "-e" flag) and the expression does not compile, GHC correctly prints an error message, but then exits with exit status 0. For example: {{{ $ ghc -e foo <interactive>:1:1: Not in scope: `foo' $ echo $? 0 }}} This is inconvenient for automated scripts that call GHC. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7962 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7962: "ghc -e <invalid expression>" should return non-zero exit status ----------------------------+----------------------------------------------- Reporter: timmaxw | Owner: Type: feature request | Status: new Priority: normal | Component: GHCi Version: 7.6.2 | Keywords: Os: Linux | Architecture: Unknown/Multiple Failure: Other | Blockedby: Blocking: | Related: ----------------------------+----------------------------------------------- Comment(by Fuuzetsu): GHC does what it was expected to do successfully. If it was to throw a non-zero code, it would indicate that there's something wrong with our usage of GHC or that it had some kind of other issue (and in fact we get ‘1’ when we try to compile a non-existent file). GHC -e executes successfully and therefore exits with 0. It couldn't really care less about what happens during the session. For scripting, you probably want to write a Haskell program that does what you want and if it fails, throw whatever error code you want. It just isn't GHCs place to decide what it considers successful inside the session. Just my 2 cents. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7962#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7962: "ghc -e <invalid expression>" should return non-zero exit status ----------------------------+----------------------------------------------- Reporter: timmaxw | Owner: Type: feature request | Status: new Priority: normal | Component: GHCi Version: 7.6.2 | Keywords: Os: Linux | Architecture: Unknown/Multiple Failure: Other | Blockedby: Blocking: | Related: ----------------------------+----------------------------------------------- Comment(by carter): Alternatively: does using runghc have the expected behavior? -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7962#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7962: "ghc -e <invalid expression>" should return non-zero exit status ----------------------------+----------------------------------------------- Reporter: timmaxw | Owner: Type: feature request | Status: new Priority: normal | Component: GHCi Version: 7.6.2 | Keywords: Os: Linux | Architecture: Unknown/Multiple Failure: Other | Blockedby: Blocking: | Related: ----------------------------+----------------------------------------------- Changes (by timmaxw): * cc: timmaxw@… (added) Comment: GHC exits with status 1 if it encounters errors when compiling: {{{ $ cat >Test.hs askfljawioefjaiwojfeoawfe $ ghc Test.hs [1 of 1] Compiling Main ( Test.hs, Test.o ) Test.hs:1:1: Parse error: naked expression at top level $ echo $? 1 }}} It also exits with status 1 if the expression passed to "ghc -e" evaluates to bottom: {{{ $ ghc -e "head []" <interactive>: Prelude.head: empty list $ echo $? 1 }}} It seems odd that GHC would return 1 in both of those cases, but return 0 for "ghc -e <invalid expression>". Either the return value in one or both of those cases should be changed to 0, or the return value for "ghc -e <invalid expression>" should be changed to 1. "runghc" behaves like a call to "ghc -e main <some file>". If there is an error in the expression "main" (i.e. if "main" is not in scope) it returns 0: {{{ $ cat >Test2.hs foo = 1 $ runghc Test2.hs Test2.hs:1:33: Not in scope: `main' Perhaps you meant `min' (imported from Prelude) $ echo $? 0 }}} But if there is an error in the text of the program itself, or if the program throws an exception when "main" is run, then it returns 1. -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7962#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC