Skip to content

Conversation

@taras
Copy link
Member

@taras taras commented Aug 19, 2020

Closes #427

Motivation

People should know what is happening when an error occurred. They should not have to look at stack traces to figure out what it means. When running tests without bigtest server present, we would get an ugly stack trace that said: websocket server closed connection unexpectedly. Instead, we want to show an error that suggests to run bigtest server before running tests.

Approach

Detect when we get websocket server closed connection unexpectedly and show error: Could not connect to BigTest server on ${uri}. Run "bigtest server" to start the server. instead.

@changeset-bot
Copy link

changeset-bot bot commented Aug 19, 2020

🦋 Changeset is good to go

Latest commit: f11c264

We got this.

This PR includes changesets to release 3 packages
Name Type
@bigtest/cli Patch
@bigtest/client Patch
bigtest Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@taras taras requested a review from cowboyd August 19, 2020 23:00
@github-actions
Copy link
Contributor

github-actions bot commented Aug 19, 2020

The preview packages of this pull request have been published.
Click on the following packages for instructions on how to install them:

@bigtest/agent

Install using the following command:

$ npm install @bigtest/agent@tm_better-error-when-bigtest-server-is-not-available

Or update your package.json file:

{
  "@bigtest/agent": "tm_better-error-when-bigtest-server-is-not-available"
}

@bigtest/atom

Install using the following command:

$ npm install @bigtest/atom@tm_better-error-when-bigtest-server-is-not-available

Or update your package.json file:

{
  "@bigtest/atom": "tm_better-error-when-bigtest-server-is-not-available"
}

@bigtest/bundler

Install using the following command:

$ npm install @bigtest/bundler@tm_better-error-when-bigtest-server-is-not-available

Or update your package.json file:

{
  "@bigtest/bundler": "tm_better-error-when-bigtest-server-is-not-available"
}

@bigtest/cli

Install using the following command:

$ npm install @bigtest/cli@tm_better-error-when-bigtest-server-is-not-available

Or update your package.json file:

{
  "@bigtest/cli": "tm_better-error-when-bigtest-server-is-not-available"
}

@bigtest/client

Install using the following command:

$ npm install @bigtest/client@tm_better-error-when-bigtest-server-is-not-available

Or update your package.json file:

{
  "@bigtest/client": "tm_better-error-when-bigtest-server-is-not-available"
}

@bigtest/effection

Install using the following command:

$ npm install @bigtest/effection@tm_better-error-when-bigtest-server-is-not-available

Or update your package.json file:

{
  "@bigtest/effection": "tm_better-error-when-bigtest-server-is-not-available"
}

@bigtest/effection-express

Install using the following command:

$ npm install @bigtest/effection-express@tm_better-error-when-bigtest-server-is-not-available

Or update your package.json file:

{
  "@bigtest/effection-express": "tm_better-error-when-bigtest-server-is-not-available"
}

@bigtest/server

Install using the following command:

$ npm install @bigtest/server@tm_better-error-when-bigtest-server-is-not-available

Or update your package.json file:

{
  "@bigtest/server": "tm_better-error-when-bigtest-server-is-not-available"
}

@bigtest/webdriver

Install using the following command:

$ npm install @bigtest/webdriver@tm_better-error-when-bigtest-server-is-not-available

Or update your package.json file:

{
  "@bigtest/webdriver": "tm_better-error-when-bigtest-server-is-not-available"
}

Generated by 🚫 dangerJS against f11c264

cowboyd
cowboyd previously approved these changes Aug 20, 2020
Copy link
Member

@cowboyd cowboyd left a comment

Choose a reason for hiding this comment

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

I'm wondering if we should have a timeout

if (e.message.includes('websocket server closed connection unexpectedly')) {
throw new MainError({
exitCode: 1,
message: `Could not connect to BigTest server on ${uri}. Run "bigtest server" to start the server.`
Copy link
Member

Choose a reason for hiding this comment

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

Since we use the runTest command in both the ci and test commands, we have a potential weird case where the server stops responding to commands in between when it is started, and when we actually try to connect the client. This should be exceedingly rare, but I figured I'd point it out nonetheless.

@cowboyd cowboyd self-requested a review August 20, 2020 18:03
@cowboyd cowboyd dismissed their stale review August 20, 2020 18:04

oops, meant to hit comment, not approve

@taras taras force-pushed the tm/better-error-when-bigtest-server-is-not-available branch from 06f9257 to baec97c Compare August 20, 2020 19:54
@taras taras requested a review from jnicklas August 26, 2020 10:41
yield spawn(function* detectStartupError(): Operation<void> {
let [error] = yield once(socket, 'error');

if (isYaetiError(error)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd call this isErrorEvent since Yaeti is just the nodejs error event emulator for the ErrorEvent. When the client is running on the browser, it will actually be an ErrorEvent

Copy link
Member

Choose a reason for hiding this comment

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

Worth noting that on the web, this will always be an error event.

@taras taras requested review from cowboyd and pittst3r August 26, 2020 22:04
Copy link
Member

@cowboyd cowboyd left a comment

Choose a reason for hiding this comment

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

Looks great! effection code looking sharp.

if (isErrorEvent(error)) {
throw new NoServerError(`Could not connect to server at ${url}`);
} else {
throw error;
Copy link
Member

Choose a reason for hiding this comment

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

I'm trying to imagine a scenario where we execute this code branch, and can't think of one other than a bug in the websocket library. Still, it's good to have in case there is and it will throw a big nasty stack trace.

private constructor(private socket: WebSocket) {}

static *create(url: string): Operation<Client> {
let socket = new w3cwebsocket(url) as WebSocket;
Copy link
Member

Choose a reason for hiding this comment

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

Out of scope for this PR, but in order to make this work in the browser, we're going to have to loosely couple to our underlying websocket library. I wonder what is the best way to do that.

@taras taras dismissed jnicklas’s stale review August 27, 2020 03:06

Applied changes

@taras taras merged commit 6225250 into v0 Aug 27, 2020
@taras taras deleted the tm/better-error-when-bigtest-server-is-not-available branch August 27, 2020 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better error if test command cannot connect to an orchestrator

5 participants