@@ -136,11 +136,16 @@ export class TaskManager {
136
136
const attachmentContents : string [ ] = [ ] ;
137
137
for ( const filename of attachments ) {
138
138
try {
139
+ console . log ( "We are about to try to read the file." )
139
140
const content = await this . fileSystemService . readAttachmentFile ( filename ) ;
140
141
attachmentContents . push ( content ) ;
141
142
} catch ( error ) {
142
143
// Propagate file read errors
143
- throw error ;
144
+ throw createError (
145
+ ErrorCode . FileReadError ,
146
+ `Failed to read attachment file: ${ filename } ` ,
147
+ { originalError : error }
148
+ ) ;
144
149
}
145
150
}
146
151
@@ -171,6 +176,7 @@ export class TaskManager {
171
176
`Invalid provider: ${ provider } `
172
177
) ;
173
178
}
179
+ console . log ( "set model and provider" )
174
180
175
181
// Define the schema for the LLM's response using jsonSchema helper
176
182
const projectPlanSchema = jsonSchema < ProjectPlanOutput > ( {
@@ -223,6 +229,7 @@ export class TaskManager {
223
229
} catch ( err ) {
224
230
// Handle specific AI SDK errors
225
231
if ( err instanceof Error ) {
232
+ // Check for specific error names or messages
226
233
if ( err . name === 'NoObjectGeneratedError' ) {
227
234
throw createError (
228
235
ErrorCode . InvalidResponseFormat ,
@@ -244,20 +251,33 @@ export class TaskManager {
244
251
{ originalError : err }
245
252
) ;
246
253
}
254
+ // --- Updated Check for API Key Errors ---
255
+ // Check by name (more robust) or message content
256
+ if ( err . name === 'LoadAPIKeyError' || err . message . includes ( 'API key is missing' ) ) {
257
+ throw createError (
258
+ ErrorCode . ConfigurationError , // Use the correct code for config issues
259
+ "Invalid or missing API key. Please check your environment variables." , // More specific message
260
+ { originalError : err }
261
+ ) ;
262
+ }
263
+ // Existing check for general auth errors (might still be relevant for other cases)
247
264
if ( err . message . includes ( 'authentication' ) || err . message . includes ( 'unauthorized' ) ) {
248
265
throw createError (
249
266
ErrorCode . ConfigurationError ,
250
- "Invalid API key or authentication failed . Please check your environment variables ." ,
267
+ "Authentication failed with the LLM provider . Please check your credentials ." ,
251
268
{ originalError : err }
252
269
) ;
253
270
}
254
271
}
255
272
256
- // For unknown errors, preserve the original error but wrap it
273
+ // For unknown errors from the LLM/SDK, preserve the original error but wrap it.
274
+ // Use a more generic error code here if it's not one of the above.
275
+ // Perhaps keep InvalidResponseFormat or create a new one like LLMInteractionError?
276
+ // Let's stick with InvalidResponseFormat for now as it often manifests as bad output.
257
277
throw createError (
258
- ErrorCode . InvalidResponseFormat ,
259
- "Failed to generate project plan" ,
260
- { originalError : err }
278
+ ErrorCode . InvalidResponseFormat , // Fallback code
279
+ "Failed to generate project plan due to an unexpected error." , // Fallback message
280
+ { originalError : err } // Always include original error for debugging
261
281
) ;
262
282
}
263
283
}
0 commit comments