diff --git a/lib/pointer.ts b/lib/pointer.ts index 44292609..ed6b9586 100644 --- a/lib/pointer.ts +++ b/lib/pointer.ts @@ -92,6 +92,8 @@ class Pointer { // Crawl the object, one token at a time this.value = unwrapOrThrow(obj); + const errors: MissingPointerError[] = []; + for (let i = 0; i < tokens.length; i++) { if (resolveIf$Ref(this, options, pathFromRoot)) { // The $ref path has changed, so append the remaining tokens to the path @@ -120,12 +122,16 @@ class Pointer { } this.value = null; - throw new MissingPointerError(token, decodeURI(this.originalPath)); + errors.push(new MissingPointerError(token, decodeURI(this.originalPath))); } else { this.value = this.value[token]; } } + if (errors.length > 0) { + throw errors.length === 1 ? errors[0] : new AggregateError(errors, "Multiple missing pointer errors"); + } + // Resolve the final value if (!this.value || (this.value.$ref && url.resolve(this.path, this.value.$ref) !== pathFromRoot)) { resolveIf$Ref(this, options, pathFromRoot);