Skip to content
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: Errors block #3584

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Errors clonning
  • Loading branch information
denis256 committed Nov 22, 2024
commit d514e9e44d415f3f2466c50d20c5b73d9a155e36
2 changes: 1 addition & 1 deletion config/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ func getOutputJSONWithCaching(ctx *ParsingContext, targetConfig string) ([]byte,
// - The config path to the dependency module's config
// - The original config path to the dependency module's config
//
// That way, everything in that dependnecy happens within its own ctx.
// That way, everything in that dependency happens within its own ctx.
func cloneTerragruntOptionsForDependency(ctx *ParsingContext, targetConfigPath string) (*options.TerragruntOptions, error) {
targetOptions, err := ctx.TerragruntOptions.Clone(targetConfigPath)
if err != nil {
Expand Down
58 changes: 58 additions & 0 deletions config/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,64 @@ type IgnoreConfig struct {
Signals map[string]interface{} `hcl:"signals,optional"`
}

func (c *ErrorsConfig) Clone() *ErrorsConfig {
if c == nil {
return nil
}

clone := &ErrorsConfig{
Retry: make(map[string]*RetryConfig),
Ignore: make(map[string]*IgnoreConfig),
}

for k, v := range c.Retry {
clone.Retry[k] = v.Clone()
}

for k, v := range c.Ignore {
clone.Ignore[k] = v.Clone()
}

return clone
}

func (c *RetryConfig) Clone() *RetryConfig {
if c == nil {
return nil
}

retryableErrors := make([]string, len(c.RetryableErrors))
copy(retryableErrors, c.RetryableErrors)

return &RetryConfig{
Name: c.Name,
RetryableErrors: retryableErrors,
MaxAttempts: c.MaxAttempts,
SleepIntervalSec: c.SleepIntervalSec,
}
}

func (c *IgnoreConfig) Clone() *IgnoreConfig {
if c == nil {
return nil
}

ignorableErrors := make([]string, len(c.IgnorableErrors))
copy(ignorableErrors, c.IgnorableErrors)

signals := make(map[string]interface{})
for k, v := range c.Signals {
signals[k] = v
}

return &IgnoreConfig{
Name: c.Name,
IgnorableErrors: ignorableErrors,
Message: c.Message,
Signals: signals,
}
}

// Custom error types

type InvalidArgError string
Expand Down
6 changes: 6 additions & 0 deletions options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"path/filepath"
"time"

"github.com/gruntwork-io/terragrunt/config"

"github.com/gruntwork-io/terragrunt/internal/errors"
"github.com/gruntwork-io/terragrunt/pkg/log"
"github.com/gruntwork-io/terragrunt/pkg/log/format"
Expand Down Expand Up @@ -365,6 +367,9 @@ type TerragruntOptions struct {
// ReadFiles is a map of files to the Units
// that read them using HCL functions in the unit.
ReadFiles map[string][]string

// ErrorsConfig is a configuration for error handling.
ErrorsConfig *config.ErrorsConfig
}

// TerragruntOptionsFunc is a functional option type used to pass options in certain integration tests
Expand Down Expand Up @@ -641,6 +646,7 @@ func (opts *TerragruntOptions) Clone(terragruntConfigPath string) (*TerragruntOp
// copy array
StrictControls: util.CloneStringList(opts.StrictControls),
FeatureFlags: opts.FeatureFlags,
ErrorsConfig: opts.ErrorsConfig,
}, nil
}

Expand Down