Skip to content
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

feat: port in use #6887

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion layout.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
Copy link
Contributor

Choose a reason for hiding this comment

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

why was this changed?

Copy link
Contributor Author

@wconrad265 wconrad265 Oct 24, 2024

Choose a reason for hiding this comment

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

image

When we were trying to push this commit, we kept having a prettier format error for this file. This is what it recommended that we do, to update to a lowercase doctype. From my understanding, there is no functional difference between the two.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down
43 changes: 22 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 35 additions & 21 deletions src/commands/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,44 @@ import { createStatusCommand } from './status/index.js'
import { createSwitchCommand } from './switch/index.js'
import { createUnlinkCommand } from './unlink/index.js'
import { createWatchCommand } from './watch/index.js'
import { AddressInUseError } from './types.js'

const SUGGESTION_TIMEOUT = 1e4

process.on('uncaughtException', async (err) => {
console.log('')
error(
`${chalk.red(
'Netlify CLI has terminated unexpectedly',
)}\nThis is a problem with the Netlify CLI, not with your application.\nIf you recently updated the CLI, consider reverting to an older version by running:\n\n${chalk.bold(
'npm install -g netlify-cli@VERSION',
)}\n\nYou can use any version from ${chalk.underline(
'https://ntl.fyi/cli-versions',
)}.\n\nPlease report this problem at ${chalk.underline(
'https://ntl.fyi/cli-error',
)} including the error details below.\n`,
{ exit: false },
)

const systemInfo = await getSystemInfo()

console.log(chalk.dim(err.stack || err))
console.log(chalk.dim(systemInfo))

reportError(err, { severity: 'error' })
process.on('uncaughtException', async (err: AddressInUseError | Error) => {
if ('code' in err && err.code === 'EADDRINUSE') {
error(
`${chalk.red(`Port ${err.port} is already in use`)}\n\n` +
`Your serverless functions might be initializing a server\n` +
`to listen on specific port without properly closing it.\n\n` +
`This behavior is generally not advised\n` +
`To resolve this issue, try the following:\n` +
`1. If you NEED your serverless function to listen on a specific port,\n` +
`use a randomly assigned port as we do not officially support this.\n` +
`2. Review your serverless functions for lingering server connections, close them\n` +
`3. Check if any other applications are using port ${err.port}\n`,
{ exit: false },
)
} else {
error(
`${chalk.red(
'Netlify CLI has terminated unexpectedly',
)}\nThis is a problem with the Netlify CLI, not with your application.\nIf you recently updated the CLI, consider reverting to an older version by running:\n\n${chalk.bold(
'npm install -g netlify-cli@VERSION',
)}\n\nYou can use any version from ${chalk.underline(
'https://ntl.fyi/cli-versions',
)}.\n\nPlease report this problem at ${chalk.underline(
'https://ntl.fyi/cli-error',
)} including the error details below.\n`,
{ exit: false },
)

const systemInfo = await getSystemInfo()

console.log(chalk.dim(err.stack || err))
console.log(chalk.dim(systemInfo))
reportError(err, { severity: 'error' })
}

process.exit(1)
})
Expand Down
8 changes: 8 additions & 0 deletions src/commands/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@ export type NetlifyOptions = {
state: StateConfig
frameworksAPIPaths: FrameworksAPIPaths
}

export interface AddressInUseError extends Error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just add this into the same error type as optional fields

Copy link
Contributor

@tlane25 tlane25 Oct 24, 2024

Choose a reason for hiding this comment

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

The Error type lives in ~external/38d21a27-4378-4895-a56a-d0fa5726a379/lib.es2022.error.d.ts. I think it's from a dependency/ external source.

code: 'EADDRINUSE'
errno: number
syscall: 'listen'
address: string
port: number
}
21 changes: 17 additions & 4 deletions src/lib/templates/function-error.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand All @@ -18,8 +18,18 @@

body {
background-color: var(--colorBgApp);
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif,
'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
font-family:
system-ui,
-apple-system,
BlinkMacSystemFont,
'Segoe UI',
Roboto,
Helvetica,
Arial,
sans-serif,
'Apple Color Emoji',
'Segoe UI Emoji',
'Segoe UI Symbol';
color: var(--colorDefaultTextColor);
margin: 0;
line-height: 1.5;
Expand Down Expand Up @@ -53,7 +63,10 @@
section.card {
border-radius: 0.5rem;
background: var(--colorBgCard);
box-shadow: rgb(6 11 16 / 20%) 0px 16px 24px, rgb(6 11 16 / 30%) 0px 6px 30px, rgb(6 11 16 / 40%) 0px 8px 10px;
box-shadow:
rgb(6 11 16 / 20%) 0px 16px 24px,
rgb(6 11 16 / 30%) 0px 6px 30px,
rgb(6 11 16 / 40%) 0px 8px 10px;
border-top-width: 0.5rem;
border-top-style: solid;
border-top-color: var(--colorError);
Expand Down
6 changes: 3 additions & 3 deletions src/utils/command-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ export const error = (message: unknown | Error | string = '', options: { exit?:
message instanceof Error
? message
: // eslint-disable-next-line unicorn/no-nested-ternary
typeof message === 'string'
? new Error(message)
: { message, stack: undefined, name: 'Error' }
typeof message === 'string'
? new Error(message)
: { message, stack: undefined, name: 'Error' }

if (options.exit === false) {
const bang = chalk.red(BANG)
Expand Down