From 2cd4936c997187c7422ba36167f33323b5cf19f7 Mon Sep 17 00:00:00 2001 From: Dave Date: Fri, 26 Apr 2024 04:34:31 -0400 Subject: [PATCH] fix: security scanner warning noise: error handlers part 1 (#2141) first group of error handlers to reduce security scanner warning noise level Signed-off-by: Dave Lee --- core/backend/options.go | 11 ++++++++--- core/startup/startup.go | 5 ++++- embedded/embedded.go | 6 +++++- examples/semantic-todo/main.go | 5 ++++- main.go | 6 +++++- pkg/assets/list.go | 7 ++++++- pkg/grpc/server.go | 4 ++-- 7 files changed, 34 insertions(+), 10 deletions(-) diff --git a/core/backend/options.go b/core/backend/options.go index bbb9990d..4a7435e6 100644 --- a/core/backend/options.go +++ b/core/backend/options.go @@ -7,7 +7,8 @@ import ( "github.com/go-skynet/LocalAI/core/config" pb "github.com/go-skynet/LocalAI/pkg/grpc/proto" - model "github.com/go-skynet/LocalAI/pkg/model" + "github.com/go-skynet/LocalAI/pkg/model" + "github.com/rs/zerolog/log" ) func modelOpts(c config.BackendConfig, so *config.ApplicationConfig, opts []model.Option) []model.Option { @@ -109,8 +110,12 @@ func gRPCPredictOpts(c config.BackendConfig, modelPath string) *pb.PredictOption promptCachePath := "" if c.PromptCachePath != "" { p := filepath.Join(modelPath, c.PromptCachePath) - os.MkdirAll(filepath.Dir(p), 0750) - promptCachePath = p + err := os.MkdirAll(filepath.Dir(p), 0750) + if err == nil { + promptCachePath = p + } else { + log.Error().Err(err).Str("promptCachePath", promptCachePath).Msg("error creating prompt cache folder") + } } return &pb.PredictOptions{ diff --git a/core/startup/startup.go b/core/startup/startup.go index b9e95ebf..17bbf9f5 100644 --- a/core/startup/startup.go +++ b/core/startup/startup.go @@ -122,7 +122,10 @@ func Startup(opts ...config.AppOption) (*config.BackendConfigLoader, *model.Mode // Watch the configuration directory // If the directory does not exist, we don't watch it configHandler := newConfigFileHandler(options) - configHandler.Watch() + err = configHandler.Watch() + if err != nil { + log.Error().Err(err).Msg("error establishing configuration directory watcher") + } log.Info().Msg("core/startup process completed!") return cl, ml, options, nil diff --git a/embedded/embedded.go b/embedded/embedded.go index c779fc26..438a1352 100644 --- a/embedded/embedded.go +++ b/embedded/embedded.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/go-skynet/LocalAI/pkg/downloader" + "github.com/rs/zerolog/log" "github.com/go-skynet/LocalAI/pkg/assets" "gopkg.in/yaml.v3" @@ -29,7 +30,10 @@ func ModelShortURL(s string) string { } func init() { - yaml.Unmarshal(modelLibrary, &modelShorteners) + err := yaml.Unmarshal(modelLibrary, &modelShorteners) + if err != nil { + log.Error().Err(err).Msg("error while unmarshalling embedded modelLibrary") + } } func GetRemoteLibraryShorteners(url string) (map[string]string, error) { diff --git a/examples/semantic-todo/main.go b/examples/semantic-todo/main.go index 371fe6b9..a8936ea1 100644 --- a/examples/semantic-todo/main.go +++ b/examples/semantic-todo/main.go @@ -239,7 +239,10 @@ func (app *App) updateUI() { task := Task{Description: inputField.GetText()} app.tasks = append(app.tasks, task) app.state = StateRoot - postTasksToExternalService([]Task{task}) + err := postTasksToExternalService([]Task{task}) + if err != nil { + panic(err) + } } app.updateUI() }) diff --git a/main.go b/main.go index 04f13d3f..8fb50184 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,11 @@ func main() { for _, envFile := range envFiles { if _, err := os.Stat(envFile); err == nil { log.Info().Str("envFile", envFile).Msg("loading environment variables from file") - godotenv.Load(envFile) + err = godotenv.Load(envFile) + if err != nil { + log.Error().Err(err).Str("envFile", envFile).Msg("failed to load environment variables from file") + continue + } } } diff --git a/pkg/assets/list.go b/pkg/assets/list.go index 7b705b49..47e60a40 100644 --- a/pkg/assets/list.go +++ b/pkg/assets/list.go @@ -3,10 +3,12 @@ package assets import ( "embed" "io/fs" + + "github.com/rs/zerolog/log" ) func ListFiles(content embed.FS) (files []string) { - fs.WalkDir(content, ".", func(path string, d fs.DirEntry, err error) error { + err := fs.WalkDir(content, ".", func(path string, d fs.DirEntry, err error) error { if err != nil { return err } @@ -18,5 +20,8 @@ func ListFiles(content embed.FS) (files []string) { files = append(files, path) return nil }) + if err != nil { + log.Error().Err(err).Msg("error walking the embedded filesystem") + } return } diff --git a/pkg/grpc/server.go b/pkg/grpc/server.go index 8116241f..8e9f4d68 100644 --- a/pkg/grpc/server.go +++ b/pkg/grpc/server.go @@ -131,10 +131,10 @@ func (s *server) PredictStream(in *pb.PredictOptions, stream pb.Backend_PredictS done <- true }() - s.llm.PredictStream(in, resultChan) + err := s.llm.PredictStream(in, resultChan) <-done - return nil + return err } func (s *server) TokenizeString(ctx context.Context, in *pb.PredictOptions) (*pb.TokenizationResponse, error) {