Giter VIP home page Giter VIP logo

Comments (3)

wahern avatar wahern commented on July 17, 2024

Yes, this is an unfortunate early design decision and I'd like to change it eventually. Along with returning (return-value, error-string, error-code) instead of (return-value, error-code).

Every socket has an error handler. The default error handler will throw an error for everything except EPIPE and ETIMEDOUT. The idea was that errors would be thrown, except that EPIPE and ETIMEDOUT weren't errors and would usually be handled inline. This is described in the socket:onerror method documentation, and the introduction section on Errors also has a blurb about it (I should make it more explicit). I now find the current default behavior really quite annoying. The original impetus--keep applications from accidentally ignoring errors--is no longer relevant, because errors are repeated until cleared, and will eventually throw after a user-defined count of unsuccessful operations if the error hadn't been cleared.

You can change the current behavior by changing the default error handler using socket.onerror, which is a method on the prototype singleton. All subsequent sockets will then use that error handler.

from cqueues.

daurnimator avatar daurnimator commented on July 17, 2024

Thanks for the note; I didn't realise that was what socket.onerror was for.

This seems a much more reasonable default (at least to me):

local cqueues_socket = require "cqueues.socket"
local cqueues_errno = require "cqueues.errno"
-- Change default error handler to *not* throw.
cqueues_socket.onerror(function(sock, func, errno, level)
    local msg = cqueues_errno.strerror(errno)
    return msg, errno
end)

from cqueues.

wahern avatar wahern commented on July 17, 2024

On Wed, Oct 22, 2014 at 09:41:30AM -0700, daurnimator wrote:

Thanks for the note; I didn't realise that was what socket.onerror was for.

This seems a much more reasonable default (at least to me):

-- Change default error handler to *not* throw.
cqueues_socket.onerror(function(sock, func, errno, level)
  local msg = cqueues_errno.strerror(errno)
  return msg, errno
end)

I agree it makes more sense. Eventually I want to have a flag day where I
change the default to the above, not just for sockets but for all modules.
But that'll require some planning and a careful refactoring of everything,
including making it easy to get the old behavior, as there's too much code
in production at this point.

FWIW, auxlib.fileresult will convert the existing return values to the more
idiomatic Lua return values.

I've opened two new issues to fix this stuff. You can keep #8 open if you
want.

from cqueues.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.