Comments (8)
I didn't even realise that it would capture user thrown errors. Not sure if can be seen as a bug or as a feature, as I can that this can be useful but also really annoying.
I'm just going to label this as a bug
for now. The quickest fix would be to force parsing to be async using a process.nextTick/setimmediate/setTimeout
Note: We could use https://github.com/NobleJS/setImmediate for this.
from primus.
Yeah, emitting data
on the next tick does the trick.
from primus.
Good to know that it's working, but not sure if that would be the optimal solution for this. I think it makes more sense to update the parsers https://github.com/3rd-Eden/primus/blob/master/parsers/json.js#L11 so they call the fn
callback after the try / catch
statement. This would also increase performance as V8 won't be de-optimising transformation handling.
from primus.
Ohhhhh I see now... Good call, I'll go ahead and fix them that way. I don't really see the need to make the fn
call async in this case now though. This what your thinking?
exports.decoder = function decoder(data, fn) {
try { data = JSON.parse(data); }
catch (e) { return fn(e); }
fn(undefined, data);
}
Though, I guess you could also drop fn
from the catch statement too... Need to test it, unless you know off the top of your head.
exports.decoder = function decoder(data, fn) {
var err = undefined;
try { data = JSON.parse(data); }
catch (e) { err = e; }
fn(err || undefined, data);
};
from primus.
Yes, your first example was exactly what I was thinking. The second example would also work and can be written cleaner as well:
exports.decoder = function decoder(data, fn) {
var err; // err is always undef when not nothing is assigned to it.
try { data = JSON.parse(data); }
catch (e) { err = e; }
fn(err, data);
};
from primus.
Ah with this fix, it shows an actual failed test when using binary-pack. When checking for \u2028
and \u2029
in https://github.com/3rd-Eden/primus/blob/master/spark.js#L206, currently it always assumes strings and uses packet.indexOf
.
Want to just ignore anything that's not a string? Seems silly to cast the buffer right back to a string... Meh?
from primus.
@gjohnson whoops, yes I think a simple typeof
check would be sufficient to fix that.
from primus.
Closing this. It was fixed in #43
from primus.
Related Issues (20)
- Missing dependencies for parser: "json" HOT 1
- Primus->diagnostics->storage-engine forces --unsafe-perm in global install HOT 4
- update documentation to be more explicit around createSocket
- Problem using proxy with primus client side
- Nativescript support HOT 1
- Does the primus web client work with a non-primus websocket server? HOT 4
- How can I know if a connection has been upgraded or not? HOT 4
- import primus client in client JS
- Getting response headers while polling HOT 3
- public connections and connected HOT 1
- Consider to rewrite without prototype pollution? HOT 11
- Primus with Koa and websockets transport HOT 3
- Can you please consider changing "Primus, the creator god of transformers" HOT 3
- primus doesn't accept custom path with engine.io HOT 10
- async plugins support HOT 8
- support of the new uwebsocket version
- Allow Primus instance to select version of transformer/engine library
- Server Side Events (SSE) source HOT 7
- Maximum Concurrent Connection on Primus Server HOT 2
- Consider alternative to deprecated navigator.userAgent getter. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from primus.