Skip to content

Commit 01b0064

Browse files
committed
cue: use unwrapJSONError in the entrypoint API only
It's already called from Value.MarshalJSON, the exported API, so there's no need to call it from the internal APIs it calls too. Any errors that structValue.marshalJSON or marshalList return are already unwrapped by Value.MarshalJSON before returning. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I01ca43692b9d1c315c501df01240d42a1c8b5324 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201806 Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 97f622b commit 01b0064

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

cue/types.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,20 @@ func (o *hiddenStructValue) Lookup(key string) Value {
143143

144144
// MarshalJSON returns a valid JSON encoding or reports an error if any of the
145145
// fields is invalid.
146-
func (o *structValue) marshalJSON() (b []byte, err errors.Error) {
146+
func (o *structValue) marshalJSON() (b []byte, err error) {
147147
b = append(b, '{')
148148
n := o.Len()
149149
for i := range n {
150150
k, v := o.At(i)
151151
s, err := internaljson.Marshal(k)
152152
if err != nil {
153-
return nil, unwrapJSONError(err)
153+
return nil, err
154154
}
155155
b = append(b, s...)
156156
b = append(b, ':')
157157
bb, err := internaljson.Marshal(v)
158158
if err != nil {
159-
return nil, unwrapJSONError(err)
159+
return nil, err
160160
}
161161
b = append(b, bb...)
162162
if i < n-1 {
@@ -294,13 +294,13 @@ func (i *hiddenIterator) IsDefinition() bool {
294294

295295
// marshalJSON iterates over the list and generates JSON output. HasNext
296296
// will return false after this operation.
297-
func marshalList(l *Iterator) (b []byte, err errors.Error) {
297+
func marshalList(l *Iterator) (b []byte, err error) {
298298
b = append(b, '[')
299299
if l.Next() {
300300
for i := 0; ; i++ {
301301
x, err := internaljson.Marshal(l.Value())
302302
if err != nil {
303-
return nil, unwrapJSONError(err)
303+
return nil, err
304304
}
305305
b = append(b, x...)
306306
if !l.Next() {

0 commit comments

Comments
 (0)