Skip to content

Commit b04f519

Browse files
committed
chore: address SonarQube
1 parent 67298ce commit b04f519

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

packages/event-handler/src/bedrock-agent/BedrockAgentFunctionResolver.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,6 @@ class BedrockAgentFunctionResolver {
147147
fn: ToolFunction<TParams>,
148148
config: Configuration
149149
): undefined {
150-
this.#registerTool(fn, config);
151-
return;
152-
}
153-
154-
#registerTool<TParams extends Record<string, ParameterValue>>(
155-
handler: ToolFunction<TParams>,
156-
config: Configuration
157-
): void {
158150
const { name } = config;
159151
if (this.#tools.has(name)) {
160152
this.#logger.warn(
@@ -163,7 +155,7 @@ class BedrockAgentFunctionResolver {
163155
}
164156

165157
this.#tools.set(name, {
166-
handler: handler as ToolFunction,
158+
handler: fn as ToolFunction,
167159
config,
168160
});
169161
this.#logger.debug(`Tool "${name}" has been registered.`);
@@ -213,9 +205,9 @@ class BedrockAgentFunctionResolver {
213205
const tool = this.#tools.get(toolName);
214206

215207
if (tool == null) {
216-
this.#logger.error(`Tool ${toolName} has not been registered.`);
208+
this.#logger.error(`Tool "${toolName}" has not been registered.`);
217209
return new BedrockFunctionResponse({
218-
body: `Error: tool ${toolName} has not been registered.`,
210+
body: `Error: tool "${toolName}" has not been registered.`,
219211
sessionAttributes,
220212
promptSessionAttributes,
221213
knowledgeBasesConfiguration,
@@ -238,7 +230,7 @@ class BedrockAgentFunctionResolver {
238230
break;
239231
}
240232
// this default will also catch array types but we leave them as strings
241-
// because we cannot reliably parse them
233+
// because we cannot reliably parse them - see discussion in #3710
242234
default: {
243235
toolParams[param.name] = param.value;
244236
break;
@@ -269,8 +261,12 @@ class BedrockAgentFunctionResolver {
269261
});
270262
} catch (error) {
271263
this.#logger.error(`An error occurred in tool ${toolName}.`, error);
264+
const errorMessage =
265+
error instanceof Error
266+
? `${error.name} - ${error.message}`
267+
: String(error);
272268
return new BedrockFunctionResponse({
273-
body: `Unable to complete tool execution due to ${error instanceof Error ? `${error.name} - ${error.message}` : String(error)}`,
269+
body: `Unable to complete tool execution due to ${errorMessage}`,
274270
sessionAttributes,
275271
promptSessionAttributes,
276272
knowledgeBasesConfiguration,

0 commit comments

Comments
 (0)