PageRenderTime 52ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/src/lua_lanes/tests/error.lua

https://bitbucket.org/xixs/spew
Lua | 48 lines | 26 code | 10 blank | 12 comment | 1 complexity | 6b1fc461121dea22421b31efea5ed4ef MD5 | raw file
  1. --
  2. -- Error reporting
  3. --
  4. -- Note: this code is supposed to end in errors; not included in 'make test'
  5. --
  6. local lanes = require "lanes"
  7. lanes.configure( 1)
  8. local function lane()
  9. local subf= function() -- this so that we can see the call stack
  10. error "aa"
  11. --error({})
  12. --error(error)
  13. end
  14. local subf2= function()
  15. subf()
  16. end
  17. subf2()
  18. end
  19. local function cleanup(err)
  20. end
  21. local lgen = lanes.gen("*", { --[[finalizer=cleanup]] }, lane)
  22. ---
  23. io.stderr:write( "\n** Error catching **\n" )
  24. --
  25. local h= lgen()
  26. local _,err,stack= h:join() -- wait for the lane (no automatic error propagation)
  27. if err then
  28. assert( type(stack)=="table" )
  29. io.stderr:write( "Lane error: "..tostring(err).."\n" )
  30. io.stderr:write( "\t", table.concat(stack,"\n\t"), "\n" );
  31. end
  32. ---
  33. io.stderr:write( "\n** Error propagation **\n" )
  34. --
  35. local h2= lgen()
  36. local _= h2[0]
  37. assert(false) -- does NOT get here
  38. --never ends