Skip to content

Commit 34b6bb4

Browse files
tt
t
authored and
t
committed
fix: added types for EADDRINUSE error and updated error message
Co-authored-by: Will <[email protected]>
1 parent 9bd658a commit 34b6bb4

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/commands/main.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,23 @@ import { createStatusCommand } from './status/index.js'
3737
import { createSwitchCommand } from './switch/index.js'
3838
import { createUnlinkCommand } from './unlink/index.js'
3939
import { createWatchCommand } from './watch/index.js'
40-
40+
import { AddressInUseError } from './types.js'
4141
const SUGGESTION_TIMEOUT = 1e4
4242

43-
process.on('uncaughtException', async (err: any) => {
44-
console.log('')
4543

46-
if (err.code === 'EADDRINUSE') {
44+
process.on('uncaughtException', async (err: AddressInUseError | Error) => {
45+
46+
if ('code' in err && err.code === 'EADDRINUSE') {
4747
error(
4848
`${chalk.red(`Port ${err.port} is already in use`)}\n\n` +
49-
`This could be due to one of your serverless functions initializing a server\n` +
50-
`to listen on port ${err.port} without properly closing it.\n\n` +
49+
`Your serverless functions might be initializing a server\n` +
50+
`to listen on specific port without properly closing it.\n\n` +
51+
`This behavior is generally not advised\n` +
5152
`To resolve this issue, try the following:\n` +
52-
`1. Check if any other applications are using port ${err.port}\n` +
53-
`2. Review your serverless functions for any lingering server connections\n`,
53+
`1. If you NEED your serverless function to listen on a specific port,\n` +
54+
`use a randomly assigned port as we do not officially support this.\n` +
55+
`2. Review your serverless functions for lingering server connections, close them\n` +
56+
`3. Check if any other applications are using port ${err.port}\n`,
5457
{ exit: false },
5558
)
5659
} else {

src/commands/types.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,11 @@ export type NetlifyOptions = {
7373
state: StateConfig
7474
frameworksAPIPaths: FrameworksAPIPaths
7575
}
76+
77+
export interface AddressInUseError extends Error {
78+
code: 'EADDRINUSE'
79+
errno: number
80+
syscall: 'listen'
81+
address: string
82+
port: number
83+
}

0 commit comments

Comments
 (0)