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 <dave@gray101.com>
This commit is contained in:
Dave 2024-04-26 04:34:31 -04:00 committed by GitHub
parent 44bc540bb5
commit 2cd4936c99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 34 additions and 10 deletions

View File

@ -7,7 +7,8 @@ import (
"github.com/go-skynet/LocalAI/core/config" "github.com/go-skynet/LocalAI/core/config"
pb "github.com/go-skynet/LocalAI/pkg/grpc/proto" 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 { 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 := "" promptCachePath := ""
if c.PromptCachePath != "" { if c.PromptCachePath != "" {
p := filepath.Join(modelPath, c.PromptCachePath) p := filepath.Join(modelPath, c.PromptCachePath)
os.MkdirAll(filepath.Dir(p), 0750) err := os.MkdirAll(filepath.Dir(p), 0750)
if err == nil {
promptCachePath = p promptCachePath = p
} else {
log.Error().Err(err).Str("promptCachePath", promptCachePath).Msg("error creating prompt cache folder")
}
} }
return &pb.PredictOptions{ return &pb.PredictOptions{

View File

@ -122,7 +122,10 @@ func Startup(opts ...config.AppOption) (*config.BackendConfigLoader, *model.Mode
// Watch the configuration directory // Watch the configuration directory
// If the directory does not exist, we don't watch it // If the directory does not exist, we don't watch it
configHandler := newConfigFileHandler(options) 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!") log.Info().Msg("core/startup process completed!")
return cl, ml, options, nil return cl, ml, options, nil

View File

@ -7,6 +7,7 @@ import (
"strings" "strings"
"github.com/go-skynet/LocalAI/pkg/downloader" "github.com/go-skynet/LocalAI/pkg/downloader"
"github.com/rs/zerolog/log"
"github.com/go-skynet/LocalAI/pkg/assets" "github.com/go-skynet/LocalAI/pkg/assets"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
@ -29,7 +30,10 @@ func ModelShortURL(s string) string {
} }
func init() { 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) { func GetRemoteLibraryShorteners(url string) (map[string]string, error) {

View File

@ -239,7 +239,10 @@ func (app *App) updateUI() {
task := Task{Description: inputField.GetText()} task := Task{Description: inputField.GetText()}
app.tasks = append(app.tasks, task) app.tasks = append(app.tasks, task)
app.state = StateRoot app.state = StateRoot
postTasksToExternalService([]Task{task}) err := postTasksToExternalService([]Task{task})
if err != nil {
panic(err)
}
} }
app.updateUI() app.updateUI()
}) })

View File

@ -43,7 +43,11 @@ func main() {
for _, envFile := range envFiles { for _, envFile := range envFiles {
if _, err := os.Stat(envFile); err == nil { if _, err := os.Stat(envFile); err == nil {
log.Info().Str("envFile", envFile).Msg("loading environment variables from file") 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
}
} }
} }

View File

@ -3,10 +3,12 @@ package assets
import ( import (
"embed" "embed"
"io/fs" "io/fs"
"github.com/rs/zerolog/log"
) )
func ListFiles(content embed.FS) (files []string) { 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 { if err != nil {
return err return err
} }
@ -18,5 +20,8 @@ func ListFiles(content embed.FS) (files []string) {
files = append(files, path) files = append(files, path)
return nil return nil
}) })
if err != nil {
log.Error().Err(err).Msg("error walking the embedded filesystem")
}
return return
} }

View File

@ -131,10 +131,10 @@ func (s *server) PredictStream(in *pb.PredictOptions, stream pb.Backend_PredictS
done <- true done <- true
}() }()
s.llm.PredictStream(in, resultChan) err := s.llm.PredictStream(in, resultChan)
<-done <-done
return nil return err
} }
func (s *server) TokenizeString(ctx context.Context, in *pb.PredictOptions) (*pb.TokenizationResponse, error) { func (s *server) TokenizeString(ctx context.Context, in *pb.PredictOptions) (*pb.TokenizationResponse, error) {