Skip to content

Runtime errors are not reported in chained promises #4

Description

@joagre

If I make a programming error in the first promise (in a promise chain) I get an expected runtime error but if I make a programming error in the second promise I get no runtime error.

I slightly modifed your chained promises example to verify this:

local deferred = require "lib.deferred"

function readasync(filename, cb)
  if filename == 'first.txt' then
    call_missing_function()
    cb("content1", nil)
  else
    --call_missing_function()
    cb("content2", nil)
  end
end

function read(filename)
  local d = deferred.new()
  readasync(filename, function(contents, err)
    if err == nil then
      d:resolve(contents)
    else
      d:reject(err)
    end
  end)
  return d
end

read('first.txt'):next(function(s)
  print('First file:', s)
  return read('second.txt')
end):next(function(s)
  print('Second file:', s)
end):next(nil, function(err)
  -- error while reading first or second file
  print('Error:', err)
end)

When I run the above I get an expected runtime error:

nov. 02 06:38:45.241 ERROR: Runtime error
  /Users/jocke/src/blackmode/trunk/app/ui2/main.lua:5: attempt to call global 'call_missing_function' (a nil value)
  stack traceback:
  /Users/jocke/src/blackmode/trunk/app/ui2/main.lua:5: in function 'readasync'
  /Users/jocke/src/blackmode/trunk/app/ui2/main.lua:15: in function 'read'
  /Users/jocke/src/blackmode/trunk/app/ui2/main.lua:25: in main chunk

If I change the readsync function above to this:

function readasync(filename, cb)
  if filename == 'first.txt' then
    --call_missing_function()
    cb("content1", nil)
  else
    call_missing_function()
    cb("content2", nil)
  end
end

Then I just get the custom error message and no run-time error:

Error:	/Users/jocke/src/blackmode/trunk/app/ui2/main.lua:8: attempt to call global 'call_missing_function' (a nil value)

I this to be expected?

Kind regards

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions