-
-
Notifications
You must be signed in to change notification settings - Fork 971
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
Suppressing 423
error in Terragrunt Provider Cache
#3453
Conversation
423
error suppression in Terragrunt Provider Cache423
error in Terragrunt Provider Cache
423
error in Terragrunt Provider Cache423
error in Terragrunt Provider Cache
internal/errors/errors.go
Outdated
|
||
// WithPanicHandling wraps every command you add to *cli.App to handle panics by logging them with a stack trace and returning | ||
// an error up the chain. | ||
func WithPanicHandling(action func(c *cli.Context) error) func(c *cli.Context) error { |
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.
WithPanicHandling
seems to be unused, is it intended?
$ grep -irn "WithPanicHandling" .
./internal/errors/errors.go:106:// WithPanicHandling wraps every command you add to *cli.App to handle panics by logging them with a stack trace and returning
./internal/errors/errors.go:108:func WithPanicHandling(action func(c *cli.Context) error) func(c *cli.Context) error
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.
Indeed. Removed.
internal/errors/errors.go
Outdated
} | ||
|
||
// ErrorWithExitCode is a custom error that is used to specify the app exit code. | ||
type ErrorWithExitCode struct { |
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.
Should the name conform to the XxxError
format?
Like ExitCodeError
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.
Renamed.
@@ -951,11 +951,11 @@ func TestAwsMockOutputsFromRemoteState(t *testing.T) { //nolint: paralleltest | |||
require.NoError(t, os.Remove(filepath.Join(environmentPath, "/app1/.terraform/terraform.tfstate"))) | |||
require.NoError(t, os.RemoveAll(filepath.Join(environmentPath, "/app1/.terraform"))) | |||
|
|||
_, stderr, err := runTerragruntCommandWithOutput(t, fmt.Sprintf("terragrunt init --terragrunt-fetch-dependency-output-from-state --terragrunt-non-interactive --terragrunt-working-dir %s/app2", environmentPath)) |
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.
Seems to fail test TestAwsMockOutputsFromRemoteState
after multiple CI reruns
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.
Fixed.
I noticed strict linter complaining about some moved code, most probably we need another issue to address the findings
|
Something is not right with error handling I suspect
|
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.
Nothing major in my review. I'll avoid submitting approval, as it seems Denis has found some significant issues with error handling.
@@ -165,7 +165,7 @@ func (module *RunningModule) moduleFinished(moduleErr error) { | |||
if moduleErr == nil { | |||
module.Module.TerragruntOptions.Logger.Debugf("Module %s has finished successfully!", module.Module.Path) | |||
} else { | |||
module.Module.TerragruntOptions.Logger.Errorf("Module %s has finished with an error: %v", module.Module.Path, moduleErr) | |||
module.Module.TerragruntOptions.Logger.Errorf("Module %s has finished with an error", module.Module.Path) |
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.
Why aren't we wrapping moduleErr
here?
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.
We display this error in the last steps. Since this error contains multiple lines, it is better to avoid duplicating it in the log.
configstack/test_helpers_test.go
Outdated
errors.As(actualError, &multiError) | ||
require.NotNil(t, multiError, "Expected a MutliError, but got: %v", actualError) | ||
|
||
assert.Equal(t, len(expectedErrors), len(multiError.Errors)) |
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.
Would assert.Len
have been more useful here?
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.
It definitely fits better. Thanks.
@@ -0,0 +1,31 @@ | |||
package errors |
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.
Why is this better than using the standard library directly? It seems to me that we should just use the standard library running Is
, As
, etc.
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.
This is just for convenience, in order not to have extra imports that require manual assignment of aliases.
import goerrors "errors"
internal/os/exec/cmd.go
Outdated
} | ||
|
||
// RegisterGracefullyShutdown registers a graceful shutdown for the command in two ways: | ||
// 1. If the context cacnel contains a cause with a signal, this means that Terragrunt received the signal from the OS, |
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.
// 1. If the context cacnel contains a cause with a signal, this means that Terragrunt received the signal from the OS, | |
// 1. If the context cancel contains a cause with a signal, this means that Terragrunt received the signal from the OS, |
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.
Thanks.
internal/os/exec/cmd.go
Outdated
}, sig) | ||
|
||
if cmd.forwardSignalDelay > 0 { | ||
cmd.logger.Infof("%s signal will be forwarded to %s with delay %s", |
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.
Just double-checking here: Are you sure this should be in info?
internal/os/exec/cmd.go
Outdated
|
||
// SendSignal sends the given `sig` to the executed command. | ||
func (cmd *Cmd) SendSignal(sig os.Signal) { | ||
cmd.logger.Infof("%s signal is forwarded to %s", cases.Title(language.English).String(sig.String()), cmd.filename) |
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.
Just double-checking here: Are you sure this should this be in info?
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.
No, you are most likely right, changed to Debug
cmd.logger.Infof("%s signal is forwarded to %s", cases.Title(language.English).String(sig.String()), cmd.filename) | ||
|
||
if err := cmd.Process.Signal(sig); err != nil { | ||
cmd.logger.Errorf("Failed to forwarding signal %s to %s: %v", sig, cmd.filename, err) |
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.
Why isn't this error being wrapped via %w
?
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.
This is a log message, not returned error. I actually do not really know if there is a sense to wrap it when we display it as a text.
internal/os/exec/cmd_unix_test.go
Outdated
runChannel <- cmd.Run() | ||
}() | ||
|
||
time.Sleep(1000 * time.Millisecond) |
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.
This might be a dumb question, but why aren't we waiting 1 * time.Second
?
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 didn't pay attention, and you're right, I fixed it.
internal/os/exec/cmd_unix_test.go
Outdated
runChannel <- cmd.Run() | ||
}() | ||
|
||
time.Sleep(1000 * time.Millisecond) |
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.
Same potentially dumb question here.
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 didn't pay attention, and you're right, I fixed it.
if opts.JSONLogFormat && opts.TerraformLogsToJSON { | ||
logger := opts.Logger.WithField("workingDir", opts.WorkingDir).WithField("executedCommandArgs", args) | ||
outWriter = logger.WithOptions(log.WithOutput(errWriter)).Writer() | ||
errWriter = logger.WithOptions(log.WithOutput(errWriter)).WriterLevel(log.ErrorLevel) | ||
} else if command == opts.TerraformPath { |
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.
Nice.
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.
Thanks.
Fixed. |
I fixed almost everything except the functions that are too long. |
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.
👍
|
||
// Errorf creates a new error with the given format and values. | ||
// It can be used as a drop-in replacement for fmt.Errorf() to provide descriptive errors in return values. | ||
// If none of the given values contains an stack trace, it will be created. |
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.
"a stack trace" (in all places)
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.
Ah, thanks, I will fix it in the next PR.
Description
Fixes #3430.
Fixes #3420.
TODOs
Read the Gruntwork contribution guidelines.
Release Notes (draft)
Added / Removed / Updated [X].
Migration Guide