@@ -3,6 +3,7 @@ import { benchifyFileSchema } from './schemas';
3
3
import { z } from 'zod' ;
4
4
import { fetchAllSandboxFiles } from './file-filter' ;
5
5
import { applyTransformations } from './sandbox-helpers' ;
6
+ import { detectCodeErrors , parseTypeScriptErrors } from './error-detection' ;
6
7
7
8
const E2B_API_KEY = process . env . E2B_API_KEY ;
8
9
@@ -59,8 +60,11 @@ export async function createSandbox({ files }: { files: z.infer<typeof benchifyF
59
60
console . log ( 'New packages installed successfully:' , result . stdout ) ;
60
61
if ( result . stderr ) {
61
62
console . warn ( 'npm install warnings:' , result . stderr ) ;
62
- // Parse npm install errors
63
- if ( result . stderr . includes ( 'npm ERR!' ) ) {
63
+ // Only treat critical npm errors as build errors (not warnings or peer dep issues)
64
+ if ( result . stderr . includes ( 'npm ERR!' ) &&
65
+ ( result . stderr . includes ( 'ENOTFOUND' ) ||
66
+ result . stderr . includes ( 'ECONNREFUSED' ) ||
67
+ result . stderr . includes ( 'permission denied' ) ) ) {
64
68
buildErrors . push ( {
65
69
type : 'build' ,
66
70
message : 'Package installation failed: ' + result . stderr . split ( 'npm ERR!' ) [ 1 ] ?. trim ( )
@@ -79,39 +83,47 @@ export async function createSandbox({ files }: { files: z.infer<typeof benchifyF
79
83
}
80
84
}
81
85
82
- // Run TypeScript check to catch type errors
86
+ // Start the dev server and check logs for errors (let Vite handle error detection)
83
87
try {
84
- console . log ( 'Running TypeScript check...' ) ;
85
- const tscResult = await sandbox . commands . run ( 'cd /app && npx tsc --noEmit --skipLibCheck' ) ;
86
-
87
- if ( tscResult . exitCode !== 0 && tscResult . stderr ) {
88
- console . log ( 'TypeScript errors found:' , tscResult . stderr ) ;
89
- const tsErrors = parseTypeScriptErrors ( tscResult . stderr ) ;
90
- buildErrors . push ( ...tsErrors ) ;
88
+ console . log ( 'Starting dev server...' ) ;
89
+ // Start dev server in background
90
+ const devServerResult = await sandbox . commands . run ( 'cd /app && npm run dev' , { background : true } ) ;
91
+
92
+ console . log ( 'Dev server command executed' ) ;
93
+ console . log ( 'Dev server exit code:' , devServerResult . exitCode ) ;
94
+ console . log ( 'Dev server stderr:' , devServerResult . stderr || 'No stderr' ) ;
95
+ console . log ( 'Dev server stdout:' , devServerResult . stdout || 'No stdout' ) ;
96
+
97
+ // Give it a moment to start and potentially fail
98
+ console . log ( 'Waiting 3 seconds for dev server to start...' ) ;
99
+ await new Promise ( resolve => setTimeout ( resolve , 3000 ) ) ;
100
+
101
+ // Check the initial output for immediate errors
102
+ if ( devServerResult . stderr || devServerResult . stdout ) {
103
+ const allOutput = ( devServerResult . stderr || '' ) + '\n' + ( devServerResult . stdout || '' ) ;
104
+
105
+ // Use the error detection module
106
+ const errorResult = detectCodeErrors ( allOutput ) ;
107
+
108
+ if ( errorResult . hasErrors ) {
109
+ console . log ( '🔴 CODE ERRORS DETECTED!' ) ;
110
+ buildErrors . push ( ...errorResult . errors ) ;
111
+ } else if ( errorResult . isInfrastructureOnly ) {
112
+ console . log ( '⚠️ Only infrastructure errors detected (ignoring)' ) ;
113
+ } else {
114
+ console . log ( '✅ No errors detected' ) ;
115
+ }
116
+ } else {
117
+ console . log ( '⚠️ No stderr or stdout from dev server command' ) ;
91
118
}
92
- } catch ( error ) {
93
- console . error ( 'TypeScript check failed:' , error ) ;
94
- buildErrors . push ( {
95
- type : 'typescript' ,
96
- message : `TypeScript check failed: ${ error instanceof Error ? error . message : String ( error ) } `
97
- } ) ;
98
- }
99
119
100
- // Try to build the project to catch build-time errors
101
- try {
102
- console . log ( 'Running build check...' ) ;
103
- const buildResult = await sandbox . commands . run ( 'cd /app && npm run build' ) ;
104
-
105
- if ( buildResult . exitCode !== 0 ) {
106
- console . log ( 'Build errors found:' , buildResult . stderr ) ;
107
- const viteErrors = parseViteBuildErrors ( buildResult . stderr ) ;
108
- buildErrors . push ( ...viteErrors ) ;
109
- }
120
+ console . log ( 'Dev server started, output checked' ) ;
121
+ console . log ( 'Total build errors found:' , buildErrors . length ) ;
110
122
} catch ( error ) {
111
- console . error ( 'Build check failed:' , error ) ;
123
+ console . error ( 'Dev server check failed:' , error ) ;
112
124
buildErrors . push ( {
113
125
type : 'build' ,
114
- message : `Build failed: ${ error instanceof Error ? error . message : String ( error ) } `
126
+ message : `Dev server failed to start : ${ error instanceof Error ? error . message : String ( error ) } `
115
127
} ) ;
116
128
}
117
129
@@ -130,60 +142,7 @@ export async function createSandbox({ files }: { files: z.infer<typeof benchifyF
130
142
} ;
131
143
}
132
144
133
- function parseTypeScriptErrors ( stderr : string ) : BuildError [ ] {
134
- const errors : BuildError [ ] = [ ] ;
135
- const lines = stderr . split ( '\n' ) ;
136
-
137
- for ( const line of lines ) {
138
- // Match TypeScript error pattern: file(line,column): error TS####: message
139
- const match = line . match ( / ( .+ ) \( ( \d + ) , ( \d + ) \) : e r r o r T S \d + : ( .+ ) / ) ;
140
- if ( match ) {
141
- const [ , file , line , column , message ] = match ;
142
- errors . push ( {
143
- type : 'typescript' ,
144
- message : message . trim ( ) ,
145
- file : file . replace ( '/app/' , '' ) ,
146
- line : parseInt ( line ) ,
147
- column : parseInt ( column )
148
- } ) ;
149
- }
150
- }
151
145
152
- // If no specific errors found but stderr has content, add generic error
153
- if ( errors . length === 0 && stderr . trim ( ) ) {
154
- errors . push ( {
155
- type : 'typescript' ,
156
- message : 'TypeScript compilation failed: ' + stderr . trim ( )
157
- } ) ;
158
- }
159
-
160
- return errors ;
161
- }
162
-
163
- function parseViteBuildErrors ( stderr : string ) : BuildError [ ] {
164
- const errors : BuildError [ ] = [ ] ;
165
- const lines = stderr . split ( '\n' ) ;
166
-
167
- for ( const line of lines ) {
168
- // Match Vite build error patterns
169
- if ( line . includes ( 'error' ) || line . includes ( 'Error' ) ) {
170
- errors . push ( {
171
- type : 'build' ,
172
- message : line . trim ( )
173
- } ) ;
174
- }
175
- }
176
-
177
- // If no specific errors found but stderr has content, add generic error
178
- if ( errors . length === 0 && stderr . trim ( ) ) {
179
- errors . push ( {
180
- type : 'build' ,
181
- message : 'Build failed: ' + stderr . trim ( )
182
- } ) ;
183
- }
184
-
185
- return errors ;
186
- }
187
146
188
147
function extractNewPackages ( packageJsonContent : string ) : string [ ] {
189
148
try {
0 commit comments