diff --git a/.changelog/4257.txt b/.changelog/4257.txt new file mode 100644 index 00000000000..98f254a2a7e --- /dev/null +++ b/.changelog/4257.txt @@ -0,0 +1,3 @@ +```release-note:bug +cli/context: fix possible error when listing contexts if a non waypoint context file exists in the context directory +``` \ No newline at end of file diff --git a/internal/clicontext/storage.go b/internal/clicontext/storage.go index f6c7502f527..7b1c176f419 100644 --- a/internal/clicontext/storage.go +++ b/internal/clicontext/storage.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" ) // Storage is the primary struct for interacting with stored CLI contexts. @@ -50,7 +51,10 @@ func (m *Storage) List() ([]string, error) { continue } - result = append(result, m.nameFromPath(n)) + // filter out possible non .hcl files + if strings.HasSuffix(n, ".hcl") { + result = append(result, m.nameFromPath(n)) + } } return result, nil