Skip to content

lib: emit error when failing to get length#127

Merged
alexindigo merged 1 commit intoform-data:masterfrom
LinusU:patch-1
Aug 16, 2015
Merged

lib: emit error when failing to get length#127
alexindigo merged 1 commit intoform-data:masterfrom
LinusU:patch-1

Conversation

@LinusU
Copy link
Copy Markdown
Contributor

@LinusU LinusU commented Jul 22, 2015

If an error occurs during getLength it will be silently ignored. Instead a new error will be hit a few lines down since length will be undefined. This patch emits the first error instead to give the user a clue as to what went wrong.

@alexindigo
Copy link
Copy Markdown
Member

Thanks for the PR.

Undefined length won't trigger new error, it would keep Content-Length empty. (i'm not saying it good good over there, it does look like not well thought one.) Our idea is to support chunked encoding when there is no length, rather than stop the world. If you can implement something along the that lines, it'd be much better for the library in long term.

And tests would be very nice too.

Thank you.

@LinusU
Copy link
Copy Markdown
Contributor Author

LinusU commented Jul 23, 2015

It will trigger a new error, here are the relevant lines in the Node.js source code: https://github.com/joyent/node/blob/master/lib/_http_outgoing.js#L334-L335

I agree that implementing chunked encoding would be the best, but in the mean time I believe this to be better than the current behaviour. Tests would be good to have, I'll try to find some time to do them.

@alexindigo
Copy link
Copy Markdown
Member

Please add related tests and it will be gtm. Thank you.

@LinusU
Copy link
Copy Markdown
Contributor Author

LinusU commented Aug 1, 2015

@alexindigo Done 👍

@LinusU
Copy link
Copy Markdown
Contributor Author

LinusU commented Aug 14, 2015

@alexindigo ping, using this in production and would love a new release with this added 🚀

@alexindigo
Copy link
Copy Markdown
Member

Oh hey, sorry for the delays.

Yes, I wanted to chat with you about it, if you don't mind.
Can you enlighten me about your test, looks like it would do without http server,
or did I miss anything?

Thank you.

@alexindigo
Copy link
Copy Markdown
Member

It will go out with 1.0.0-rc4. Thanks.

@LinusU
Copy link
Copy Markdown
Contributor Author

LinusU commented Aug 14, 2015

Absolutely, no problem.

I used the http server since the problem, and the updated code, lies in the submit function. Since that function always creates a request (either with http or https) I think it's necessary to start a server.

@alexindigo
Copy link
Copy Markdown
Member

Funny thing :) Your test passing without your modifications to the form-data.js :)

@LinusU
Copy link
Copy Markdown
Contributor Author

LinusU commented Aug 15, 2015

You are very right, turns out that I thought that I faked an fs.ReadStream pretty good when I did in fact not. It has fd and path properties as well.

I've updated the test to actually use fs.createReadStream with a path that shouldn't exist.

@alexindigo
Copy link
Copy Markdown
Member

Cool. Thanks. If you could fix couple minor style issues, just to make it look uniform with rest of the code, we will be good to go. I'm taking about spaces between function and parenthesis.

Thanks a lot for pushing it through.

If an error occurs during `getLength` it will be silently ignored. Instead a new error will be hit a few lines down since `length` will be `undefined`. This patch emits the first error instead to give the user a clue as to what went wrong.
@LinusU
Copy link
Copy Markdown
Contributor Author

LinusU commented Aug 16, 2015

I hope that this is what you meant. It would be cool to use some styling standard specification, like feross/standard so that the coding style can be checked automatically when running npm test.

   form.append('fake-stream', src);

-  form.on('error', function (err) {
+  form.on('error', function(err) {
     assert.equal(err.code, 'ENOENT');
     assert.equal(err.path, path);
-    req.on('error', function () {});
+    req.on('error', function() {});
     server.close();
   });

-  server.listen(common.port, function () {
+  server.listen(common.port, function() {
     req = form.submit(addr);
   });
 })();

@alexindigo
Copy link
Copy Markdown
Member

Yep, looks great. Thanks.
And for auto checks, we're getting there. :)
Thank thing was created by Old Gods in the prehistoric times, you probably noticed Makefile in the repo ;)

alexindigo added a commit that referenced this pull request Aug 16, 2015
lib: emit error when failing to get length
@alexindigo alexindigo merged commit 7837f7e into form-data:master Aug 16, 2015
@LinusU LinusU deleted the patch-1 branch August 16, 2015 14:59
@LinusU
Copy link
Copy Markdown
Contributor Author

LinusU commented Aug 16, 2015

Hehe, sounds good :)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants