diff --git a/.golangci.toml b/.golangci.toml index 245261518..e8c61e0ad 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -7,3 +7,7 @@ tab-width = 2 # there's currently no way to only log violations in golangci-lint # https://github.com/golangci/golangci-lint/issues/1981 # enable = ["lll"] + +[run] +# Don't bother linting test files +skip-files = ["pkg/.*_test.go"] diff --git a/cmd/ast/main.go b/cmd/ast/main.go index c762af5c3..e82eeb3f5 100644 --- a/cmd/ast/main.go +++ b/cmd/ast/main.go @@ -49,7 +49,7 @@ func run(cmd *cobra.Command, args []string) error { if err != nil { return err } - defer z.Sync() // nolint:errcheck + defer z.Sync() //nolint:errcheck defer zap.ReplaceGlobals(z)() if cfg.file == "" { diff --git a/pkg/config/config.go b/pkg/config/config.go index 394f68224..bd3915dd8 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -109,7 +109,7 @@ func ReadConfig(fpath string) (Application, error) { if err != nil { return appCfg, err } - defer f.Close() // nolint:errcheck + defer f.Close() //nolint:errcheck return ReadConfigReader(fpath, f) } diff --git a/pkg/engine2/cli.go b/pkg/engine2/cli.go index 90ae401d7..fa037ed18 100644 --- a/pkg/engine2/cli.go +++ b/pkg/engine2/cli.go @@ -217,7 +217,10 @@ func (em *EngineMain) RunEngine(cmd *cobra.Command, args []string) error { pprof.StopCPUProfile() profileF.Close() }() - pprof.StartCPUProfile(profileF) + err = pprof.StartCPUProfile(profileF) + if err != nil { + return fmt.Errorf("failed to start profile: %w", err) + } } // Set up analytics, and hook them up to the logs diff --git a/pkg/engine2/constraints/constraint.go b/pkg/engine2/constraints/constraint.go index 221113e3f..77d6c6dc1 100644 --- a/pkg/engine2/constraints/constraint.go +++ b/pkg/engine2/constraints/constraint.go @@ -181,7 +181,7 @@ func LoadConstraintsFromFile(path string) (Constraints, error) { if err != nil { return Constraints{}, err } - defer f.Close() // nolint:errcheck + defer f.Close() //nolint:errcheck err = yaml.NewDecoder(f).Decode(&input) if err != nil { diff --git a/pkg/engine2/operational_eval/evaluator.go b/pkg/engine2/operational_eval/evaluator.go index 8c8c2997d..594ce951a 100644 --- a/pkg/engine2/operational_eval/evaluator.go +++ b/pkg/engine2/operational_eval/evaluator.go @@ -323,6 +323,8 @@ func newChanges() graphChanges { } // addNode is a convenient lower-level add for [graphChanges.nodes] +// +//nolint:unused func (changes graphChanges) addNode(v Vertex) { changes.nodes[v.Key()] = v } @@ -434,7 +436,11 @@ func (eval *Evaluator) UpdateId(oldId, newId construct.ResourceId) error { replaceVertex(key, vertex) // because the temp graph contains the src and target as nodes, we need to update it if it exists if vertex.TempGraph != nil { - construct.ReplaceResource(vertex.TempGraph, oldId, &construct.Resource{ID: newId}) + err := construct.ReplaceResource(vertex.TempGraph, oldId, &construct.Resource{ID: newId}) + if err != nil { + errs = errors.Join(errs, err) + continue + } } } } diff --git a/pkg/engine2/operational_eval/graph.go b/pkg/engine2/operational_eval/graph.go index fc391dd20..76ae22969 100644 --- a/pkg/engine2/operational_eval/graph.go +++ b/pkg/engine2/operational_eval/graph.go @@ -84,7 +84,11 @@ func (eval *Evaluator) pathVertices(source, target construct.ResourceId) (graphC generateAndAddVertex := func( edge construct.SimpleEdge, kb knowledgebase.TemplateKB, - satisfication knowledgebase.EdgePathSatisfaction) error { + satisfication knowledgebase.EdgePathSatisfaction, + ) error { + if satisfication.Classification == "" { + return fmt.Errorf("edge %s has no classification to expand", edge) + } buildTempGraph := true // We are checking to see if either of the source or target nodes will change due to property references, diff --git a/pkg/engine2/operational_eval/vertex_internal.go b/pkg/engine2/operational_eval/vertex_internal.go deleted file mode 100644 index 7674f516b..000000000 --- a/pkg/engine2/operational_eval/vertex_internal.go +++ /dev/null @@ -1,19 +0,0 @@ -package operational_eval - -type internalVertex struct { - Internal string -} - -func (v *internalVertex) Key() Key { - return Key{Internal: v.Internal} -} - -func (v *internalVertex) Evaluate(eval *Evaluator) error { - return nil -} - -func (v *internalVertex) UpdateFrom(other Vertex) {} - -func (v *internalVertex) Dependencies(eval *Evaluator) (graphChanges, error) { - return graphChanges{}, nil -} diff --git a/pkg/engine2/operational_eval/vertex_path_expand.go b/pkg/engine2/operational_eval/vertex_path_expand.go index f01300f42..0dff7e355 100644 --- a/pkg/engine2/operational_eval/vertex_path_expand.go +++ b/pkg/engine2/operational_eval/vertex_path_expand.go @@ -21,14 +21,6 @@ type ( TempGraph construct.Graph Satisfication knowledgebase.EdgePathSatisfaction } - - // pathSatisfication is a wrapper around [EdgePathSatisfaction] that makes unset distinguishable - // from expanding on an empty classification. Once all expansions have classification, this can - // be removed and use [EdgePathSatisfaction] directly (`.valid` becomes `.Classification != ""`) - pathSatisfication struct { - knowledgebase.EdgePathSatisfaction - valid bool - } ) func (v *pathExpandVertex) Key() Key { diff --git a/pkg/engine2/operational_rule/operational_step.go b/pkg/engine2/operational_rule/operational_step.go index c08144e4e..57083ee4f 100644 --- a/pkg/engine2/operational_rule/operational_step.go +++ b/pkg/engine2/operational_rule/operational_step.go @@ -6,7 +6,6 @@ import ( "reflect" "github.com/dominikbraun/graph" - "github.com/iancoleman/strcase" construct "github.com/klothoplatform/klotho/pkg/construct2" "github.com/klothoplatform/klotho/pkg/engine2/reconciler" "github.com/klothoplatform/klotho/pkg/engine2/solution_context" @@ -243,17 +242,6 @@ func (ctx OperationalRuleContext) removeDependencyForDirection(direction knowled } } -func (ctx OperationalRuleContext) addResourceName(partialId construct.ResourceId) construct.ResourceId { - // TODO handle cases when multiple resources want to use the same ID, such as `aws:subnet:myvpc:public` by adding an - // incrementing number to them. - if ctx.Property != nil { - partialId.Name = strcase.ToSnake(ctx.Property.Name) - return partialId - } - partialId.Name = fmt.Sprintf("%s_%s", ctx.Data.Edge.Source.Name, ctx.Data.Edge.Target.Name) - return partialId -} - func (ctx OperationalRuleContext) SetField(resource, fieldResource *construct.Resource, step knowledgebase.OperationalStep) error { if ctx.Property == nil { return nil diff --git a/pkg/engine2/path_selection/candidate_validity.go b/pkg/engine2/path_selection/candidate_validity.go index 812a99278..2c294c9b5 100644 --- a/pkg/engine2/path_selection/candidate_validity.go +++ b/pkg/engine2/path_selection/candidate_validity.go @@ -13,14 +13,6 @@ import ( ) type ( - // validityChecker defines methods for checking validity of a candidate based on the operation specified in the - // path satisfaction route. The validityChecker has the ability to both check if a candidate is valid - // and mutate a candidate to be valid - validityChecker interface { - isValid(resourceToCheck, targetResource construct.ResourceId) (bool, error) - makeValid(resource, operationResource construct.ResourceId) error - } - // downstreamChecker is a validityChecker that checks if a candidate is valid based on what is downstream of the specified // resources downstreamChecker struct { @@ -279,11 +271,9 @@ func (d downstreamChecker) makeValid(resource, operationResource *construct.Reso } } if p.IsPropertyTypeScalar() { - currRes.SetProperty(property, downstream) - return true, errs + return true, errors.Join(errs, currRes.SetProperty(property, downstream)) } else { - currRes.AppendProperty(property, downstream) - return true, errs + return true, errors.Join(errs, currRes.AppendProperty(property, downstream)) } } return false, errs diff --git a/pkg/engine2/path_selection/path_expansion.go b/pkg/engine2/path_selection/path_expansion.go index cd442251c..527bf86da 100644 --- a/pkg/engine2/path_selection/path_expansion.go +++ b/pkg/engine2/path_selection/path_expansion.go @@ -433,56 +433,6 @@ func ExpandPath( return nil } -func runOnNamespaces(src, target *construct.Resource, ctx solution_context.SolutionContext, result ExpansionResult) error { - if src.ID.Namespace != "" && target.ID.Namespace != "" { - kb := ctx.KnowledgeBase() - targetNamespaceResourceId, err := kb.GetResourcesNamespaceResource(target) - if targetNamespaceResourceId.IsZero() { - return fmt.Errorf("could not find namespace resource for %s", target) - } - if err != nil { - return err - } - - srcNamespaceResourceId, err := kb.GetResourcesNamespaceResource(src) - if srcNamespaceResourceId.IsZero() { - return fmt.Errorf("could not find namespace resource for %s", src) - } - if err != nil { - return err - } - srcNamespaceResource, err := ctx.RawView().Vertex(srcNamespaceResourceId) - if err != nil { - return err - } - targetNamespaceResource, err := ctx.RawView().Vertex(targetNamespaceResourceId) - if err != nil { - return err - } - // if we have a namespace resource that is not the same as the target namespace resource - tg, err := BuildPathSelectionGraph( - construct.SimpleEdge{Source: srcNamespaceResourceId, Target: targetNamespaceResourceId}, - kb, - "", - ) - if err != nil { - return fmt.Errorf("could not build path selection graph: %w", err) - } - // TODO: We should get all of the as source and as targets here to ensure we have all paths required - input := ExpansionInput{ - Dep: construct.ResourceEdge{Source: srcNamespaceResource, Target: targetNamespaceResource}, - Classification: "", - TempGraph: tg, - } - edges, err := expandEdge(ctx, input, result.Graph) - if err != nil { - return err - } - result.Edges = append(result.Edges, edges...) - } - return nil -} - func connectThroughNamespace(src, target *construct.Resource, ctx solution_context.SolutionContext, result ExpansionResult) ( connected bool, errs error, diff --git a/pkg/graph_loader/loader.go b/pkg/graph_loader/loader.go index 011268dac..984beaab0 100644 --- a/pkg/graph_loader/loader.go +++ b/pkg/graph_loader/loader.go @@ -49,7 +49,7 @@ func LoadConstructGraphFromFile(path string) (*construct.ConstructGraph, error) if err != nil { return graph, err } - defer f.Close() // nolint:errcheck + defer f.Close() //nolint:errcheck err = yaml.NewDecoder(f).Decode(&input) if err != nil { return graph, err @@ -95,7 +95,7 @@ func LoadResourceGraphFromFile(path string) (*construct.ResourceGraph, error) { if err != nil { return graph, err } - defer f.Close() // nolint:errcheck + defer f.Close() //nolint:errcheck err = yaml.NewDecoder(f).Decode(&input) if err != nil { return graph, err diff --git a/pkg/infra/cli2.go b/pkg/infra/cli2.go index 9a273d256..25ee70801 100644 --- a/pkg/infra/cli2.go +++ b/pkg/infra/cli2.go @@ -85,7 +85,10 @@ func GenerateIac(cmd *cobra.Command, args []string) error { pprof.StopCPUProfile() profileF.Close() }() - pprof.StartCPUProfile(profileF) + err = pprof.StartCPUProfile(profileF) + if err != nil { + return fmt.Errorf("failed to start profile: %w", err) + } } var files []io.File diff --git a/pkg/infra/iac3/template_types.go b/pkg/infra/iac3/template_types.go index 492e5906c..1079d9585 100644 --- a/pkg/infra/iac3/template_types.go +++ b/pkg/infra/iac3/template_types.go @@ -35,19 +35,8 @@ type ( } appliedOutputs []appliedOutput - - // undefinedT is a helper type to represent the `undefined` value in a template. It is needed over just using - // "undefined" because the string is not false-y. - undefinedT string ) -// undefined is false-y in a template (if used in an `if`), but resolves to `undefined` when rendered. -var undefined = undefinedT("") - -func (undefinedT) String() string { - return "undefined" -} - func (tc TemplatesCompiler) NewAppliedOutput(ref construct.PropertyRef, name string) appliedOutput { ao := appliedOutput{Name: name} if ao.Name == "" {