From 9882c11411f7ea5b8e7f92189e71e1f3d62cab05 Mon Sep 17 00:00:00 2001 From: duwenxin Date: Wed, 4 Feb 2026 01:31:19 -0500 Subject: [PATCH] refactor looker --- .../lookercreateprojectfile.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/tools/looker/lookercreateprojectfile/lookercreateprojectfile.go b/internal/tools/looker/lookercreateprojectfile/lookercreateprojectfile.go index bcbdc02014..830df321f7 100644 --- a/internal/tools/looker/lookercreateprojectfile/lookercreateprojectfile.go +++ b/internal/tools/looker/lookercreateprojectfile/lookercreateprojectfile.go @@ -16,12 +16,14 @@ package lookercreateprojectfile import ( "context" "fmt" + "net/http" yaml "github.com/goccy/go-yaml" "github.com/googleapis/genai-toolbox/internal/embeddingmodels" "github.com/googleapis/genai-toolbox/internal/sources" "github.com/googleapis/genai-toolbox/internal/tools" "github.com/googleapis/genai-toolbox/internal/tools/looker/lookercommon" + "github.com/googleapis/genai-toolbox/internal/util" "github.com/googleapis/genai-toolbox/internal/util/parameters" "github.com/looker-open-source/sdk-codegen/go/rtl" @@ -110,29 +112,29 @@ func (t Tool) ToConfig() tools.ToolConfig { return t.Config } -func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) { +func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) { source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type) if err != nil { - return nil, err + return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err) } sdk, err := source.GetLookerSDK(string(accessToken)) if err != nil { - return nil, fmt.Errorf("error getting sdk: %w", err) + return nil, util.NewClientServerError("error getting sdk", http.StatusInternalServerError, err) } mapParams := params.AsMap() projectId, ok := mapParams["project_id"].(string) if !ok { - return nil, fmt.Errorf("'project_id' must be a string, got %T", mapParams["project_id"]) + return nil, util.NewAgentError(fmt.Sprintf("'project_id' must be a string, got %T", mapParams["project_id"]), nil) } filePath, ok := mapParams["file_path"].(string) if !ok { - return nil, fmt.Errorf("'file_path' must be a string, got %T", mapParams["file_path"]) + return nil, util.NewAgentError(fmt.Sprintf("'file_path' must be a string, got %T", mapParams["file_path"]), nil) } fileContent, ok := mapParams["file_content"].(string) if !ok { - return nil, fmt.Errorf("'file_content' must be a string, got %T", mapParams["file_content"]) + return nil, util.NewAgentError(fmt.Sprintf("'file_content' must be a string, got %T", mapParams["file_content"]), nil) } req := lookercommon.FileContent{ @@ -142,7 +144,7 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para err = lookercommon.CreateProjectFile(sdk, projectId, req, source.LookerApiSettings()) if err != nil { - return nil, fmt.Errorf("error making create_project_file request: %s", err) + return nil, util.ProcessGeneralError(err) } data := make(map[string]any)