Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: Replace an Error with a deprecation message. #1982

Closed
wants to merge 1 commit into from

Conversation

ChALkeR
Copy link
Member

@ChALkeR ChALkeR commented Jun 15, 2015

This fixes a breaking change in commit 353e26e, that was included in a minor version of io.js and broke at least two modules (that were misusing fs.createWriteStream method, but still).

Disclaimer: I am not sure if this is worth fixing, but if it is, this should work.

The two modules I mentioned above were passing a function to fs.createWriteStream, and that was never supported (it was always ignored). In 2.3.0 a more strict options validation was introduced, it started throwing an Error, and that two modules (at least) broke.

@ChALkeR
Copy link
Member Author

ChALkeR commented Jun 15, 2015

Fixes: #1981

@mscdex mscdex added the fs Issues and PRs related to the fs subsystem / file system. label Jun 15, 2015
@ChALkeR
Copy link
Member Author

ChALkeR commented Jun 15, 2015

Ah, wait a moment. It still doesn't fix this, needs an extra change.

@ChALkeR
Copy link
Member Author

ChALkeR commented Jun 15, 2015

Ok, should be fixed now (for WriteStream).

Though I am not sure if ReadStream needed any changes at all, because it was calling Object.create before, and that should fail if the passed argument is not an object or null.

throw new TypeError('options must be a string or an object');
else if (options === null || typeof options !== 'object') {
//throw new TypeError('options must be a string or an object');
internalUtil.printDeprecationMessage('Passing anything but an object or \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message will be printed whenever this situation arises. Is that the intention here? Normally, it is used like this

var warned = false;
...
    warned = internalUtil.printDeprecationMessage('...', warned);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed.

@ChALkeR ChALkeR force-pushed the fs-stream-fix branch 2 times, most recently from 950029e to ee895ff Compare June 15, 2015 14:20
warnedWriteStreamOptions
);
options = options || {};
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the ReadStream block, else is not there. Should we make this consistent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the ReadStream, Object.create(options || {}) is called since 4d0329e (v1.5.0). I don't think that there is any need to patch that nowdays and re-introduce pre-1.5.0 behavior.

Actually, even failing with an error on anything but a null in that block (if (options === null || typeof options !== 'object')) should not break anything (compared to v1.5.0). It might be better to add a special case for a null instead of patching that block. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant, options = Object.create(options); used to be outside the if..else if blocks in both the cases. Now it is only inside the else part. Isn't this wrong?

);
options = options || {};
} else {
options = Object.create(options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets say I pass a string as an argument to ReadStream, then the options will have encoding in its prototype. But in the WriteStream, encoding will be on the options object itself. Is this okay?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you post a code sample? I think that I'm missing the idea here.

@Fishrock123
Copy link
Contributor

I would rather revert, than re-land the original on next (next major) once reviewed.

@ChALkeR
Copy link
Member Author

ChALkeR commented Jun 15, 2015

@Fishrock123 That would break a feature that was already released in 2.3.0.

@Fishrock123
Copy link
Contributor

Ack I see now.

I'm not sure if we should throw a deprecation here or just silently fail not do anything like before. cc @nodejs/tsc

@ChALkeR
Copy link
Member Author

ChALkeR commented Jun 15, 2015

It hasn't failed before, the function argument was just ignored. At least for the WriteStream.
And in 2.3.0 it started throwing.

else if (options === null || typeof options !== 'object')
throw new TypeError('options must be a string or an object');
else if (options === null || typeof options !== 'object') {
//throw new TypeError('options must be a string or an object');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can drop this an the other commented type error lines.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

This fixes a breaking change in commit
353e26e.
@ChALkeR
Copy link
Member Author

ChALkeR commented Jun 17, 2015

Ok, as no one (including myself) seems to actually support the idea of handling this (wrong API usage by modules) on the io.js side, I closed these PRs (both #1982 and #1998).
If anyone of @nodejs/collaborators thinks that this or #1998 should be reopened or that there needs to be more discussion on this matter, just leave a message here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants