1- import { APP_DIR , CONFIG_DIR , ConfigIO , setEnvVar , setSessionProjectRoot } from '../../../lib' ;
1+ import {
2+ APP_DIR ,
3+ CONFIG_DIR ,
4+ ConfigIO ,
5+ DependencyCheckError ,
6+ GitInitError ,
7+ setEnvVar ,
8+ setSessionProjectRoot ,
9+ } from '../../../lib' ;
210import type {
311 BuildType ,
412 DeployedState ,
@@ -8,7 +16,7 @@ import type {
816 SDKFramework ,
917 TargetLanguage ,
1018} from '../../../schema' ;
11- import { getErrorMessage } from '../../errors' ;
19+ import { toError } from '../../errors' ;
1220import { checkCreateDependencies } from '../../external-requirements' ;
1321import { initGitRepo , setupPythonProject , writeEnvFile , writeGitignore } from '../../operations' ;
1422import { createConfigBundleForAgent } from '../../operations/agent/config-bundle-defaults' ;
@@ -57,7 +65,11 @@ export async function createProject(options: CreateProjectOptions): Promise<Crea
5765
5866 // Fail on errors
5967 if ( ! depCheck . passed ) {
60- return { success : false , error : depCheck . errors . join ( '\n' ) , warnings : depWarnings } ;
68+ return {
69+ success : false ,
70+ error : new DependencyCheckError ( depCheck . errors ) ,
71+ warnings : depWarnings . length > 0 ? depWarnings : undefined ,
72+ } ;
6173 }
6274 }
6375
@@ -93,7 +105,11 @@ export async function createProject(options: CreateProjectOptions): Promise<Crea
93105 const gitResult = await initGitRepo ( projectRoot ) ;
94106 if ( gitResult . status === 'error' ) {
95107 onProgress ?.( 'Initialize git repository' , 'error' ) ;
96- return { success : false , error : gitResult . message , warnings : depWarnings } ;
108+ return {
109+ success : false ,
110+ error : new GitInitError ( gitResult . message ?? 'Git initialization failed' ) ,
111+ warnings : depWarnings . length > 0 ? depWarnings : undefined ,
112+ } ;
97113 }
98114 onProgress ?.( 'Initialize git repository' , 'done' ) ;
99115 }
@@ -104,7 +120,7 @@ export async function createProject(options: CreateProjectOptions): Promise<Crea
104120 warnings : depWarnings . length > 0 ? depWarnings : undefined ,
105121 } ;
106122 } catch ( err ) {
107- return { success : false , error : getErrorMessage ( err ) , warnings : depWarnings } ;
123+ return { success : false , error : toError ( err ) , warnings : depWarnings . length > 0 ? depWarnings : undefined } ;
108124 }
109125}
110126
@@ -174,7 +190,11 @@ export async function createProjectWithAgent(options: CreateWithAgentOptions): P
174190
175191 // Fail on errors
176192 if ( ! depCheck . passed ) {
177- return { success : false , error : depCheck . errors . join ( '\n' ) , warnings : depWarnings } ;
193+ return {
194+ success : false ,
195+ error : new DependencyCheckError ( depCheck . errors ) ,
196+ warnings : depWarnings . length > 0 ? depWarnings : undefined ,
197+ } ;
178198 }
179199
180200 // First create the base project (skip dependency check since we already did it)
@@ -187,9 +207,7 @@ export async function createProjectWithAgent(options: CreateWithAgentOptions): P
187207 onProgress,
188208 } ) ;
189209 if ( ! projectResult . success ) {
190- // Merge warnings from both checks
191- const allWarnings = [ ...depWarnings , ...( projectResult . warnings ?? [ ] ) ] ;
192- return { ...projectResult , warnings : allWarnings . length > 0 ? allWarnings : undefined } ;
210+ return { ...projectResult , warnings : depWarnings . length > 0 ? depWarnings : projectResult . warnings } ;
193211 }
194212
195213 // Import path: delegate to executeImportAgent after project scaffolding
@@ -207,7 +225,7 @@ export async function createProjectWithAgent(options: CreateWithAgentOptions): P
207225 } ) ;
208226 if ( ! importResult . success ) {
209227 onProgress ?.( 'Import agent from Bedrock' , 'error' ) ;
210- return { success : false , error : importResult . error , warnings : depWarnings } ;
228+ return importResult ;
211229 }
212230 onProgress ?.( 'Import agent from Bedrock' , 'done' ) ;
213231 return {
@@ -217,7 +235,7 @@ export async function createProjectWithAgent(options: CreateWithAgentOptions): P
217235 warnings : depWarnings . length > 0 ? depWarnings : undefined ,
218236 } ;
219237 } catch ( err ) {
220- return { success : false , error : getErrorMessage ( err ) , warnings : depWarnings } ;
238+ return { success : false , error : toError ( err ) , warnings : depWarnings . length > 0 ? depWarnings : undefined } ;
221239 }
222240 }
223241
@@ -310,7 +328,7 @@ export async function createProjectWithAgent(options: CreateWithAgentOptions): P
310328 warnings : depWarnings . length > 0 ? depWarnings : undefined ,
311329 } ;
312330 } catch ( err ) {
313- return { success : false , error : getErrorMessage ( err ) , warnings : depWarnings } ;
331+ return { success : false , error : toError ( err ) , warnings : depWarnings . length > 0 ? depWarnings : undefined } ;
314332 }
315333}
316334
0 commit comments