Skip to content

Some valid Path values cannot be applied to their source Value #180

@jbardin

Description

@jbardin

A Value containing a set cannot use the path argument within a Transform callback for all paths.

Given an object like so:

ObjectVal(map[string]Value{
  "set": SetVal([]Value{
    ObjectVal(map[string]Value{
      "attr": StringVal("val"),
    }),
  }),
})

Using Transform to obtain each step's value from another object will encounter a path which cannot be used.

// using the same value to ensure all paths are valid, and should result in the same value
Transform(val, func(p Path, v Value) (Value, error) {
    return p.Apply(val)
})

This results in at step 1: key value not number or string when the path is for

cty.Path{cty.GetAttrStep{Name:"set"}, cty.IndexStep{Key:cty.ObjectVal(map[string]cty.Value{"attr":cty.StringVal("val")})}, cty.GetAttrStep{Name:"attr"}}

I'm not sure how we would intend to handle this. Sets are not currently index-able, so simply skipping the key value not number or string check doesn't work. Should we make all Path values valid for Apply on a correctly shaped Value, have special handling to detect when a set is encountered in the path, or maybe just document this as a potential hazard within Transform and Walk?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions