From: Nathaniel Wesley Filardo Date: Mon, 1 Jul 2013 04:04:43 +0000 (-0400) Subject: Soften exception messages a bit X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=672e880292041352f1ff9bace06cef488605ff04;p=dyna2 Soften exception messages a bit Some infinitessimal part of github issue #32. --- diff --git a/src/Dyna/Main/Driver.hs b/src/Dyna/Main/Driver.hs index dddd174..93f028d 100644 --- a/src/Dyna/Main/Driver.hs +++ b/src/Dyna/Main/Driver.hs @@ -387,10 +387,13 @@ processFile fileName = bracket openOut hClose go tus = nHide $ IUniv UShared tf = nHide IFree - cqPlans = map (\(fa,r,e) -> (fa,r,check e)) qPlans + cqPlans = map check qPlans where - check (Right p) = p - check (Left _) = dynacPanic $ "Backchaining planner failed" + check (f,r,Right p) = (f,r,p) + check (_,r,Left _) = dynacUserErr $ + "Unable to plan backchaining for rule" + (prettySpanLoc (r_span r)) + <> dot in do -- Do this before forcing cInitializers, cuPlans, etc., @@ -440,7 +443,7 @@ processFile fileName = bracket openOut hClose go parse aggs = do pr <- T.parseFromFileEx (P.oneshotDynaParser aggs <* T.eof) fileName case pr of - TR.Failure td -> dynacUserANSIErr $ PPA.align ("Parser error" PPA.<$> td) + TR.Failure td -> dynacParseErr $ PPA.align td TR.Success rs -> return rs @@ -464,10 +467,10 @@ main = catches (getArgs >>= main_) printerr x = pe x >> exitFailure pe (UserProgramError d) = do - PP.hPutDoc stderr (upeMsg <> line <> PP.indent 1 d) + PP.hPutDoc stderr (upeMsg <> line <> PP.indent 1 d upePostfix) hPutStrLn stderr "" - pe (UserProgramANSIError d) = do - PPA.hPutDoc stderr (upeMsg <> PPA.line <> PPA.indent 1 d) + pe (UserProgramParseError d) = do + PPA.hPutDoc stderr (parseMsg <> PPA.line <> PPA.indent 1 d) hPutStrLn stderr "" pe (InvocationError d) = do PP.hPutDoc stderr ("Invocation error:" <> line <> PP.indent 1 d) @@ -489,7 +492,13 @@ main = catches (getArgs >>= main_) hPutStrLn stderr "" upeMsg :: (IsString s) => s - upeMsg = "FATAL: Encountered error in input program:" + upeMsg = "Encountered error in input program:" + + upePostfix :: Doc e + upePostfix = "Everything was syntactically valid, but we could not" + "see it through." + + parseMsg = "Could not parse:" sorryMsg :: (IsString s) => s sorryMsg = "Terribly sorry, but you've hit an unsupported feature" diff --git a/src/Dyna/Main/Exception.hs b/src/Dyna/Main/Exception.hs index b39cc98..35687ef 100644 --- a/src/Dyna/Main/Exception.hs +++ b/src/Dyna/Main/Exception.hs @@ -24,8 +24,8 @@ data DynacException = -- | The user program contains an error UserProgramError (PP.Doc TP.Effect) - -- | Same as 'UserProgramError' but with ANSI documentation - | UserProgramANSIError PPA.Doc + -- | Parser errors get their own branch for convenience of printout + | UserProgramParseError PPA.Doc -- | Something went wrong when trying to understand arguments | InvocationError (PP.Doc TP.Effect) @@ -55,8 +55,8 @@ dynacPanicStr = throw . Panic . PP.text -- | Throw an ANSI error; this is used inside the parser, primarily, due to -- trifecta's movement to the ANSI prettyprinter. -dynacUserANSIErr :: PPA.Doc -> a -dynacUserANSIErr = throw . UserProgramANSIError +dynacParseErr :: PPA.Doc -> a +dynacParseErr = throw . UserProgramParseError -- | A type-restricted version of 'throw' dynacThrow :: DynacException -> a diff --git a/test/repl/aggregator-conflict.expect b/test/repl/aggregator-conflict.expect index a571301..3cff8f9 100644 --- a/test/repl/aggregator-conflict.expect +++ b/test/repl/aggregator-conflict.expect @@ -1,9 +1,11 @@ :- :- ============= a := 1 :- DynaCompilerError: -FATAL: Encountered error in input program: - Conflicting aggregators; rule /home/timv/.dyna/tmp/966093dc38b755a6f17b02774b5c656931163a3a.dyna:5:1-/home/timv/.dyna/tmp/966093dc38b755a6f17b02774b5c656931163a3a.dyna:5:3 +Encountered error in input program: + Conflicting aggregators; rule /home/timv/.dyna/tmp/31141/966093dc38b755a6f17b02774b5c656931163a3a.dyna:5:1-/home/timv/.dyna/tmp/31141/966093dc38b755a6f17b02774b5c656931163a3a.dyna:5:3 uses '|=' for a/0 but I had been lead to expect '+='. +Everything was syntactically valid, but we could not +see it through. > new rule(s) were not added to program.