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: separate strings out of primary SynthesizeStream pipe #957

Merged
merged 3 commits into from
Sep 17, 2019
Merged

feat: separate strings out of primary SynthesizeStream pipe #957

merged 3 commits into from
Sep 17, 2019

Conversation

MasterOdin
Copy link
Contributor

@MasterOdin MasterOdin commented Sep 16, 2019

Fixes #956

As discussed in the issue, the SythesizeStream is currently outputting all information, be it strings or binary data to the pipe (after converting to a Buffer). However, following the example, this will lead to a file that is invalid as it will append both the text and binary to the same file.

This PR separates out the information, and outputs the information onto their own relevant channel as documented for the different types of information strings on the documentation:

The various things documented as being possible emitted:

While this is a breaking change, as it's breaking things to be more expected and inline with how the API is thought to work, putting it as a minor release instead of a major release, which also does not require any documentation change.

No idea how to include a test for this change as well since it looks like the existing test does not directly test the data piped out of the socket.

Checklist
  • npm test passes (tip: npm run autofix can correct most style issues)

Note: Labeled this a feat instead of fix so that it gets a minor release instead of a bugfix by semantic-release, which I think is probably more appropriate, but can rename the commit if desired.

@codecov-io
Copy link

codecov-io commented Sep 16, 2019

Codecov Report

Merging #957 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #957   +/-   ##
=======================================
  Coverage   64.28%   64.28%           
=======================================
  Files           2        2           
  Lines          14       14           
  Branches        3        3           
=======================================
  Hits            9        9           
  Misses          4        4           
  Partials        1        1

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86506e3...e7aabca. Read the comment docs.

Copy link
Contributor

@dpopp07 dpopp07 left a comment

Choose a reason for hiding this comment

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

Looks pretty good! I have a couple questions on things that I might want to change, so I will await your responses before moving forward

lib/synthesize-stream.ts Show resolved Hide resolved
lib/synthesize-stream.ts Show resolved Hide resolved
lib/synthesize-stream.ts Outdated Show resolved Hide resolved
self.emit('words', message, chunk);
}
else if (json['error']) {
self.emit('error', message, chunk);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only one that makes me uneasy because the other existing error event has one arg, which is an Error object that's been formatted a little:

    socket.onerror = event => {
      const err = new Error('WebSocket connection error');
      err.name = SynthesizeStream.WEBSOCKET_CONNECTION_ERROR;
      err['event'] = event;
      self.emit('error', err);
      self.push(null);
    };

it is very likely that users already have handlers set up for the Error event expecting this type of object. I think it would be prudent here to either a) rename this event to something unique or b) try to put together a similarly formatted Error object to send back as the first arg. There are pros and cons to both - what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted my previous response, after re-reading the docs, it is not clear to me what the behavior on error from the socket, so I'd like to test some stuff first before giving a response.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, so played around a bit more with this and it looks like for things like messing up the codec or forgetting text argument, the JSON object is sent over the onmessage channel to the user and then with an additional message on the onclose that says "see previous message for the error details". I'd probably lean towards making them emit on the same channel (and unify warnings to a similar emit format, though on a different channel), as the end result is all the same regardless of the exact reason.

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds good to me, thanks for looking into it

Copy link
Contributor

Choose a reason for hiding this comment

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

Everything else looks good. Once you update the error handler, I'll approve and merge 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, updated the error handler to look like the onerror signature. I did not touch the warnings one as I'm not sure there's a good way to mimic the warnings as JS does not really have a good concept of warnings like python unfortunately.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think that's fine and there's no existing API there so I'm not worried about it

Copy link
Contributor

@dpopp07 dpopp07 left a comment

Choose a reason for hiding this comment

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

Nice, looks good! Thanks again for the PR

@dpopp07 dpopp07 merged commit 3014478 into watson-developer-cloud:master Sep 17, 2019
watson-github-bot pushed a commit that referenced this pull request Sep 19, 2019
# [4.5.0](v4.4.0...v4.5.0) (2019-09-19)

### Bug Fixes

* ignore unecessary files for npm releases ([#962](#962)) ([93eb677](93eb677))

### Features

* separate strings out of primary SynthesizeStream pipe ([#957](#957)) ([3014478](3014478))
@watson-github-bot
Copy link
Member

🎉 This PR is included in version 4.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@MasterOdin MasterOdin deleted the synthesize_string branch September 27, 2019 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

synthesizeUsingWebSocket producing bad files
4 participants