Skip to content

Commit

Permalink
Avoid panic when searching for .regal/config.yaml
Browse files Browse the repository at this point in the history
As reported in #682, the server panics when the dir for whatever reason
is "". I don't yet know how to trigger this, and the result of this fix
is likely that the config file won't be found when this happens. But as
a temporary measure I prefer to have Regal run with default configuration
compared to crashing.

Signed-off-by: Anders Eknert <anders@styra.com>
  • Loading branch information
anderseknert committed Apr 25, 2024
1 parent e42be60 commit 311603c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func lint(args []string, params *lintCommandParams) (report.Report, error) {
}

regal = regal.WithUserConfig(userConfig)
case err != nil && params.configFile != "":
case params.configFile != "":
return report.Report{}, fmt.Errorf("user-provided config file not found: %w", err)
case params.debug:
log.Println("no user-provided config file found, will use the default config")
Expand Down
6 changes: 6 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ func FindRegalDirectory(path string) (*os.File, error) {

// Move up one level in the directory tree
parts := strings.Split(dir, rio.PathSeparator)
if len(parts) == 0 {
// See https://github.com/StyraInc/regal/issues/682
// Not sure how we could get here, but we need to stop if we do
return nil, errors.New("stopping as dir is empty string")
}

parts = parts[:len(parts)-1]

if parts[0] == volume {
Expand Down

0 comments on commit 311603c

Please sign in to comment.