mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-01-10 23:08:06 -05:00
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:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user