fix: improve dry run output formatting and config path error handling

## CHANGES

- Remove leading newline from DryRunResponse constant
- Add newline separator in SendStream method output
- Add newline separator in Send method output
- Improve GetDefaultConfigPath error handling logic
- Add stderr error message for config access failures
- Return empty string when config file doesn't exist
This commit is contained in:
Kayvan Sylvan
2025-07-16 23:46:07 -07:00
parent ac97f9984f
commit da1c8ec979
2 changed files with 10 additions and 6 deletions

View File

@@ -12,7 +12,7 @@ import (
"github.com/danielmiessler/fabric/internal/plugins"
)
const DryRunResponse = "\nDry run: Fake response sent by DryRun plugin\n"
const DryRunResponse = "Dry run: Fake response sent by DryRun plugin\n"
type Client struct {
*plugins.PluginBase
@@ -108,6 +108,7 @@ func (c *Client) constructRequest(msgs []*chat.ChatCompletionMessage, opts *doma
func (c *Client) SendStream(msgs []*chat.ChatCompletionMessage, opts *domain.ChatOptions, channel chan string) error {
request := c.constructRequest(msgs, opts)
channel <- request
channel <- "\n"
channel <- DryRunResponse
close(channel)
return nil
@@ -116,7 +117,7 @@ func (c *Client) SendStream(msgs []*chat.ChatCompletionMessage, opts *domain.Cha
func (c *Client) Send(_ context.Context, msgs []*chat.ChatCompletionMessage, opts *domain.ChatOptions) (string, error) {
request := c.constructRequest(msgs, opts)
return request + DryRunResponse, nil
return request + "\n" + DryRunResponse, nil
}
func (c *Client) Setup() error {

View File

@@ -81,9 +81,12 @@ func GetDefaultConfigPath() string {
}
defaultConfigPath := filepath.Join(homeDir, ".fabric.yaml")
if _, err := os.Stat(defaultConfigPath); err == nil {
return defaultConfigPath
if _, err := os.Stat(defaultConfigPath); err != nil {
if os.IsNotExist(err) {
return ""
}
fmt.Fprintf(os.Stderr, "Error accessing default config path: %v\n", err)
return ""
}
return ""
return defaultConfigPath
}