-
Notifications
You must be signed in to change notification settings - Fork 369
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
fix: File#save
iterable fixes
#2293
Conversation
@@ -3644,20 +3643,6 @@ class File extends ServiceObject<File, FileMetadata> { | |||
} | |||
const returnValue = retry( | |||
async (bail: (err: Error) => void) => { | |||
if (data instanceof Readable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this logic as for the vast majority it would simply slow down their uploads unnecessarily. Additionally, later versions of Node.js catch this for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know what versions catch this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node 18.0.0:
- stream: fix pipeline callback not called on ended stream nodejs/node#46600
- https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V18.md#18.0.0
Here's a simple reproduction for a REPL (anything before 18 the console.log
isn't called):
const readable = stream.Readable({read() {this.push(null)}});
readable.read();
readable.readable // false
stream.pipeline(readable, stream.PassThrough, () => console.log('done'));
file.save(generator(), options, (err: Error) => { | ||
assert.strictEqual( | ||
err.message, | ||
'The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Object' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just testing Node internals. Removed.
// If data is not a valid PipelineSource, then pipeline will | ||
// fail without destroying the writable stream. If data is a | ||
// PipelineSource that yields invalid chunks (e.g. a stream in | ||
// object mode or an iterable that does not yield Buffers or | ||
// strings), then pipeline will destroy the writable stream. | ||
if (!writable.destroyed) writable.destroy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case doesn't happen - instead, Node throws immediately and this callback is never called.
Fixes #2278 🦕