Skip to content

Commit ba4e891

Browse files
committed
Improve some error messages when processing context.
1 parent 08af646 commit ba4e891

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/json/ld/context.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def parse(local_context, remote_contexts = [])
339339
end
340340
else
341341
# 3.3) If context is not a JSON object, an invalid local context error has been detected and processing is aborted.
342-
raise JsonLdError::InvalidLocalContext
342+
raise JsonLdError::InvalidLocalContext, context.inspect
343343
end
344344
end
345345
end
@@ -369,15 +369,15 @@ def create_term_definition(local_context, term, defined)
369369
when nil
370370
defined[term] = false
371371
else
372-
raise JsonLdError::CyclicIRIMapping, "Cyclical term dependency found for #{term.inspect}"
372+
raise JsonLdError::CyclicIRIMapping, "Cyclical term dependency found: #{term.inspect}"
373373
end
374374

375375
# Since keywords cannot be overridden, term must not be a keyword. Otherwise, an invalid value has been detected, which is an error.
376376
if KEYWORDS.include?(term) && !%w(@vocab @language).include?(term)
377-
raise JsonLdError::KeywordRedefinition, "term #{term.inspect} must not be a keyword" if
377+
raise JsonLdError::KeywordRedefinition, "term must not be a keyword: #{term.inspect}" if
378378
@options[:validate]
379379
elsif !term_valid?(term) && @options[:validate]
380-
raise JsonLdError::InvalidTermDefinition, "term #{term.inspect} is invalid"
380+
raise JsonLdError::InvalidTermDefinition, "term is invalid: #{term.inspect}"
381381
end
382382

383383
# Remove any existing term definition for term in active context.
@@ -410,13 +410,13 @@ 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' to #{type.inspect}"
413+
raise JsonLdError::InvalidTypeMapping, "invalid mapping for '@type': #{type.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' to #{type.inspect}"
419+
raise JsonLdError::InvalidTypeMapping, "unknown mapping for '@type': #{type.inspect}"
420420
end
421421
debug("") {"type_mapping: #{type.inspect}"}
422422
definition.type_mapping = type
@@ -425,7 +425,7 @@ def create_term_definition(local_context, term, defined)
425425
if value.has_key?('@reverse')
426426
raise JsonLdError::InvalidReverseProperty, "unexpected key in #{value.inspect}" if
427427
value.keys.any? {|k| %w(@id).include?(k)}
428-
raise JsonLdError::InvalidIRIMapping, "expected value of @reverse to be a string" unless
428+
raise JsonLdError::InvalidIRIMapping, "expected value of @reverse to be a string: #{value['@reverse'].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.
@@ -446,7 +446,7 @@ def create_term_definition(local_context, term, defined)
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" unless
449+
raise JsonLdError::InvalidIRIMapping, "expected value of @id to be a string: #{value['@id'].inspect}" unless
450450
value['@id'].is_a?(String)
451451
definition.id = expand_iri(value['@id'],
452452
:vocab => true,
@@ -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" unless vocab
473+
raise JsonLdError::InvalidIRIMapping, "relative term definition without vocab: #{term}" unless vocab
474474
definition.id = vocab + term
475475
debug("") {"=> #{definition.id}"}
476476
end

0 commit comments

Comments
 (0)