From 19457d61b9511b64911ddba1a98fb9409bee2bc3 Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Mon, 21 Aug 2017 21:06:57 +0200 Subject: [PATCH] Handle resolving of terms from undefined modules consistently --- CHANGELOG.md | 6 ++++++ lib/rdf/namespace.ex | 3 ++- test/unit/vocabulary_namespace_test.exs | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e891b7..d4fde4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,12 @@ This project adheres to [Semantic Versioning](http://semver.org/) and - `RDF.Literal.InvalidError` instead of `RDF.InvalidLiteralError` - `RDF.Namespace.InvalidVocabBaseIRIError` instead of `RDF.Namespace.InvalidVocabBaseURIError` +### Fixed + +- when trying to resolve a term from an undefined module a `RDF.Namespace.UndefinedTermError` + exception + + [Compare v0.2.0...HEAD](https://github.com/marcelotto/rdf-ex/compare/v0.2.0...HEAD) diff --git a/lib/rdf/namespace.ex b/lib/rdf/namespace.ex index 69e230e..2a0d02e 100644 --- a/lib/rdf/namespace.ex +++ b/lib/rdf/namespace.ex @@ -52,7 +52,8 @@ defmodule RDF.Namespace do defp do_resolve_term(RDF, term), do: do_resolve_term(RDF.NS.RDF, term) defp do_resolve_term(namespace, term) do - if Keyword.has_key?(namespace.__info__(:functions), :__resolve_term__) do + if Code.ensure_compiled?(namespace) and + Keyword.has_key?(namespace.__info__(:functions), :__resolve_term__)do namespace.__resolve_term__(term) else raise RDF.Namespace.UndefinedTermError, diff --git a/test/unit/vocabulary_namespace_test.exs b/test/unit/vocabulary_namespace_test.exs index 3382b78..cbde69f 100644 --- a/test/unit/vocabulary_namespace_test.exs +++ b/test/unit/vocabulary_namespace_test.exs @@ -738,6 +738,9 @@ defmodule RDF.Vocabulary.NamespaceTest do assert_raise RDF.Namespace.UndefinedTermError, fn -> RDF.iri(ExUnit.Test) end end + test "resolving an non-existing RDF.Namespace module" do + assert_raise RDF.Namespace.UndefinedTermError, fn -> RDF.iri(NonExisting.Test) end + end describe "term resolution in a strict vocab namespace" do alias TestNS.{ExampleFromGraph, ExampleFromNTriplesFile, StrictExampleFromTerms}