]> hydra-www.ietfng.org Git - dyna2/commitdiff
Soften exception messages a bit
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Mon, 1 Jul 2013 04:04:43 +0000 (00:04 -0400)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Mon, 1 Jul 2013 04:04:43 +0000 (00:04 -0400)
Some infinitessimal part of github issue #32.

src/Dyna/Main/Driver.hs
src/Dyna/Main/Exception.hs
test/repl/aggregator-conflict.expect

index dddd174f3a0871055a20e3340df6f6fcd52b1128..93f028dc4a102eee6836892e46bf6bf3d8864759 100644 (file)
@@ -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"
index b39cc9879f10c042917ec4ae3b4d521b1cc33097..35687ef4363a36e9d64a40b5c4d14bfe4467222c 100644 (file)
@@ -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
index a57130160ef2df6e5b08116ddcfc14c7580b3b03..3cff8f96725ae49654b5480914e13b97db0406b6 100644 (file)
@@ -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.