Skip to content

Start proxy during site start and improve error wording - #1089

Merged
wojtekn merged 11 commits into
trunkfrom
update/proxy-error-wording
Mar 21, 2025
Merged

Start proxy during site start and improve error wording#1089
wojtekn merged 11 commits into
trunkfrom
update/proxy-error-wording

Conversation

@wojtekn

@wojtekn wojtekn commented Mar 18, 2025

Copy link
Copy Markdown
Contributor

Related issues

Proposed Changes

A "Custom domain set up failed" error is displayed immediately after user starts Studio, even if the user doesn't use a custom domain. I propose to improve Proxy error wording to be more informative about what happened:

Screenshot 2025-03-18 at 16 19 17

Also, I delay starting the proxy until the user tries to start a site that uses custom domains, so users who have port 80 busy and start Studio won't see error immediately.

Testing Instructions

  1. Start a local web server app, e.g., Local
  2. Start Studio
  3. Confirm there is no error about custom domains displayed
  4. Start a site that doesn't use custom domains
  5. Confirm there is no error about custom domains displayed
  6. Start a site that uses custom domains
  7. Confirm that the error message is displayed and that the new wording is clear
  8. Close Studio and other web server that uses 80 port
  9. Repeat above steps and confirm there is no error message and that site is accessible using custom domain

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@wojtekn wojtekn self-assigned this Mar 18, 2025
@wojtekn wojtekn changed the title Improve Proxy error wording Mar 18, 2025
@wojtekn
wojtekn marked this pull request as ready for review March 19, 2025 10:36
Comment thread src/lib/proxy-server.ts
.on( 'error', ( err ) => {
console.log( err );
console.error( `Error starting proxy server on port 80:`, err );
console.error( `Error starting proxy server on port 80` );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let's clean up the error logging, we are logging this error too many times.

Comment thread src/lib/proxy-server.ts Outdated
buttons: [ __( 'OK' ) ],
} );
return false;
throw new Error( 'Studio failed to start the proxy server' );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let's move the part responsible for dialog to the renderer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks a bit odd that we throw a new exception for known error types but just return false for unknown error types. The known error types indicate that port 80 is busy, but other errors also indicate that Studio failed to start the proxy server.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've updated that logic to handle error cases only through exceptions and cleaned up the logic around false.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice improvement 👍

@wojtekn
wojtekn requested a review from a team March 19, 2025 10:46

@bcotrim bcotrim left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code LGTM, and a much better user experience 👍
Just FYI we have this related PR: #1090 there might be some code merging to do, and we should retest, depending on what is merged first.

My only suggestion would be to include unit tests for this scenario.

@sejas sejas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It works as expected. I confirm that the alert appears if port 80 is already in use. I also confirm that sites without a custom domain function as expected without any errors, even if port 80 is occupied. After freeing port 80, I was able to start two Studio sites with custom domains.

Great work!

Screenshot 2025-03-19 at 19 37 25

Here are the logs when running two sites with custom domains:

Server stopped
Stopped watching for file changes
SQLite folder already exists. Skipping download.
Domain example-2.wp.local added to hosts file for port 8901
Proxy server started on port 80
Custom domain proxy server started successfully
Starting server for 'example 2'
directory: /Users/macbookpro/Studio/example-2
mode: wordpress
php: 8.2
wp: latest
WordPress latest folder already exists. Skipping download.
SQLite folder already exists. Skipping download.
Server running at http://example-2.wp.local
Server started for 'example 2'
Domain example.wp.local added to hosts file for port 8900
Custom domain proxy server started successfully
Starting server for 'example'
directory: /Users/macbookpro/Studio/example
mode: wordpress
php: 8.2
wp: latest
WordPress latest folder already exists. Skipping download.
SQLite folder already exists. Skipping download.
Server running at http://example.wp.local
Server started for 'example' 
Comment thread src/hooks/use-site-details.tsx Outdated
getIpcApi().showErrorMessageBox( {
title: __( 'Studio failed to initialize custom domains' ),
message: __(
'Studio needs to use port 80, but it’s already in use by another app. Close any local development apps and restart Studio.'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we mention that the port 80 is only necessary for custom domains?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The title says it failed to initialize custom domains, but it makes sense to clarify the message. I've added that in c82c902

Comment thread src/ipc-handlers.ts Outdated
Comment on lines +410 to +417
try {
const proxyStarted = await startProxyServer();
if ( ! proxyStarted ) {
console.warn(
'Failed to start custom domain proxy server - custom domains will require port numbers'
);
}
console.log( 'Custom domain proxy server started successfully' );

@sejas sejas Mar 19, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to change anything. Just an observation. I noticed we display Custom domain proxy server started successfully each time we start a server with custom domain.
I think it's innocuous as we also display the Domain example.wp.local added to hosts file for port 8900

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed redundant logging in 67bdbcf and moved the hosts log message to the proper place in f29028e

@wojtekn
wojtekn force-pushed the update/proxy-error-wording branch from dc5b1ee to c82c902 Compare March 20, 2025 09:23
Comment thread src/hooks/use-site-details.tsx Outdated
} );
if (
error instanceof Error &&
error.message.includes( 'Studio failed to start the proxy server' )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this error only indicates that port 80 is busy, I would argue we should use a more specific error message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've improved wording in e06d062

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, as those are used internally to mitigate IPC handler that flattens our exceptions, we could change descriptive messages to codes e.g. PROXY_ERROR_80 or prepend messages with the prefix e.g. PROXY_ERROR_80: 'Studio failed to [...]. Thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree we could use a message like PROXY_ERROR_80, since this is only used internally 👍

@wojtekn
wojtekn merged commit cf9a212 into trunk Mar 21, 2025
@wojtekn
wojtekn deleted the update/proxy-error-wording branch March 21, 2025 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants