diff --git a/pkg/codingcontext/agent.go b/pkg/codingcontext/agent.go index 1e09d9c..56da557 100644 --- a/pkg/codingcontext/agent.go +++ b/pkg/codingcontext/agent.go @@ -101,7 +101,7 @@ var agentPathPatterns = map[Agent][]string{ func (a *Agent) Set(value string) error { agent, err := ParseAgent(value) if err != nil { - return err + return fmt.Errorf("failed to set agent value %q: %w", value, err) } *a = agent diff --git a/pkg/codingcontext/context.go b/pkg/codingcontext/context.go index 46286fb..dc38531 100644 --- a/pkg/codingcontext/context.go +++ b/pkg/codingcontext/context.go @@ -67,12 +67,12 @@ func (cc *Context) visitMarkdownFiles(searchDirFn func(path string) []string, vi if _, err := os.Stat(dir); os.IsNotExist(err) { continue } else if err != nil { - return err + return fmt.Errorf("failed to stat directory %s: %w", dir, err) } err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { if err != nil { - return err + return fmt.Errorf("failed to walk path %s: %w", path, err) } ext := filepath.Ext(path) // .md or .mdc if info.IsDir() || ext != ".md" && ext != ".mdc" { @@ -94,7 +94,7 @@ func (cc *Context) visitMarkdownFiles(searchDirFn func(path string) []string, vi return visitor(path) }) if err != nil { - return err + return fmt.Errorf("failed to walk directory %s: %w", dir, err) } } @@ -118,7 +118,7 @@ func (cc *Context) findTask(taskName string) error { var frontMatter markdown.TaskFrontMatter md, err := markdown.ParseMarkdownFile(path, &frontMatter) if err != nil { - return err + return fmt.Errorf("failed to parse task file %s: %w", path, err) } // Extract selector labels from task frontmatter and add them to cc.includes. @@ -132,7 +132,7 @@ func (cc *Context) findTask(taskName string) error { if frontMatter.Agent != "" { agent, err := ParseAgent(frontMatter.Agent) if err != nil { - return err + return fmt.Errorf("failed to parse agent from task frontmatter: %w", err) } cc.agent = agent } @@ -152,7 +152,7 @@ func (cc *Context) findTask(taskName string) error { // Parse the task content (including user_prompt) to separate text blocks from slash commands task, err := taskparser.ParseTask(taskContent) if err != nil { - return err + return fmt.Errorf("failed to parse task content: %w", err) } // Build the final content by processing each block @@ -174,7 +174,7 @@ func (cc *Context) findTask(taskName string) error { } else if block.SlashCommand != nil { commandContent, err := cc.findCommand(block.SlashCommand.Name, block.SlashCommand.Params()) if err != nil { - return err + return fmt.Errorf("failed to find command %s: %w", block.SlashCommand.Name, err) } finalContent.WriteString(commandContent) } @@ -218,7 +218,7 @@ func (cc *Context) findCommand(commandName string, params taskparser.Params) (st var frontMatter markdown.CommandFrontMatter md, err := markdown.ParseMarkdownFile(path, &frontMatter) if err != nil { - return err + return fmt.Errorf("failed to parse command file %s: %w", path, err) } // Extract selector labels from command frontmatter and add them to cc.includes. diff --git a/pkg/codingcontext/markdown/frontmatter.go b/pkg/codingcontext/markdown/frontmatter.go index e3119f1..e9be92a 100644 --- a/pkg/codingcontext/markdown/frontmatter.go +++ b/pkg/codingcontext/markdown/frontmatter.go @@ -2,6 +2,7 @@ package markdown import ( "encoding/json" + "fmt" "github.com/kitproj/coding-context-cli/pkg/codingcontext/mcp" ) @@ -57,12 +58,12 @@ func (t *TaskFrontMatter) UnmarshalJSON(data []byte) error { } if err := json.Unmarshal(data, aux); err != nil { - return err + return fmt.Errorf("failed to unmarshal task frontmatter: %w", err) } // Also unmarshal into Content map if err := json.Unmarshal(data, &t.BaseFrontMatter.Content); err != nil { - return err + return fmt.Errorf("failed to unmarshal task frontmatter content: %w", err) } return nil @@ -94,12 +95,12 @@ func (c *CommandFrontMatter) UnmarshalJSON(data []byte) error { } if err := json.Unmarshal(data, aux); err != nil { - return err + return fmt.Errorf("failed to unmarshal command frontmatter: %w", err) } // Also unmarshal into Content map if err := json.Unmarshal(data, &c.BaseFrontMatter.Content); err != nil { - return err + return fmt.Errorf("failed to unmarshal command frontmatter content: %w", err) } return nil @@ -143,12 +144,12 @@ func (r *RuleFrontMatter) UnmarshalJSON(data []byte) error { } if err := json.Unmarshal(data, aux); err != nil { - return err + return fmt.Errorf("failed to unmarshal rule frontmatter: %w", err) } // Also unmarshal into Content map if err := json.Unmarshal(data, &r.BaseFrontMatter.Content); err != nil { - return err + return fmt.Errorf("failed to unmarshal rule frontmatter content: %w", err) } return nil diff --git a/pkg/codingcontext/mcp/mcp.go b/pkg/codingcontext/mcp/mcp.go index b6b0624..456072f 100644 --- a/pkg/codingcontext/mcp/mcp.go +++ b/pkg/codingcontext/mcp/mcp.go @@ -1,6 +1,9 @@ package mcp -import "encoding/json" +import ( + "encoding/json" + "fmt" +) // TransportType defines the communication protocol used by the server. // Supported by both Claude and Cursor. @@ -58,7 +61,7 @@ func (m *MCPServerConfig) UnmarshalJSON(data []byte) error { } if err := json.Unmarshal(data, aux); err != nil { - return err + return fmt.Errorf("failed to unmarshal MCP server config: %w", err) } // Initialize Content map if needed @@ -68,7 +71,7 @@ func (m *MCPServerConfig) UnmarshalJSON(data []byte) error { // Also unmarshal into Content map if err := json.Unmarshal(data, &m.Content); err != nil { - return err + return fmt.Errorf("failed to unmarshal MCP server config content: %w", err) } return nil diff --git a/pkg/codingcontext/taskparser/params.go b/pkg/codingcontext/taskparser/params.go index 8e50712..2f9ff2e 100644 --- a/pkg/codingcontext/taskparser/params.go +++ b/pkg/codingcontext/taskparser/params.go @@ -377,7 +377,7 @@ func (p Params) Set(value string) error { params, err := ParseParams(quotedValue) if err != nil { - return err + return fmt.Errorf("failed to parse parameter '%s': %w", value, err) } maps.Copy(p, params)