Skip to content

Commit ff00f8b

Browse files
committed
fix(tool): fix the error handling in the write-tool
1 parent 421c6cf commit ff00f8b

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/adapters/openai/helpers/completions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ Return only the fixed JSON without any explanation.`;
703703
presence_penalty: 0,
704704
});
705705

706-
this.context.logger.info("LLM response:" + { response: JSON.stringify(res, null, 2) });
706+
this.context.logger.info("LLM response: " + JSON.stringify(res, null, 2));
707707

708708
// Track token usage
709709
if (res.usage) {

src/tools/write-file/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class WriteFile implements Tool<FileWriteResult> {
6262
// First validate the overall structure
6363
const validation = this._validateDiffBlock(diff);
6464
if (!validation.isValid) {
65-
this.context.logger.error("Diff block validation failed:" + { error: validation.error });
65+
this.context.logger.error("Diff block validation failed:", { error: validation.error ? { stack: validation.error } : undefined });
6666
throw new Error(`Invalid diff block format: ${validation.error}`);
6767
}
6868

@@ -163,8 +163,12 @@ export class WriteFile implements Tool<FileWriteResult> {
163163
diffBlocksApplied = blocks.length;
164164
this.context.logger.info(`Successfully applied ${diffBlocksApplied} diff blocks to file`);
165165
} catch (error) {
166-
this.context.logger.error("Error applying diff blocks:", { error: error instanceof Error ? error : new Error(String(error)) });
167-
throw error;
166+
this.context.logger.error("Error applying diff blocks:", {
167+
error: error instanceof Error ? error : { stack: String(error) },
168+
stack: error instanceof Error ? error.stack : undefined,
169+
});
170+
const typedError = error instanceof Error ? error : new Error(String(error || "Unknown error"));
171+
throw typedError;
168172
}
169173
} else {
170174
// Direct content write - will create new file if doesn't exist
@@ -202,12 +206,15 @@ export class WriteFile implements Tool<FileWriteResult> {
202206
},
203207
};
204208
} catch (error) {
205-
const errorObj = error instanceof Error ? error : new Error(String(error));
206-
this.context.logger.error(`File write failed:`, { error: errorObj });
209+
const errorObj = error instanceof Error ? error : new Error(String(error || "Unknown error"));
210+
this.context.logger.error(`File write failed:`, {
211+
error: { stack: errorObj.message },
212+
stack: errorObj.stack,
213+
});
207214

208215
return {
209216
success: false,
210-
error: errorObj.message,
217+
error: errorObj.message || "Unknown error occurred",
211218
metadata: {
212219
timestamp: Date.now(),
213220
toolName: this.name,

0 commit comments

Comments
 (0)