When formatDescriptor() is called on a deserialized descriptor of an object with a self-referential property at a nesting depth beyond maxDepth, it may throw a PointerLookupError.
MRE:
const value = {};
const actualDescriptor = concordance.describe({
a: {
b: value
},
c: value
});
const serializedActual = concordance.serialize(actualDescriptor);
const deserializedActual = concordance.deserialize(serializedActual);
concordance.formatDescriptor(deserializedActual, {maxDepth: 1});
The deeply-nested self-reference occurs at a depth greater than maxDepth
The shallow self-reference occurs at a depth at most maxDepth
The name of the property containing the deeply-nested self-reference is lexically less than the name of the property containing the shallow self-reference
I believe the problem to be that the descriptor is deserialized lazily, and the formatter never calls upon the deeply-nested self-referential value, so when the shallow self-reference is called upon, its pointer references a descriptor that hasn't been deserialized yet.
I first encountered this in AVA, where it can cause an error to be thrown when a snapshot assertion comparing against such a value fails.
When
formatDescriptor()
is called on a deserialized descriptor of an object with a self-referential property at a nesting depth beyondmaxDepth
, it may throw aPointerLookupError
.MRE:
This throws:
To reproduce the issue, the following must hold:
maxDepth
is non-zeromaxDepth
maxDepth
I believe the problem to be that the descriptor is deserialized lazily, and the formatter never calls upon the deeply-nested self-referential value, so when the shallow self-reference is called upon, its pointer references a descriptor that hasn't been deserialized yet.
I first encountered this in AVA, where it can cause an error to be thrown when a snapshot assertion comparing against such a value fails.
I'm working on a PR that may fix this presently.