ruby-rdf / json-ld

Ruby JSON-LD reader/writer for RDF.rb
The Unlicense
232 stars 27 forks source link

Error always mentions stdin, and not the real filename #38

Closed mitar closed 7 years ago

mitar commented 7 years ago

I run the program:

$ jsonld --expand in.json 
Error in -stdin-
/Users/user/.gem/ruby/2.4.0/gems/json-ld-2.1.3/lib/json/ld/context.rb:653:in `create_term_definition': invalid term definition: @context not valid in term definition for JSON-LD 1.0 (JSON::LD::JsonLdError::InvalidTermDefinition)

I would expect that the error was Error in in.json. Hopefully maybe even the file line and column in which the error happens (or JSON path/pointer or something). It might be that there are multiple @contexts present in a file. From the error message it is hard to kw which one is a problem.

gkellogg commented 7 years ago

Fixed a couple of issues you noted. Getting line/column or JSON pointer not really feasible, as first pass turns JSON into Ruby representation and such information is not available. Constructing a JSON pointer could be possible, but not something I have time to tackle.

mitar commented 7 years ago

Hm, does this addresses that the output is Error in -stdin- despite me passing a filename in?

gkellogg commented 7 years ago

Yes, the problem is that remote files are loaded using something other than File.open, so path was not an accessor. It no uses either requested_url, or base_uri, depending.

mitar commented 7 years ago

Oh, I understand, that error is not coming from some other remote file and not in.json?

gkellogg commented 7 years ago

In this case, the error comes form a context definition for the term B, which is inline (there is no remote context). As mentioned, the use of JSON-LD 1.1 features requires announcement, typically using the @version property in the context. The updated error message attempts to clarify this.

The filename is reported based on that passed in, not one found through context resolution. In a perfect world, the exception would record the context URL used to resolve the issue, but it's not currently available. But, with knowledge of what term it is that's causing the problem, it should be straightforward to track it down.

Good error reporting is about the most difficult thing of all. And, I need to leave something for other contributors to do 😄; that's the beauty of open-source.

mitar commented 7 years ago

:-)

Thanks for all the explanation and all the work. :-) All this really looks amazing already.