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

feat: support iterables in file#save (#2202) #2203

Merged
merged 1 commit into from
Aug 11, 2023

Conversation

matthieusieben
Copy link
Contributor

@matthieusieben matthieusieben commented May 26, 2023

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #2202 🦕

BEGIN_COMMIT_OVERRIDE
feat: support iterables in file@save
END_COMMIT_OVERRIDE

@matthieusieben matthieusieben requested review from a team as code owners May 26, 2023 10:11
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: storage Issues related to the googleapis/nodejs-storage API. labels May 26, 2023
src/file.ts Outdated Show resolved Hide resolved
@ddelgrosso1
Copy link
Contributor

@matthieusieben thank you for the contribution, we always appreciate getting them. Let me check regarding the disabling of retries but I think we will have to find another way around as this would not adhere to the documentation and would probably be pretty specific to Node storage when compared to our other languages.

src/file.ts Outdated Show resolved Hide resolved
src/file.ts Outdated Show resolved Hide resolved
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Jun 8, 2023
@matthieusieben
Copy link
Contributor Author

matthieusieben commented Jun 8, 2023

Here is a summary of the changes that were added:

  • Do not attempt to read a destroyed readable as this would yield a never resolving promise
  • Do not leave the promise "hanging" when we bail (reject will always be called, regardless of wether bail was called)
  • Do not retry when a failure occurs with a readable stream or (async) iterable
  • Properly cleanup if data is not valid and causes pipeline to throw before the pipeline is actually running
  • Added more test cases

src/file.ts Outdated Show resolved Hide resolved
src/file.ts Outdated Show resolved Hide resolved
@ddelgrosso1 ddelgrosso1 added the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 13, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 13, 2023
@ddelgrosso1 ddelgrosso1 added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Jul 13, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 13, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 13, 2023
@ddelgrosso1
Copy link
Contributor

I think this is looking pretty good. Looks like some issues with tests on Node 12. Ideally I would like to get this in before the move to 14.

@ddelgrosso1 ddelgrosso1 added the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 13, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 13, 2023
@ddelgrosso1 ddelgrosso1 added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Jul 13, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 13, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 13, 2023
@matthieusieben
Copy link
Contributor Author

The reason node-12 is failing is that pipeline only supported Streams (and not AsyncIterable, Iterable or PipelineSourceFunction). Not only did node12 not support those but it does not even throw a proper error in theses cases.

https://nodejs.org/docs/latest-v12.x/api/stream.html#stream_stream_pipeline_streams_callback

How should I adapt to this limitation of Node 12 ?

@matthieusieben
Copy link
Contributor Author

One approach would be to add the following when data is not a buffer or string

// In node 12, pipeline() only supports "Stream"s
if (!('pipe' in data) || typeof data.pipe !== 'function') {
  const nodeVersion = Number(process.versions.node.split('.')[0]);
  if (!nodeVersion || nodeVersion < 14) {
    throw new Error('Saving using an iterable requires Node 14 (or higher)');
  }
}

And to catch that particular error in tests. What do you think ?

@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Aug 3, 2023
@ddelgrosso1
Copy link
Contributor

Removed do not merge as 7.0 is live.

@ddelgrosso1 ddelgrosso1 closed this Aug 3, 2023
@ddelgrosso1 ddelgrosso1 reopened this Aug 3, 2023
@ddelgrosso1 ddelgrosso1 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 3, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 3, 2023
@danielbankhead danielbankhead added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 7, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 7, 2023
@ddelgrosso1 ddelgrosso1 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 11, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 11, 2023
@ddelgrosso1 ddelgrosso1 merged commit c0d9d58 into googleapis:main Aug 11, 2023
10 checks passed
ddelgrosso1 added a commit that referenced this pull request Aug 11, 2023
ddelgrosso1 added a commit that referenced this pull request Aug 11, 2023
ddelgrosso1 added a commit that referenced this pull request Aug 11, 2023
ddelgrosso1 added a commit that referenced this pull request Aug 11, 2023
ddelgrosso1 added a commit that referenced this pull request Aug 11, 2023
ddelgrosso1 added a commit that referenced this pull request Aug 11, 2023
ddelgrosso1 added a commit that referenced this pull request Aug 11, 2023
* feat: support iterables in file#save (#2202) (#2203)

* Revert "feat: support iterables in file#save (#2202) (#2203)" (#2270)

This reverts commit c0d9d58.

* Revert "Revert "feat: support iterables in file#save (#2202) (#2203)" (#2270)"

This reverts commit 49327ff.

---------

Co-authored-by: Matthieu <matthieusieben@users.noreply.github.com>
ddelgrosso1 pushed a commit to ddelgrosso1/nodejs-storage that referenced this pull request Aug 11, 2023
ddelgrosso1 added a commit to ddelgrosso1/nodejs-storage that referenced this pull request Aug 11, 2023
ddelgrosso1 added a commit to ddelgrosso1/nodejs-storage that referenced this pull request Aug 11, 2023
…"" (googleapis#2271)

* feat: support iterables in file#save (googleapis#2202) (googleapis#2203)

* Revert "feat: support iterables in file#save (googleapis#2202) (googleapis#2203)" (googleapis#2270)

This reverts commit c0d9d58.

* Revert "Revert "feat: support iterables in file#save (googleapis#2202) (googleapis#2203)" (googleapis#2270)"

This reverts commit 49327ff.

---------

Co-authored-by: Matthieu <matthieusieben@users.noreply.github.com>
@ddelgrosso1
Copy link
Contributor

BEGIN_COMMIT_OVERRIDE
feat: support iterables in file@save
END_COMMIT_OVERRIDE

ddelgrosso1 pushed a commit to ddelgrosso1/nodejs-storage that referenced this pull request Aug 11, 2023
ddelgrosso1 added a commit to ddelgrosso1/nodejs-storage that referenced this pull request Aug 11, 2023
ddelgrosso1 added a commit to ddelgrosso1/nodejs-storage that referenced this pull request Aug 11, 2023
…"" (googleapis#2271)

* feat: support iterables in file#save (googleapis#2202) (googleapis#2203)

* Revert "feat: support iterables in file#save (googleapis#2202) (googleapis#2203)" (googleapis#2270)

This reverts commit c0d9d58.

* Revert "Revert "feat: support iterables in file#save (googleapis#2202) (googleapis#2203)" (googleapis#2270)"

This reverts commit 49327ff.

---------

Co-authored-by: Matthieu <matthieusieben@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File#save should support Readable / AsyncIterable data
4 participants