mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: fix nil pointer dereference in ReportTask (#19045)
This pull request addresses a bug related to a nil pointer dereference in the task reporting functionality. ### Bug Fixes and Error Handling: * Updated `RegisterTools` in `mcp.go` to skip registering the `ReportTask` tool in the remote MCP context when a task reporter is not configured, preventing potential nil pointer dereference panics. * Added a check in `toolsdk.go` to ensure task reporting dependencies are available before invoking the reporter, returning an appropriate error if not. ### Test Coverage: * Added `TestReportTaskNilPointerDeref` in `toolsdk_test.go` to verify that the system does not panic when task reporting dependencies are missing and instead returns a clear error message. * Added `TestReportTaskWithReporter` in `toolsdk_test.go` to validate correct behavior when a task reporter is configured, ensuring the handler processes the request as expected. Signed-off-by: Thomas Kosiewski <tk@coder.com>
This commit is contained in:
+6
-2
@@ -79,11 +79,15 @@ func (s *Server) RegisterTools(client *codersdk.Client) error {
|
||||
return xerrors.Errorf("failed to initialize tool dependencies: %w", err)
|
||||
}
|
||||
|
||||
// Register all available tools
|
||||
// Register all available tools, but exclude tools that require dependencies not available in the
|
||||
// remote MCP context
|
||||
for _, tool := range toolsdk.All {
|
||||
if tool.Name == toolsdk.ToolNameReportTask {
|
||||
continue
|
||||
}
|
||||
|
||||
s.mcpServer.AddTools(mcpFromSDK(tool, toolDeps))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user