state: print encoding error before object

This prevents a very large object string from pushing an error message from
saving (which is usually something informative like "type Foo does not
implement SaverLoader") off the edge of the line. cl/605534648 already did this
for loading.

PiperOrigin-RevId: 631622344
This commit is contained in:
Jamie Liu
2024-05-07 19:17:26 -07:00
committed by gVisor bot
parent 434c4d2536
commit 2e4177ed2d
+1 -1
View File
@@ -772,7 +772,7 @@ func (es *encodeState) Save(obj reflect.Value) {
}
}); err != nil {
// Include the object in the error message.
Failf("encoding error at object %#v: %w", oes.obj.Interface(), err)
Failf("encoding error: %w\nfor object %#v", err, oes.obj.Interface())
}
// Check that we have objects to serialize.