Skip to content

Improve Dev Proxy API port conflict handling with helpful error messages #1274

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions DevProxy/Commands/DevProxyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,25 +493,34 @@ private async Task<int> InvokeAsync(InvocationContext context)

return 0;
}
catch (TaskCanceledException)
{
throw;
}
catch (Exception ex)
{
_logger.LogError(ex, "An error occurred while running Dev Proxy");
var inner = ex.InnerException;

while (inner is not null)
{
_logger.LogError(inner, "============ Inner exception ============");
inner = inner.InnerException;
}
#if DEBUG
throw; // so debug tools go straight to the source of the exception when attached
#else
return 1;
#endif
catch (TaskCanceledException)
{
throw;
}
catch (IOException ex) when (ex.Message.Contains("Failed to bind to address", StringComparison.OrdinalIgnoreCase) && ex.Message.Contains($":{_proxyConfiguration.ApiPort}", StringComparison.OrdinalIgnoreCase))
{
_logger.LogError("Dev Proxy API port {ApiPort} is already in use.", _proxyConfiguration.ApiPort);
_logger.LogError("To resolve this issue:");
_logger.LogError("1. Add the 'apiPort' property to your configuration file and set it to a different port number");
_logger.LogError("2. If you're using Dev Proxy Toolkit, update the API port extension setting to match your custom port");
_logger.LogError("Example configuration: {{ \"apiPort\": 8898 }}");
return 1;
}
catch (Exception ex)
{
_logger.LogError(ex, "An error occurred while running Dev Proxy");
var inner = ex.InnerException;

while (inner is not null)
{
_logger.LogError(inner, "============ Inner exception ============");
inner = inner.InnerException;
}
#if DEBUG
throw; // so debug tools go straight to the source of the exception when attached
#else
return 1;
#endif
}
}

Expand Down
Loading