-
-
Notifications
You must be signed in to change notification settings - Fork 995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Improve *-all error message output #722
Open
msvechla
wants to merge
11
commits into
gruntwork-io:main
Choose a base branch
from
msvechla:detailed-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4235479
initial draft of detailed errors
msvechla b68b1ef
refactoring
msvechla 0053f8b
refactor to use standard MultiError
msvechla c6abfd9
refactor to use standard MultiError
msvechla 1fa02b3
cleanup unused change
msvechla 09a26c9
duplicate stderr stream so we can process the errors separately
msvechla e0aafd6
Move non error output from stderr to stdout
msvechla b6d4aec
Revert "Move non error output from stderr to stdout"
msvechla ad68cec
remove auto-init pollution from stderr and move formatting to function
msvechla 6068be2
add module and integration tests
msvechla c56c680
separate detailed errors from normal errors, fix tests
msvechla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package configstack | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"strings" | ||
"sync" | ||
|
||
|
@@ -27,6 +29,8 @@ type runningModule struct { | |
Dependencies map[string]*runningModule | ||
NotifyWhenDone []*runningModule | ||
FlagExcluded bool | ||
OutStream bytes.Buffer | ||
Writer io.Writer | ||
} | ||
|
||
// This controls in what order dependencies should be enforced between modules | ||
|
@@ -48,6 +52,7 @@ func newRunningModule(module *TerraformModule) *runningModule { | |
Dependencies: map[string]*runningModule{}, | ||
NotifyWhenDone: []*runningModule{}, | ||
FlagExcluded: module.FlagExcluded, | ||
Writer: module.TerragruntOptions.Writer, | ||
} | ||
} | ||
|
||
|
@@ -130,6 +135,7 @@ func removeFlagExcluded(modules map[string]*runningModule) map[string]*runningMo | |
Err: module.Err, | ||
NotifyWhenDone: module.NotifyWhenDone, | ||
Status: module.Status, | ||
Writer: module.Module.TerragruntOptions.Writer, | ||
} | ||
|
||
// Only add dependencies that should not be excluded | ||
|
@@ -154,6 +160,8 @@ func runModules(modules map[string]*runningModule) error { | |
waitGroup.Add(1) | ||
go func(module *runningModule) { | ||
defer waitGroup.Done() | ||
module.Module.TerragruntOptions.Writer = &module.OutStream | ||
module.Module.TerragruntOptions.ErrWriter = &module.OutStream | ||
module.runModuleWhenReady() | ||
}(module) | ||
} | ||
|
@@ -170,9 +178,17 @@ func collectErrors(modules map[string]*runningModule) error { | |
for _, module := range modules { | ||
if module.Err != nil { | ||
errs = append(errs, module.Err) | ||
|
||
// send all non dependency errors to the DetailedErrorChan | ||
if _, isDepErr := module.Err.(DependencyFinishedWithError); !isDepErr { | ||
DetailedErrorChan <- map[string]string{module.Module.Path: module.OutStream.String()} | ||
} | ||
} | ||
} | ||
|
||
// close the DetailedErrorChan after all errors have been sent | ||
close(DetailedErrorChan) | ||
|
||
if len(errs) == 0 { | ||
return nil | ||
} else { | ||
|
@@ -223,6 +239,7 @@ func (module *runningModule) runNow() error { | |
module.Module.TerragruntOptions.Logger.Printf("Running module %s now", module.Module.Path) | ||
return module.Module.TerragruntOptions.RunTerragrunt(module.Module.TerragruntOptions) | ||
} | ||
|
||
} | ||
|
||
// Record that a module has finished executing and notify all of this module's dependencies | ||
|
@@ -233,6 +250,9 @@ func (module *runningModule) moduleFinished(moduleErr error) { | |
module.Module.TerragruntOptions.Logger.Printf("Module %s has finished with an error: %v", module.Module.Path, moduleErr) | ||
} | ||
|
||
// print the separated module output | ||
fmt.Fprintf(module.Writer, "%s\n%v\n\n%v\n", OutputMessageSeparator, module.Module.Path, module.OutStream.String()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
|
||
module.Status = Finished | ||
module.Err = moduleErr | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused by this... You're overwriting
TerragruntOptions.ErrWriter
to write to bothmodule.OutStream
andmodule.ErrStream
... But what was theTerragrunt.LOptions.ErrWriter
value set to before that? Aremodule.OutStream
andmodule.ErrStream
initialized to anything? Will this buffer those errors until the very end or stream tostdout
/stderr
?Same questions go for
TerragruntOptions.Writer
, with the additional one of what happens when you point a second item tomodule.OutStream
?