Skip to content

Commit c46dbea

Browse files
szhGitHub Enterprise
authored and
GitHub Enterprise
committed
Merge pull request #21 from Conjur-Enterprise/no-env-error-msg
CNJR-0000: Fix unhelpful error message when specifying nonexistent en…
2 parents c638358 + fb6f25b commit c46dbea

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [0.10.3] - 2025-02-07
10+
11+
### Fixed
12+
- Fix unhelpful error message when specifying nonexistent environment
13+
[cyberark/summon#63](https://github.com/cyberark/summon-conjur/issues/63)
14+
915
## [0.10.2] - 2025-01-10
1016

1117
### Changed

pkg/secretsyml/secretsyml.go

+7
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ func parseEnvironment(ymlContent, env string, subs map[string]string) (SecretsMa
153153
out := make(map[string]SecretsMap)
154154

155155
if err := yaml.Unmarshal([]byte(ymlContent), &out); err != nil {
156+
// Check if the error is due to there being no environment sections
157+
if _, err = parseRegular(ymlContent, subs); err == nil {
158+
// If a regular parse is successful, then the error is due to the environment not existing
159+
return nil, fmt.Errorf("No such environment '%v' found in secrets file", env)
160+
}
161+
162+
// Otherwise, return the YAML parsings original error
156163
return nil, err
157164
}
158165

pkg/secretsyml/secretsyml_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,22 @@ MissingEnvironment:
168168
})
169169
})
170170

171+
t.Run("Given an environment with no sections", func(t *testing.T) {
172+
testEnv := "TestEnvironment"
173+
// This input has no environment sections, but the environment is specified
174+
input := `SOME_VAR: value`
175+
176+
t.Run("It should error", func(t *testing.T) {
177+
_, err := ParseFromString(input, testEnv, map[string]string{"env": "prod"})
178+
assert.Error(t, err)
179+
180+
// Should return the same error message as before, not a YAML parsing error
181+
errMessage := fmt.Sprintf("No such environment '%v' found in secrets file", testEnv)
182+
assert.EqualError(t, err, errMessage)
183+
})
184+
})
185+
186+
171187
t.Run("Given a common section and environment ", func(t *testing.T) {
172188
testEnv := "TestEnvironment"
173189
input := `common:

0 commit comments

Comments
 (0)