Skip to content

Commit fbf9be6

Browse files
authored
Merge pull request #611 from dgageot/fix-dead-code
Remove dead code
2 parents 1fb10cd + d94d6b0 commit fbf9be6

3 files changed

Lines changed: 13 additions & 28 deletions

File tree

pkg/config/config.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"context"
55
"fmt"
6+
"log/slog"
67
"os"
78
"path/filepath"
89
"strings"
@@ -61,18 +62,20 @@ func LoadConfig(path string, fs filesystem.FS) (*latest.Config, error) {
6162
//
6263
// This allows exiting early with a proper error message instead of failing later when trying to use a model or tool.
6364
func CheckRequiredEnvVars(ctx context.Context, cfg *latest.Config, env environment.Provider, runtimeConfig RuntimeConfig) error {
64-
requiredEnv, err := GatherMissingEnvVars(ctx, cfg, env, runtimeConfig)
65+
missing, err := gatherMissingEnvVars(ctx, cfg, env, runtimeConfig)
6566
if err != nil {
66-
return fmt.Errorf("gathering required environment variables: %w", err)
67+
// If there's a tool preflight error, log it but continue
68+
slog.Warn("Failed to preflight toolset environment variables; continuing", "error", err)
6769
}
6870

69-
if len(requiredEnv) == 0 {
70-
return nil
71+
// Return error if there are missing environment variables
72+
if len(missing) > 0 {
73+
return &environment.RequiredEnvError{
74+
Missing: missing,
75+
}
7176
}
7277

73-
return &environment.RequiredEnvError{
74-
Missing: requiredEnv,
75-
}
78+
return nil
7679
}
7780

7881
func parseCurrentVersion(dir string, data []byte, version any) (any, error) {

pkg/config/gather.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
"github.com/docker/cagent/pkg/model/provider"
1313
)
1414

15-
// GatherMissingEnvVars finds out which environment variables are required by the models and tools.
15+
// gatherMissingEnvVars finds out which environment variables are required by the models and tools.
1616
// It returns the missing variables and any non-fatal error encountered during tool discovery.
17-
func GatherMissingEnvVars(ctx context.Context, cfg *latest.Config, env environment.Provider, runtimeConfig RuntimeConfig) (missing []string, toolErr error) {
17+
func gatherMissingEnvVars(ctx context.Context, cfg *latest.Config, env environment.Provider, runtimeConfig RuntimeConfig) (missing []string, toolErr error) {
1818
requiredEnv := map[string]bool{}
1919

2020
// Models

pkg/teamloader/teamloader.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -262,24 +262,6 @@ func findAgentPaths(agentsPathOrDirectory string) ([]string, error) {
262262
return agents, nil
263263
}
264264

265-
// checkRequiredEnvVars checks which environment variables are required by the models and tools.
266-
// This allows exiting early with a proper error message instead of failing later when trying to use a model or tool.
267-
func checkRequiredEnvVars(ctx context.Context, cfg *latest.Config, env environment.Provider, runtimeConfig config.RuntimeConfig) error {
268-
missing, toolErr := config.GatherMissingEnvVars(ctx, cfg, env, runtimeConfig)
269-
270-
// If there's a tool preflight error, log it but continue
271-
if toolErr != nil {
272-
slog.Warn("Failed to preflight toolset environment variables; continuing", "error", toolErr)
273-
}
274-
275-
// Return error if there are missing environment variables
276-
if len(missing) > 0 {
277-
return &environment.RequiredEnvError{Missing: missing}
278-
}
279-
280-
return nil
281-
}
282-
283265
type loadOptions struct {
284266
modelOverrides []string
285267
toolsetRegistry *ToolsetRegistry
@@ -344,7 +326,7 @@ func Load(ctx context.Context, p string, runtimeConfig config.RuntimeConfig, opt
344326
}
345327

346328
// Early check for required env vars before loading models and tools.
347-
if err := checkRequiredEnvVars(ctx, cfg, env, runtimeConfig); err != nil {
329+
if err := config.CheckRequiredEnvVars(ctx, cfg, env, runtimeConfig); err != nil {
348330
return nil, err
349331
}
350332

0 commit comments

Comments
 (0)