MFlow  Create and maintain dynamic Web applications as easy and fast as console applications
Thou shall not write request handlers
 This release: 11/06/2014. (@agocorona) <>< . issues & bugs .  Mflow Source code,     source code of this site

Automatic error trace generation in MFlow

To have  the trace of an unexpected error is very important in Web development. Specially when the error has been produced in the exploitation environment. There is no way to make tests in a exploitation environment, so the error message is the only information available to fix it as soon as possible. 

Now MFlow permits the creation of execution traces. Not just call traces, but execution traces, whenever an error happens. It uses the package monadloc from Pepe Iborra, used to produce stack traces in his package control-monad-exception.  

Using MonadLoc, MFlow can produce entire traces instead of call stacks because his backtracking mechanism permits to  run back the execution up to the beginning in case of an exception following the exact execution steps in reverse order. In this back-execution is when the trace is generated. When running normally, the tracing machinery does not affect the performance.

This is an example of what it is necessary in order to have execution traces in case of error.  It is necessary to install the monadloc-pp and monadloc packages that install the monadloc preprocessor and the monadloc class respectively. There are two according changes in the user programs, the preprocessor directive and to include  the Control.Monad.Loc module.

EDIT:  The persistent flows have no MonadLoc instance, but since the persistent flows have forward logs, it is possible to trace the execution. Once an error is produced in a persistent flow, its log is moved to the error subdirectory within the .tcachedata folder.  Since a flow can have persistent and non persistent sections (depending where they use the step statement)  In the future, both logging mechanisms will be integrated in the same error message.

Running example

(in the light red box):

Error trace example

MFlow now produces execution traces in case of error by making use of the backtracking mechanism

It is more detailed than a call stack

this example has a deliberate error

You must be logged as admin to see the trace

pres here

Source code:

{-# OPTIONS -F -pgmF MonadLoc #-}
module TraceSample ( traceSample) where

import MFlow.Wai.Blaze.Html.All hiding (page)
import Control.Monad.Loc

import Menu
-- to run it alone, remove import menu and uncomment the following line
--main= runNavigation "" $ transientNav traceSample

traceSample= do
  page $  h2 << "Error trace example"
       ++> p << "MFlow now produces execution traces in case of error by making use of the backtracking mechanism"
       ++> p << "It is more detailed than a call stack"
       ++> p << "this example has a deliberate error"
       ++> br
       ++> p << "You must be logged as admin to see the trace"
       ++> wlink () << p << "pres here"

  page $   p <<  "Please login with admin/admin"
        ++> userWidget (Just "admin") userLogin

  u <- getCurrentUser
  page $   p << "The trace will appear after you press the link. press one of the options available at the bottom of the pagem"
        ++> p << ("user="++ u) ++> br
        ++> wlink () << "press here"
  page $   error $ "this is the error"

comments powered by Disqus