Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 0 additions & 14 deletions cmd/esc/cli/testdata/open-detailed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,6 @@ environments:
}
}
}
},
"trace": {
"def": {
"begin": {
"line": 0,
"column": 0,
"byte": 0
},
"end": {
"line": 0,
"column": 0,
"byte": 0
}
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ type Environment struct {
ExecutionContext *EvaluatedExecutionContext `json:"executionContext,omitempty"`
}

// WithoutMetadata returns a copy of the receiver without expression, schema, context, and trace metadata. Only the
// Properties field will be present.
func (e Environment) WithoutMetadata() Environment {
return Environment{Properties: NewValue(e.Properties).WithoutTraceMetadata().Value.(map[string]Value)}
}

// GetEnvironmentVariables returns any environment variables defined by the environment.
//
// Environment variables are any scalar values in the top-level `environmentVariables` property. Boolean and
Expand Down
42 changes: 0 additions & 42 deletions eval/testdata/eval/rotate-paths/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -6336,20 +6336,6 @@
}
}
}
},
"trace": {
"def": {
"begin": {
"line": 0,
"column": 0,
"byte": 0
},
"end": {
"line": 0,
"column": 0,
"byte": 0
}
}
}
}
},
Expand Down Expand Up @@ -6393,20 +6379,6 @@
}
}
}
},
"trace": {
"def": {
"begin": {
"line": 0,
"column": 0,
"byte": 0
},
"end": {
"line": 0,
"column": 0,
"byte": 0
}
}
}
}
},
Expand Down Expand Up @@ -6450,20 +6422,6 @@
}
}
}
},
"trace": {
"def": {
"begin": {
"line": 0,
"column": 0,
"byte": 0
},
"end": {
"line": 0,
"column": 0,
"byte": 0
}
}
}
}
}
Expand Down
59 changes: 1 addition & 58 deletions eval/testdata/eval/rotate-state/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -4229,20 +4229,6 @@
}
}
}
},
"trace": {
"def": {
"begin": {
"line": 0,
"column": 0,
"byte": 0
},
"end": {
"line": 0,
"column": 0,
"byte": 0
}
}
}
}
},
Expand All @@ -4268,36 +4254,7 @@
}
}
},
"previous": {
"trace": {
"def": {
"begin": {
"line": 0,
"column": 0,
"byte": 0
},
"end": {
"line": 0,
"column": 0,
"byte": 0
}
}
}
}
},
"trace": {
"def": {
"begin": {
"line": 0,
"column": 0,
"byte": 0
},
"end": {
"line": 0,
"column": 0,
"byte": 0
}
}
"previous": {}
}
}
},
Expand Down Expand Up @@ -4341,20 +4298,6 @@
}
}
}
},
"trace": {
"def": {
"begin": {
"line": 0,
"column": 0,
"byte": 0
},
"end": {
"line": 0,
"column": 0,
"byte": 0
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion eval/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (v *value) export(environment string) esc.Value {
Value: pv,
Secret: v.secret,
Unknown: v.unknown,
Trace: esc.Trace{
Trace: &esc.Trace{
Def: v.def.defRange(environment),
Base: base,
},
Expand Down
28 changes: 26 additions & 2 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Value struct {

// Trace holds information about the expression that computed this value and the value (if any) with which it was
// merged.
Trace Trace `json:"trace"`
Trace *Trace `json:"trace,omitempty"`
}

// NewValue creates a new value with the given representation.
Expand All @@ -72,6 +72,7 @@ func NewSecret[T ValueType](v T) Value {
return Value{Value: v, Secret: true}
}

// MakeSecret converts this value to a secret.
func (v Value) MakeSecret() Value {
switch v := v.Value.(type) {
case bool:
Expand Down Expand Up @@ -103,7 +104,7 @@ func (v *Value) UnmarshalJSON(data []byte) error {
Value json.RawMessage `json:"value,omitempty"`
Secret bool `json:"secret,omitempty"`
Unknown bool `json:"unknown,omitempty"`
Trace Trace `json:"trace"`
Trace *Trace `json:"trace,omitempty"`
}
if err := json.Unmarshal(data, &raw); err != nil {
return err
Expand Down Expand Up @@ -184,6 +185,29 @@ func fromJSON(path string, v any) (Value, error) {
}
}

// WithoutTraceMetadata returns a copy of the receiver with all trace metadata recursively removed.
func (v Value) WithoutTraceMetadata() Value {
vv := v
vv.Trace = nil

switch pv := v.Value.(type) {
case []Value:
a := make([]Value, len(pv))
for i, v := range pv {
a[i] = v.WithoutTraceMetadata()
}
vv.Value = a
case map[string]Value:
m := make(map[string]Value, len(pv))
for k, v := range pv {
m[k] = v.WithoutTraceMetadata()
}
vv.Value = m
}

return vv
}

// ToJSON converts a Value into a plain-old-JSON value (i.e. a value of type nil, bool, json.Number, string, []any, or
// map[string]any). If redact is true, secrets are replaced with [secret].
func (v Value) ToJSON(redact bool) any {
Expand Down
Loading