Skip to content

Commit

Permalink
Merge pull request #305 from javiercri/issue-302-ensure-dir-exists
Browse files Browse the repository at this point in the history
Fix issue 302. Show error when dir is missing
  • Loading branch information
Daniel Esponda authored Jan 28, 2022
2 parents 7cf7d39 + 50b3927 commit 1c551d7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions config-reloader/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ type Generator struct {
su datasource.StatusUpdater
}

func ensureDirExists(dir string) {
func ensureDirExists(dir string) error {
if _, err := os.Stat(dir); os.IsNotExist(err) {
_ = os.Mkdir(dir, maskDirectory)
err = os.Mkdir(dir, maskDirectory)
if err != nil {
logrus.Errorln("Unexpected error occurred with output config directory: ", dir)
return err
}
}
return nil
}

func (g *Generator) makeNamespaceConfiguration(ns *datasource.NamespaceConfig, genCtx *processors.GenerationContext, mode int) (string, string, error) {
Expand Down Expand Up @@ -351,7 +356,10 @@ func (g *Generator) CleanupUnusedFiles(outputDir string, namespaces map[string]s

// RenderToDisk write only valid configurations to disk
func (g *Generator) RenderToDisk(ctx context.Context, outputDir string) (map[string]string, error) {
ensureDirExists(outputDir)
err := ensureDirExists(outputDir)
if err != nil {
return nil, err
}
outputDir, _ = filepath.Abs(outputDir)
res := map[string]string{}

Expand Down

0 comments on commit 1c551d7

Please sign in to comment.