Skip to content

Commit 2fde9fe

Browse files
committed
Better error messages when errors found parsing context.
1 parent 36895d6 commit 2fde9fe

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/json/ld/context.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -410,22 +410,22 @@ def create_term_definition(local_context, term, defined)
410410
begin
411411
expand_iri(type, :vocab => true, :documentRelative => false, :local_context => local_context, :defined => defined)
412412
rescue JsonLdError::InvalidIRIMapping
413-
raise JsonLdError::InvalidTypeMapping, "invalid mapping for '@type': #{type.inspect}"
413+
raise JsonLdError::InvalidTypeMapping, "invalid mapping for '@type': #{type.inspect} on term #{term.inspect}"
414414
end
415415
else
416416
:error
417417
end
418418
unless %w(@id @vocab).include?(type) || type.is_a?(RDF::URI) && type.absolute?
419-
raise JsonLdError::InvalidTypeMapping, "unknown mapping for '@type': #{type.inspect}"
419+
raise JsonLdError::InvalidTypeMapping, "unknown mapping for '@type': #{type.inspect} on term #{term.inspect}"
420420
end
421421
debug("") {"type_mapping: #{type.inspect}"}
422422
definition.type_mapping = type
423423
end
424424

425425
if value.has_key?('@reverse')
426-
raise JsonLdError::InvalidReverseProperty, "unexpected key in #{value.inspect}" if
426+
raise JsonLdError::InvalidReverseProperty, "unexpected key in #{value.inspect} on term #{term.inspect}" if
427427
value.keys.any? {|k| %w(@id).include?(k)}
428-
raise JsonLdError::InvalidIRIMapping, "expected value of @reverse to be a string: #{value['@reverse'].inspect}" unless
428+
raise JsonLdError::InvalidIRIMapping, "expected value of @reverse to be a string: #{value['@reverse'].inspect} on term #{term.inspect}" unless
429429
value['@reverse'].is_a?(String)
430430

431431
# Otherwise, set the IRI mapping of definition to the result of using the IRI Expansion algorithm, passing active context, the value associated with the @reverse key for value, true for vocab, true for document relative, local context, and defined. If the result is not an absolute IRI, i.e., it contains no colon (:), an invalid IRI mapping error has been detected and processing is aborted.
@@ -434,26 +434,26 @@ def create_term_definition(local_context, term, defined)
434434
:documentRelative => true,
435435
:local_context => local_context,
436436
:defined => defined)
437-
raise JsonLdError::InvalidIRIMapping, "non-absolute @reverse IRI: #{definition.id}" unless
437+
raise JsonLdError::InvalidIRIMapping, "non-absolute @reverse IRI: #{definition.id} on term #{term.inspect}" unless
438438
definition.id.is_a?(RDF::URI) && definition.id.absolute?
439439

440440
# If value contains an @container member, set the container mapping of definition to its value; if its value is neither @set, nor @index, nor null, an invalid reverse property error has been detected (reverse properties only support set- and index-containers) and processing is aborted.
441-
if (container = value['@container'])
441+
if (container = value.fetch('@container', false))
442442
raise JsonLdError::InvalidReverseProperty,
443-
"unknown mapping for '@container' to #{container.inspect}" unless
443+
"unknown mapping for '@container' to #{container.inspect} on term #{term.inspect}" unless
444444
['@set', '@index', nil].include?(container)
445445
definition.container_mapping = container
446446
end
447447
definition.reverse_property = true
448448
elsif value.has_key?('@id') && value['@id'] != term
449-
raise JsonLdError::InvalidIRIMapping, "expected value of @id to be a string: #{value['@id'].inspect}" unless
449+
raise JsonLdError::InvalidIRIMapping, "expected value of @id to be a string: #{value['@id'].inspect} on term #{term.inspect}" unless
450450
value['@id'].is_a?(String)
451451
definition.id = expand_iri(value['@id'],
452452
:vocab => true,
453453
:documentRelative => true,
454454
:local_context => local_context,
455455
:defined => defined)
456-
raise JsonLdError::InvalidKeywordAlias, "expected value of @id to not be @context" if
456+
raise JsonLdError::InvalidKeywordAlias, "expected value of @id to not be @context on term #{term.inspect}" if
457457
definition.id == '@context'
458458
elsif term.include?(':')
459459
# If term is a compact IRI with a prefix that is a key in local context then a dependency has been found. Use this algorithm recursively passing active context, local context, the prefix as term, and defined.
@@ -470,7 +470,7 @@ def create_term_definition(local_context, term, defined)
470470
debug("") {"=> #{definition.id}"}
471471
else
472472
# Otherwise, active context must have a vocabulary mapping, otherwise an invalid value has been detected, which is an error. Set the IRI mapping for definition to the result of concatenating the value associated with the vocabulary mapping and term.
473-
raise JsonLdError::InvalidIRIMapping, "relative term definition without vocab: #{term}" unless vocab
473+
raise JsonLdError::InvalidIRIMapping, "relative term definition without vocab: #{term} on term #{term.inspect}" unless vocab
474474
definition.id = vocab + term
475475
debug("") {"=> #{definition.id}"}
476476
end
@@ -479,14 +479,14 @@ def create_term_definition(local_context, term, defined)
479479

480480
if value.has_key?('@container')
481481
container = value['@container']
482-
raise JsonLdError::InvalidContainerMapping, "unknown mapping for '@container' to #{container.inspect}" unless %w(@list @set @language @index).include?(container)
482+
raise JsonLdError::InvalidContainerMapping, "unknown mapping for '@container' to #{container.inspect} on term #{term.inspect}" unless %w(@list @set @language @index).include?(container)
483483
debug("") {"container_mapping: #{container.inspect}"}
484484
definition.container_mapping = container
485485
end
486486

487487
if value.has_key?('@language')
488488
language = value['@language']
489-
raise JsonLdError::InvalidLanguageMapping, "language must be null or a string, was #{language.inspect}}" unless language.nil? || (language || "").is_a?(String)
489+
raise JsonLdError::InvalidLanguageMapping, "language must be null or a string, was #{language.inspect}} on term #{term.inspect}" unless language.nil? || (language || "").is_a?(String)
490490
language = language.downcase if language.is_a?(String)
491491
debug("") {"language_mapping: #{language.inspect}"}
492492
definition.language_mapping = language || false
@@ -495,7 +495,7 @@ def create_term_definition(local_context, term, defined)
495495
term_definitions[term] = definition
496496
defined[term] = true
497497
else
498-
raise JsonLdError::InvalidTermDefinition, "Term definition for #{term.inspect} is an #{value.class}"
498+
raise JsonLdError::InvalidTermDefinition, "Term definition for #{term.inspect} is an #{value.class} on term #{term.inspect}"
499499
end
500500
end
501501

0 commit comments

Comments
 (0)