-
-
Notifications
You must be signed in to change notification settings - Fork 0
dev to main #27
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
dev to main #27
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import cors from 'cors' | |
| import { ZenStackMiddleware } from '@zenstackhq/server/express' | ||
| import { ZModelConfig } from './zmodel-parser' | ||
| import { getNodeModulesFolder, getPrismaVersion, getZenStackVersion } from './utils/version-utils' | ||
| import { blue, grey } from 'colors' | ||
| import { blue, grey, red } from 'colors' | ||
| import semver from 'semver' | ||
| import { CliError } from './cli-error' | ||
|
|
||
|
|
@@ -168,23 +168,29 @@ async function loadZenStackModules( | |
| enums = prismaModule.$Enums || {} | ||
| } | ||
|
|
||
| let zenstackAbsPath = zenstackPath | ||
| const zenstackAbsPath = zenstackPath | ||
| ? path.isAbsolute(zenstackPath) | ||
| ? zenstackPath | ||
| : path.join(process.cwd(), zenstackPath) | ||
| : undefined | ||
|
|
||
| if (zenstackAbsPath) { | ||
| const modelMetaPath = path.join(zenstackAbsPath, 'model-meta') | ||
| let modelMetaPath: string | undefined | ||
| try { | ||
| if (zenstackAbsPath) { | ||
| modelMetaPath = path.join(zenstackAbsPath, 'model-meta') | ||
| } else { | ||
| modelMetaPath = '@zenstackhq/runtime/model-meta' | ||
| } | ||
| modelMeta = require(modelMetaPath).default | ||
| } else { | ||
| modelMeta = require('@zenstackhq/runtime/model-meta').default | ||
| } catch { | ||
| throw new CliError( | ||
| `Failed to load ZenStack generated model meta from: ${modelMetaPath}\n` + | ||
| `Please run \`zenstack generate\` first or specify the correct output directory of ZenStack generated modules using the \`-z\` option.` | ||
| ) | ||
| } | ||
|
|
||
| if (!modelMeta.models) { | ||
| throw new CliError( | ||
| 'ZenStack generated modules not found. Please make sure `zenstack generate` has been run or specify the correct path using the `-z` option.' | ||
| ) | ||
| throw new CliError(`Generated model meta not found. Please run \`zenstack generate\` first.`) | ||
| } | ||
|
|
||
| const zenstackVersion = getZenStackVersion() | ||
|
|
@@ -247,6 +253,19 @@ export async function startServer(options: ServerOptions) { | |
| console.log(`ZenStack Studio is running at: ${blue('https://studio.zenstack.dev')}`) | ||
| }) | ||
|
|
||
| server.on('error', (err: NodeJS.ErrnoException) => { | ||
| if (err.code === 'EADDRINUSE') { | ||
| console.error( | ||
| red( | ||
| `Port ${options.port} is already in use. Please choose a different port using -p option.` | ||
| ) | ||
| ) | ||
| } else { | ||
| throw new CliError(`Failed to start the server: ${err.message}`) | ||
| } | ||
| process.exit(1) | ||
| }) | ||
|
Comment on lines
+256
to
+267
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Look for global exception handlers that might intercept throws from server "error" events
rg -n "uncaughtException|unhandledRejection" -SRepository: zenstackhq/proxy Length of output: 42 🏁 Script executed: #!/bin/bash
# Read the relevant section of src/server.ts to verify the code
if [ -f "src/server.ts" ]; then
wc -l src/server.ts
echo "---"
sed -n '250,275p' src/server.ts
else
echo "File not found, searching for server files..."
find . -name "server.ts" -type f | head -10
fiRepository: zenstackhq/proxy Length of output: 844 🏁 Script executed: #!/bin/bash
# Search for CliError definition and usage to understand its purpose
rg -n "class CliError|new CliError" -A 2 -B 2 | head -50Repository: zenstackhq/proxy Length of output: 2727 🏁 Script executed: #!/bin/bash
# Find CliError class definition
rg -n "class CliError|export class CliError" -A 5Repository: zenstackhq/proxy Length of output: 117 🏁 Script executed: #!/bin/bash
# Check if there are other server error handlers and how they handle errors
rg -n "\.on\('error'" -A 10 -B 2Repository: zenstackhq/proxy Length of output: 653 Avoid throwing in the server "error" handler; Throwing 🔧 Suggested fix server.on('error', (err: NodeJS.ErrnoException) => {
if (err.code === 'EADDRINUSE') {
console.error(
red(
`Port ${options.port} is already in use. Please choose a different port using -p option.`
)
)
} else {
- throw new CliError(`Failed to start the server: ${err.message}`)
+ console.error(red(`Failed to start the server: ${err.message}`))
}
process.exit(1)
})🤖 Prompt for AI Agents |
||
|
|
||
| // Graceful shutdown | ||
| process.on('SIGTERM', async () => { | ||
| server.close(() => { | ||
|
|
||
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.
Throwing a
CliErrorinside theserver.on('error', ...)handler means the subsequentprocess.exit(1)is unreachable for the non-EADDRINUSEbranch, and the error will surface as an unhandled exception outside the CLI's try/catch aroundprogram.parseAsync(). To keep error handling consistent and avoid unhandled exceptions, this handler should either log the error and callprocess.exit(1)without throwing, or propagate the failure through a rejected promise fromstartServerso the top-level CLI error handling can catch and report it.