@@ -88,6 +88,7 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
8888 */
8989 resolve ( obj : S , options ?: O , pathFromRoot ?: string ) {
9090 const tokens = Pointer . parse ( this . path , this . originalPath ) ;
91+ const found : any = [ ] ;
9192
9293 // Crawl the object, one token at a time
9394 this . value = unwrapOrThrow ( obj ) ;
@@ -103,6 +104,7 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
103104 }
104105
105106 const token = tokens [ i ] ;
107+
106108 if ( this . value [ token ] === undefined || ( this . value [ token ] === null && i === tokens . length - 1 ) ) {
107109 // one final case is if the entry itself includes slashes, and was parsed out as a token - we can join the remaining tokens and try again
108110 let didFindSubstringSlashMatch = false ;
@@ -120,10 +122,23 @@ class Pointer<S extends object = JSONSchema, O extends ParserOptions<S> = Parser
120122 }
121123
122124 this . value = null ;
123- throw new MissingPointerError ( token , decodeURI ( this . originalPath ) ) ;
125+
126+ let path : any = '' ;
127+
128+ if ( path !== undefined ) {
129+ path = this . $ref . path ;
130+ }
131+
132+ const targetRef = this . path . replace ( path , '' ) ;
133+ const targetFound = Pointer . join ( '' , found ) ;
134+ const parentPath = pathFromRoot ?. replace ( path , '' ) ;
135+
136+ throw new MissingPointerError ( token , decodeURI ( this . originalPath ) , targetRef , targetFound , parentPath ) ;
124137 } else {
125138 this . value = this . value [ token ] ;
126139 }
140+
141+ found . push ( token )
127142 }
128143
129144 // Resolve the final value
0 commit comments