Giter Site home page Giter Site logo

stream error about error HOT 8 OPEN

koajs avatar koajs commented on April 28, 2024
stream error

from error.

Comments (8)

jonathanong avatar jonathanong commented on April 28, 2024

thought about creating a util to yield until the first readable or error event, but i'm not sure if it's worth it

from error.

dead-horse avatar dead-horse commented on April 28, 2024

seems we treat these tow kind of errors in different way

from error.

tj avatar tj commented on April 28, 2024

yeah definitely sucks :( I have mixed feelings about adding a root level error handler, it's sort of necessary in this case but then it deviates from the norm, and the fact that you can have multiple error handlers that propagate. streams just don't fit the model really, which is why rails also bypasses middleware when streaming

from error.

dead-horse avatar dead-horse commented on April 28, 2024

i try to hacked ctx.onerror in koa-onerror, i can not found another way to deal with all errors in one place. but it is really lame.

should we make ctx.onerror more customizable (e.g. add app.errorHandler= called by ctx.onerror), or just let other middlewares to do this lame thing?

from error.

tj avatar tj commented on April 28, 2024

I don't want to form too many opinions based on the current stream implementation since they're super broken. We have a few choices for future stuff I guess, people can stream in the middleware itself, errors would propagate like normal, but it bypasses upstream middleware since you're doing all of the read/write operations in the middleware itself. Or like now with most just assign .body to a stream and let koa do its thing, which then fucks up error handling haha. Both cases kind of suck for different reasons but the latter is probably the most common. I guess what we sort of really need is the ability to prepend middleware, conceptually I don't like that but we have a few other cases for it as well

from error.

jonathanong avatar jonathanong commented on April 28, 2024

i was thinking of doing something like this in either the respond middleware or a error handler. @dead-horse maybe you want to play with this idea?

var stream = this.body
if (stream.pipe) {
  yield function (_done) {
    stream.read(0)
    stream.on('readable', done)
    stream.on('error', done)
    function done(err) {
      stream.removeListener('readable', done)
      stream.removeListener('error', done)
      _done(err)
    }
  }
}

it just makes sure the first event isn't an error, which would happen with fs streams and stuff. maybe listen to the close event as well - dunno.

only think i can think of is that doing .read(0) would end empty streams, which i consider a stream bug.

from error.

dead-horse avatar dead-horse commented on April 28, 2024

i want to make sure all errors can caught by my own, so i can decide how to display it. but stream sucks . :(
fortunately in most usage scenarios, streams not necessary. who really want to use it, must understand its disgusting place. maybe we just point this out to let users know haha

from error.

jonathanong avatar jonathanong commented on April 28, 2024

streams not necessary. who really want to use it, must understand its disgusting place.

amen!

from error.

Related Issues (12)

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.