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
fix: offer a new port and listen if already used, use consola on server error #4428
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #4428 +/- ##
=========================================
+ Coverage 91.4% 91.48% +0.08%
=========================================
Files 56 56
Lines 1943 1962 +19
Branches 485 487 +2
=========================================
+ Hits 1776 1795 +19
Misses 155 155
Partials 12 12
Continue to review full report at Codecov.
|
BeforeCurrent (after that PR)
With suggested changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to change to consola.error()
like @manniL suggested but otherwise LGTM!
I think we can improve more the DX on this. Why not checking the ECODE and display a better error instead when we know it? |
@Atinux Had the same idea. @ricardogobbosouza Do you want to take that or should we? |
@ricardogobbosouza Maybe like
We could do that for more common codes as well (list of all: http://man7.org/linux/man-pages/man3/errno.3.html) |
What will we customize? Everyone would be unnecessary, do not you think? |
@ricardogobbosouza Not every single one |
@manniL @ricardogobbosouza V8 error codes are listed here. Honestly, I would like to add this as a feature into Something else as a suggestion: For development mode, like other frameworks (CRA, Next,..) why not gently offer a new port and listen on it? :D |
@pi0 I fully agree that the error handling is done in the consola and that a new port should be suggested to the user. |
@manniL Nice idea. But won't it be annoying to change ports at each nuxt restart? We need to restart it when we change nuxt.config.js and so we should update our tabs port? Would be nicer to take 3001 if 3000 is already taken, then 3002, etc. |
@HugoHeneault Well, |
@HugoHeneault I think a random port is better than creating a counter for it. |
I'm fine with a random port if the initial one is blocked 👍 |
packages/server/src/listener.js
Outdated
|
||
async serverErrorHandler(e) { | ||
if (e.code === 'EADDRINUSE') { | ||
consola.warn(`Address \`${this.host}:${this.port}\` is already in use.`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For production, we have to throw a FATAL error because the server is not usable and we silently continue listening on a random port. This makes production debug hard
@ricardogobbosouza I've made some improvement. Would you please review latest diff? |
} | ||
|
||
// Throw error | ||
throw error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip: This error is handled by consola when using cli. The reason why not using consola
here is that programatic usage needs to capture the listen error instead of silently skipping
@pi0 nice!! 👍 |
🔥 🔥 🔥 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Types of changes
Description
port
is already in use, offer a new and listenconsola
on server errorResolves: #4421
Checklist: