Commit 47564389 authored by archblob's avatar archblob Committed by Austin Seipp
Browse files

Catch canonicalizePath exceptions, fix #10101

Summary:
Introduce by #95 'canonicalizePath' throws and exception when given
an invalid file in a call to 'sameFile'.

There are two cases when this can happen when using ghci:
  1) If there is an error at the interactive prompt, "<interactive>"
     file is searched for and not found.
  2) If there is an error in any loaded file and editing an inexistent/new
     file with 'e: foo'.

Both cases are now tested.

Test Plan: validate

Reviewers: austin, #ghc

Reviewed By: austin, #ghc

Subscribers: bgamari, thomie

Differential Revision: https://phabricator.haskell.org/D930

GHC Trac Issues: #10101
parent 94fff179
......@@ -1245,6 +1245,9 @@ editFile str =
when (null cmd)
$ throwGhcException (CmdLineError "editor not set, use :set editor")
lineOpt <- liftIO $ do
let sameFile p1 p2 = liftA2 (==) (canonicalizePath p1) (canonicalizePath p2)
`catchIO` (\_ -> return False)
curFileErrs <- filterM (\(f, _) -> unpackFS f `sameFile` file) errs
return $ case curFileErrs of
(_, line):_ -> " +" ++ show line
......@@ -3222,12 +3225,6 @@ expandPathIO p =
other ->
return other
sameFile :: FilePath -> FilePath -> IO Bool
sameFile path1 path2 = do
absPath1 <- canonicalizePath path1
absPath2 <- canonicalizePath path2
return $ absPath1 == absPath2
wantInterpretedModule :: GHC.GhcMonad m => String -> m Module
wantInterpretedModule str = wantInterpretedModuleName (GHC.mkModuleName str)
......
......@@ -6,3 +6,7 @@
:e ./Bad.hs
:l Good.hs
:e
+
:e foo
:l Bad.hs
:e bar
Bad.hs:3:8:
Bad.hs:3:8: error:
lexical error in string/character literal at character '\n'
Bad.hs:3:8:
Bad.hs:3:8: error:
lexical error in string/character literal at character '\n'
Bad.hs:3:8:
Bad.hs:3:8: error:
lexical error in string/character literal at character '\n'
<interactive>:10:1: error: parse error on input ‘+’
Bad.hs:3:8: error:
lexical error in string/character literal at character '\n'
Bad.hs:3:8: error:
lexical error in string/character literal at character '\n'
......@@ -2,3 +2,5 @@ Good.hs
Bad.hs +3
./Bad.hs +3
Good.hs
foo
bar
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment