mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
keep the friendly error message whenever possible
This commit is contained in:
parent
727e22e762
commit
30f8b014f8
@ -244,14 +244,28 @@ func (c *InitCommand) Run(args []string) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
// If the core version is OK, show any underlying config errors uncovered when initializing
|
||||
// the backend.
|
||||
diags = diags.Append(backDiags)
|
||||
if backDiags.HasErrors() {
|
||||
c.showDiagnostics(diags)
|
||||
return 1
|
||||
// If we pass the core version check, we want to show any errors from initializing the backend next,
|
||||
// which will include syntax errors from loading the configuration. However, there's a special case
|
||||
// where we are unable to load the backend from configuration or state _and_ the configuration has
|
||||
// errors. In that case, we want to show a slightly friendlier error message for newcomers.
|
||||
showBackendDiags := back != nil || rootModEarly.Backend != nil || rootModEarly.CloudConfig != nil
|
||||
if showBackendDiags {
|
||||
diags = diags.Append(backDiags)
|
||||
if backDiags.HasErrors() {
|
||||
c.showDiagnostics(diags)
|
||||
return 1
|
||||
}
|
||||
} else {
|
||||
diags = diags.Append(earlyConfDiags)
|
||||
if earlyConfDiags.HasErrors() {
|
||||
c.Ui.Error(strings.TrimSpace(errInitConfigError))
|
||||
c.showDiagnostics(diags)
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
// If everything is ok with the core version check and backend initialization,
|
||||
// show other errors from loading the full configuration tree.
|
||||
diags = diags.Append(confDiags)
|
||||
if confDiags.HasErrors() {
|
||||
c.Ui.Error(strings.TrimSpace(errInitConfigError))
|
||||
|
Loading…
Reference in New Issue
Block a user