Repository: cayleygraph/cayley
Pull request #944 (2020-09-29 15:20:31)

Fix the link for k8s usage


<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/cayleygraph/cayley/944)
<!-- Reviewable:end -->



Patch:
diff --git a/CODEOWNERS b/CODEOWNERS
index 7634900..a550627 100644
--- a/CODEOWNERS
+++ b/CODEOWNERS
@@ -1,1 +1,1 @@
-*   @dennwc
\ No newline at end of file
+*   @dennwc @eraserhd
diff --git a/README.md b/README.md
index 7ff75c9..61c8cf8 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
 [![Build Status](https://travis-ci.com/cayleygraph/cayley.svg?branch=master)](https://travis-ci.com/cayleygraph/cayley)
 [![Container Repository](https://img.shields.io/docker/cloud/build/cayleygraph/cayley "Container Repository")](https://hub.docker.com/r/cayleygraph/cayley)
 
-Cayley is an open-source database for [Linked Data](https://www.w3.org/standards/semanticweb/data). It is inspired by the graph database behind Google's [Knowledge Graph](https://en.wikipedia.org/wiki/Knowledge_Graph) (formerly [Freebase](http://freebase.com)).
+Cayley is an open-source database for [Linked Data](https://www.w3.org/standards/semanticweb/data). It is inspired by the graph database behind Google's [Knowledge Graph](https://en.wikipedia.org/wiki/Knowledge_Graph) (formerly [Freebase](https://en.wikipedia.org/wiki/Freebase_(database))).
 
 [![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-white.svg)](https://snapcraft.io/cayley)
 
@@ -19,7 +19,7 @@ Cayley is an open-source database for [Linked Data](https://www.w3.org/standards
 - Multiple query languages:
   - [Gizmo](./docs/gizmoapi.md): query language inspired by [Gremlin](http://gremlindocs.com/)
   - [GraphQL](./docs/graphql.md)-inspired query language
-  - [MQL](./docs/mql.md): simplified version for [Freebase](https://en.wikipedia.org/wiki/Freebase) fans
+  - [MQL](./docs/mql.md): simplified version for [Freebase](https://en.wikipedia.org/wiki/Freebase_(database)) fans
 - Modular: easy to connect to your favorite programming languages and back-end stores
 - Production ready: well tested and used by various companies for their production workloads
 - Fast: optimized specifically for usage in applications
diff --git a/cmd/cayley/command/dedup.go b/cmd/cayley/command/dedup.go
index d9da3ce..4577613 100644
--- a/cmd/cayley/command/dedup.go
+++ b/cmd/cayley/command/dedup.go
@@ -139,15 +139,21 @@ func dedupProperties(ctx context.Context, h *graph.Handle, pred, typ quad.IRI) e
 			)
 		}
 	}
-	err := p.Iterate(ictx).Each(func(s graph.Ref) {
+	err := p.Iterate(ictx).Each(func(s graph.Ref) error {
 		cnt++
 		it := qs.QuadIterator(quad.Subject, s).Iterate()
 		defer it.Close()
 		m := make(map[interface{}]property)
 		for it.Next(ictx) {
 			q := it.Result()
-			p := qs.QuadDirection(q, quad.Predicate)
-			o := qs.QuadDirection(q, quad.Object)
+			p, err := qs.QuadDirection(q, quad.Predicate)
+			if err != nil {
+				return err
+			}
+			o, err := qs.QuadDirection(q, quad.Object)
+			if err != nil {
+				return err
+			}
 			k := refs.ToKey(p)
 			prop := m[k]
 			prop.Pred = p
@@ -161,7 +167,7 @@ func dedupProperties(ctx context.Context, h *graph.Handle, pred, typ quad.IRI) e
 		id, ok := seen[ph]
 		if !ok {
 			seen[ph] = s
-			return
+			return nil
 		}
 		if gerr = dedupValueTx(ictx, h, tx, s, id); gerr != nil {
 			cancel()
@@ -170,6 +176,7 @@ func dedupProperties(ctx context.Context, h *graph.Handle, pred, typ quad.IRI) e
 		if txn >= batch { // TODO(dennwc): flag
 			flush()
 		}
+		return nil
 	})
 	flush()
 	clog.Infof("deduplicated %d/%d nodes in %v", dedup, cnt, time.Since(start))
@@ -180,12 +187,18 @@ func dedupProperties(ctx context.Context, h *graph.Handle, pred, typ quad.IRI) e
 }
 
 func dedupValueTx(ctx context.Context, h *graph.Handle, tx *graph.Transaction, a, b graph.Ref) error {
-	v := h.NameOf(b)
+	v, err := h.NameOf(b)
+	if err != nil {
+		return err
+	}
 	it := h.QuadIterator(quad.Object, a).Iterate()
 	defer it.Close()
 	for it.Next(ctx) {
 		// TODO(dennwc): we should be able to add "raw" quads without getting values for directions
-		q := h.Quad(it.Result())
+		q, err := h.Quad(it.Result())
+		if err != nil {
+			return err
+		}
 		tx.RemoveQuad(q)
 		q.Object = v
 		tx.AddQuad(q)
@@ -198,7 +211,10 @@ func dedupValueTx(ctx context.Context, h *graph.Handle, tx *graph.Transaction, a
 	it = h.QuadIterator(quad.Subject, a).Iterate()
 	defer it.Close()
 	for it.Next(ctx) {
-		q := h.Quad(it.Result())
+		q, err := h.Quad(it.Result())
+		if err != nil {
+			return err
+		}
 		tx.RemoveQuad(q)
 	}
 	if err := it.Err(); err != nil {
diff --git a/docs/README.md b/docs/README.md
index a00c52f..e927527 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -24,7 +24,7 @@ Welcome to the Cayley Manual! Cayley is an open-source graph database designed f
 * [Configuration](configuration.md)
 * [Migration](usage/migration.md)
 * [Usage as Container](deployment/container.md)
-* [Usage in Kubernetes](https://github.com/cayleygraph/cayley/tree/06f7114d4ad1725d58f16fc5fdc9394f293c3539/docs/k8s.md)
+* [Usage in Kubernetes](./k8s/k8s.md)
 
 ## Developers
 
diff --git a/docs/glossary.md b/docs/glossary.md
index e33d454..8305eda 100644
--- a/docs/glossary.md
+++ b/docs/glossary.md
@@ -203,7 +203,7 @@ _Note: this definitions in this glossary are sequenced so that they build on eac
    ```go
     type Shape interface {
         BuildIterator(qs graph.QuadStore) graph.Iterator
-        Optimize(r Optimizer) (Shape, bool)
+        Optimize(ctx context.Context, r Optimizer) (Shape, bool)
     }
    ```
 
diff --git a/examples/hello_bolt/main.go b/examples/hello_bolt/main.go
index d11735a..29cf529 100644
--- a/examples/hello_bolt/main.go
+++ b/examples/hello_bolt/main.go
@@ -53,8 +53,11 @@ func main() {
 
 	// While we have items
 	for it.Next(ctx) {
-		token := it.Result()                // get a ref to a node (backend-specific)
-		value := store.NameOf(token)        // get the value in the node (RDF)
+		token := it.Result()              // get a ref to a node (backend-specific)
+		value, err := store.NameOf(token) // get the value in the node (RDF)
+		if err != nil {
+			log.Fatalln(err)
+		}
 		nativeValue := quad.NativeOf(value) // convert value to normal Go type
 
 		fmt.Println(nativeValue) // print it!
diff --git a/examples/hello_world/main.go b/examples/hello_world/main.go
index 2b57f1c..9fb6bc9 100644
--- a/examples/hello_world/main.go
+++ b/examples/hello_world/main.go
@@ -23,9 +23,10 @@ func main() {
 	// Now we iterate over results. Arguments:
 	// 1. Optional context used for cancellation.
 	// 2. Quad store, but we can omit it because we have already built path with it.
-	err = p.Iterate(nil).EachValue(nil, func(value quad.Value) {
+	err = p.Iterate(nil).EachValue(nil, func(value quad.Value) error {
 		nativeValue := quad.NativeOf(value) // this converts RDF values to normal Go types
 		fmt.Println(nativeValue)
+		return nil
 	})
 	if err != nil {
 		log.Fatalln(err)
diff --git a/examples/transaction/main.go b/examples/transaction/main.go
index 07cb255..223ea75 100644
--- a/examples/transaction/main.go
+++ b/examples/transaction/main.go
@@ -32,8 +32,9 @@ func main() {
 
 	p := cayley.StartPath(store, quad.String("cats")).Out(quad.String("are"))
 
-	err = p.Iterate(nil).EachValue(nil, func(v quad.Value) {
+	err = p.Iterate(nil).EachValue(nil, func(v quad.Value) error {
 		fmt.Println("cats are", v.Native())
+		return nil
 	})
 	if err != nil {
 		log.Fatalln(err)
diff --git a/go.sum b/go.sum
index 59b6184..24da5c1 100644
--- a/go.sum
+++ b/go.sum
@@ -25,8 +25,6 @@ github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
 github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
 github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
-github.com/cayleygraph/quad v1.2.3 h1:2HXwZGElLBuFLz8/6FdfWtil2W2gdfvYxNzS337SOwo=
-github.com/cayleygraph/quad v1.2.3/go.mod h1:XOianlRdDK5Upno/6svE6APe/wD8XgYrL9smqK875nU=
 github.com/cayleygraph/quad v1.2.4 h1:+6u09WxA7zg9ILonK8DChwzWKLKsDkjyvX+CXXhI/mM=
 github.com/cayleygraph/quad v1.2.4/go.mod h1:XOianlRdDK5Upno/6svE6APe/wD8XgYrL9smqK875nU=
 github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY=
@@ -113,7 +111,6 @@ github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZp
 github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
 github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
-github.com/gobuffalo/envy v1.7.0 h1:GlXgaiBkmrYMHco6t4j7SacKO4XUjvh5pwXh0f4uxXU=
 github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
 github.com/gobuffalo/envy v1.7.1 h1:OQl5ys5MBea7OGCdvPbBJWRgnhC/fGona6QKfvFeau8=
 github.com/gobuffalo/envy v1.7.1/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w=
@@ -125,7 +122,6 @@ github.com/gobuffalo/packr/v2 v2.7.1 h1:n3CIW5T17T8v4GGK5sWXLVWJhCz7b5aNLSxW6gYi
 github.com/gobuffalo/packr/v2 v2.7.1/go.mod h1:qYEvAazPaVxy7Y7KR0W8qYEE+RymX74kETFqjFoFlOc=
 github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
 github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
-github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
 github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
 github.com/gogo/protobuf v1.3.0 h1:G8O7TerXerS4F6sx9OV7/nRfJdnXgHZu/S/7F2SN+UE=
 github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
@@ -275,14 +271,11 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T
 github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
 github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
 github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
-github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
 github.com/rogpeppe/go-internal v1.3.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
-github.com/rogpeppe/go-internal v1.4.0 h1:LUa41nrWTQNGhzdsZ5lTnkwbNjj6rXTdazA1cSdjkOY=
 github.com/rogpeppe/go-internal v1.4.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
 github.com/rogpeppe/go-internal v1.5.0 h1:Usqs0/lDK/NqTkvrmKSwA/3XkZAs7ZAW/eLeQ2MVBTw=
 github.com/rogpeppe/go-internal v1.5.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
-github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
 github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
 github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
 github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
@@ -305,7 +298,6 @@ github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tL
 github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
 github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
 github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
-github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
 github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
 github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
 github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
@@ -315,7 +307,6 @@ github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/y
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
-github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
@@ -347,9 +338,7 @@ go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
 golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU=
 golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
-golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A=
 golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc h1:c0o/qxkaO2LF5t6fQrT4b5hzyggAkLLlCUjqfRxd8Q4=
 golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@@ -381,7 +370,6 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
 golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -416,7 +404,6 @@ golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3
 golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
 golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
 golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
-golang.org/x/tools v0.0.0-20191004055002-72853e10c5a3 h1:2AmBLzhAfXj+2HCW09VCkJtHIYgHTIPcTeYqgP7Bwt0=
 golang.org/x/tools v0.0.0-20191004055002-72853e10c5a3/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.0.0-20191010075000-0337d82405ff h1:XdBG6es/oFDr1HwaxkxgVve7NB281QhxgK/i4voubFs=
 golang.org/x/tools v0.0.0-20191010075000-0337d82405ff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
diff --git a/graph/gaedatastore/iterator.go b/graph/gaedatastore/iterator.go
index fb1c2e0..b48bd90 100644
--- a/graph/gaedatastore/iterator.go
+++ b/graph/gaedatastore/iterator.go
@@ -89,7 +89,12 @@ func (it *Iterator) Optimize(ctx context.Context) (iterator.Shape, bool) { retur
 func (it *Iterator) String() string {
 	name := ""
 	if it.t != nil {
-		name = quad.StringOf(it.qs.NameOf(it.t)) + "/" + it.t.Hash
+		tn, err := it.qs.NameOf(it.t)
+		if err != nil {
+			name = "ERROR(" + err.Error() + ")"
+		} else {
+			name = quad.StringOf(tn) + "/" + it.t.Hash
+		}
 	}
 	return fmt.Sprintf("GAE(%s)", name)
 }
@@ -171,7 +176,12 @@ func newIteratorNext(qs *QuadStore, k string, d quad.Direction, t *Token) *itera
 		clog.Errorf("Cannot create iterator without a valid context")
 		return &iteratorNext{done: true}
 	}
-	name := quad.StringOf(qs.NameOf(t))
+	tn, err := qs.NameOf(t)
+	if err != nil {
+		clog.Errorf("Creating iterator token lookup error: %v", err)
+		return &iteratorNext{done: true, err: err}
+	}
+	name := quad.StringOf(tn)
 	return &iteratorNext{
 		name:  name,
 		dir:   d,
@@ -330,7 +340,12 @@ func newIteratorContains(qs *QuadStore, k string, d quad.Direction, t *Token) *i
 		clog.Errorf("Cannot create iterator without a valid context")
 		return &iteratorContains{done: true}
 	}
-	name := quad.StringOf(qs.NameOf(t))
+	tn, err := qs.NameOf(t)
+	if err != nil {
+		clog.Errorf("Creating iterator token lookup error: %v", err)
+		return &iteratorContains{done: true, err: err}
+	}
+	name := quad.StringOf(tn)
 	return &iteratorContains{
 		name:  name,
 		dir:   d,
diff --git a/graph/gaedatastore/quadstore.go b/graph/gaedatastore/quadstore.go
index 769ed20..93e984f 100644
--- a/graph/gaedatastore/quadstore.go
+++ b/graph/gaedatastore/quadstore.go
@@ -450,24 +450,22 @@ func (qs *QuadStore) QuadsAllIterator() iterator.Shape {
 	return qs.newAllIterator(quadKind)
 }
 
-func (qs *QuadStore) ValueOf(s quad.Value) graph.Ref {
+func (qs *QuadStore) ValueOf(s quad.Value) (graph.Ref, error) {
 	id := hashOf(s)
-	return &Token{Kind: nodeKind, Hash: id}
+	return &Token{Kind: nodeKind, Hash: id}, nil
 }
 
-func (qs *QuadStore) NameOf(val graph.Ref) quad.Value {
+func (qs *QuadStore) NameOf(val graph.Ref) (quad.Value, error) {
 	if qs.context == nil {
-		clog.Errorf("Error in NameOf, context is nil, graph not correctly initialised")
-		return nil
+		return nil, errors.New("context is nil, graph is not initialized")
 	} else if v, ok := val.(refs.PreFetchedValue); ok {
-		return v.NameOf()
+		return v.NameOf(), nil
 	}
 	var key *datastore.Key
 	if t, ok := val.(*Token); ok && t.Kind == nodeKind {
 		key = qs.createKeyFromToken(t)
 	} else {
-		clog.Errorf("Token not valid")
-		return nil
+		return nil, errors.New("token not valid")
 	}
 
 	// TODO (panamafrancis) implement a cache
@@ -475,23 +473,20 @@ func (qs *QuadStore) NameOf(val graph.Ref) quad.Value {
 	node := new(NodeEntry)
 	err := datastore.Get(qs.context, key, node)
 	if err != nil {
-		clog.Errorf("Error: %v", err)
-		return nil
+		return nil, err
 	}
-	return quad.Raw(node.Name)
+	return quad.Raw(node.Name), nil
 }
 
-func (qs *QuadStore) Quad(val graph.Ref) quad.Quad {
+func (qs *QuadStore) Quad(val graph.Ref) (quad.Quad, error) {
 	if qs.context == nil {
-		clog.Errorf("Error fetching quad, context is nil, graph not correctly initialised")
-		return quad.Quad{}
+		return quad.Quad{}, errors.New("context is nil, graph is not correctly initialized")
 	}
 	var key *datastore.Key
 	if t, ok := val.(*Token); ok && t.Kind == quadKind {
 		key = qs.createKeyFromToken(t)
 	} else {
-		clog.Errorf("Token not valid")
-		return quad.Quad{}
+		return quad.Quad{}, errors.New("gae quad: token not valid")
 	}
 
 	q := new(QuadEntry)
@@ -499,7 +494,7 @@ func (qs *QuadStore) Quad(val graph.Ref) quad.Quad {
 	if err != nil {
 		// Red herring error : ErrFieldMismatch can happen when a quad exists but a field is empty
 		if _, ok := err.(*datastore.ErrFieldMismatch); !ok {
-			clog.Errorf("Error: %v", err)
+			return quad.Quad{}, err
 		}
 	}
 	var label interface{}
@@ -511,7 +506,7 @@ func (qs *QuadStore) Quad(val graph.Ref) quad.Quad {
 		q.Predicate,
 		q.Object,
 		label,
-	)
+	), nil
 }
 
 func (qs *QuadStore) Stats(ctx context.Context, exact bool) (graph.Stats, error) {
@@ -557,15 +552,13 @@ func (qs *QuadStore) Close() error {
 	return nil
 }
 
-func (qs *QuadStore) QuadDirection(val graph.Ref, dir quad.Direction) graph.Ref {
+func (qs *QuadStore) QuadDirection(val graph.Ref, dir quad.Direction) (graph.Ref, error) {
 	t, ok := val.(*Token)
 	if !ok {
-		clog.Errorf("Token not valid")
-		return nil
+		return nil, errors.New("token not valid")
 	}
 	if t.Kind == nodeKind {
-		clog.Errorf("Node tokens not valid")
-		return nil
+		return nil, errors.New("node tokens not valid")
 	}
 	var offset int
 	switch dir {
@@ -579,5 +572,5 @@ func (qs *QuadStore) QuadDirection(val graph.Ref, dir quad.Direction) graph.Ref
 		offset = (quad.HashSize * 2) * 3
 	}
 	sub := t.Hash[offset : offset+(quad.HashSize*2)]
-	return &Token{Kind: nodeKind, Hash: sub}
+	return &Token{Kind: nodeKind, Hash: sub}, nil
 }
diff --git a/graph/graphmock/graphmock.go b/graph/graphmock/graphmock.go
index 43b1942..3348aaf 100644
--- a/graph/graphmock/graphmock.go
+++ b/graph/graphmock/graphmock.go
@@ -41,16 +41,16 @@ func (qs *Oldstore) valueAt(i int) quad.Value {
 	return quad.String(qs.Data[i])
 }
 
-func (qs *Oldstore) ValueOf(s quad.Value) graph.Ref {
+func (qs *Oldstore) ValueOf(s quad.Value) (graph.Ref, error) {
 	if s == nil {
-		return nil
+		return nil, nil
 	}
 	for i := range qs.Data {
 		if va := qs.valueAt(i); va != nil && s.String() == va.String() {
-			return iterator.Int64Node(i)
+			return iterator.Int64Node(i), nil
 		}
 	}
-	return nil
+	return nil, nil
 }
 
 func (qs *Oldstore) NewQuadWriter() (quad.WriteCloser, error) {
@@ -88,21 +88,21 @@ func (qs *Oldstore) NodesAllIterator() iterator.Shape { return &iterator.Null{}
 
 func (qs *Oldstore) QuadsAllIterator() iterator.Shape { return &iterator.Null{} }
 
-func (qs *Oldstore) NameOf(v graph.Ref) quad.Value {
+func (qs *Oldstore) NameOf(v graph.Ref) (quad.Value, error) {
 	switch v := v.(type) {
 	case iterator.Int64Node:
 		i := int(v)
 		if i < 0 || i >= len(qs.Data) {
-			return nil
+			return nil, nil
 		}
-		return qs.valueAt(i)
+		return qs.valueAt(i), nil
 	case StringNode:
 		if qs.Parse {
-			return quad.String(v)
+			return quad.String(v), nil
 		}
-		return quad.Raw(string(v))
+		return quad.Raw(string(v)), nil
 	default:
-		return nil
+		return nil, nil
 	}
 }
 
@@ -130,13 +130,13 @@ type Store struct {
 
 var _ graph.QuadStore = &Store{}
 
-func (qs *Store) ValueOf(s quad.Value) graph.Ref {
+func (qs *Store) ValueOf(s quad.Value) (graph.Ref, error) {
 	for _, q := range qs.Data {
 		if q.Subject == s || q.Object == s {
-			return refs.PreFetched(s)
+			return refs.PreFetched(s), nil
 		}
 	}
-	return nil
+	return nil, nil
 }
 
 func (qs *Store) ApplyDeltas([]graph.Delta, graph.IgnoreOpts) error { return nil }
@@ -153,21 +153,27 @@ func (q quadValue) Key() interface{} {
 	return q.q.String()
 }
 
-func (qs *Store) Quad(v graph.Ref) quad.Quad { return v.(quadValue).q }
+func (qs *Store) Quad(v graph.Ref) (quad.Quad, error) {
+	return v.(quadValue).q, nil
+}
 
-func (qs *Store) NameOf(v graph.Ref) quad.Value {
+func (qs *Store) NameOf(v graph.Ref) (quad.Value, error) {
 	if v == nil {
-		return nil
+		return nil, nil
 	}
-	return v.(refs.PreFetchedValue).NameOf()
+	return v.(refs.PreFetchedValue).NameOf(), nil
 }
 
 func (qs *Store) RemoveQuad(t quad.Quad) {}
 
 func (qs *Store) Type() string { return "mockstore" }
 
-func (qs *Store) QuadDirection(v graph.Ref, d quad.Direction) graph.Ref {
-	return refs.PreFetched(qs.Quad(v).Get(d))
+func (qs *Store) QuadDirection(v graph.Ref, d quad.Direction) (graph.Ref, error) {
+	qv, err := qs.Quad(v)
+	if err != nil {
+		return nil, err
+	}
+	return refs.PreFetched(qv.Get(d)), nil
 }
 
 func (qs *Store) Close() error { return nil }
@@ -200,7 +206,10 @@ func (qs *Store) NodesAllIterator() iterator.Shape {
 	set := make(map[string]bool)
 	for _, q := range qs.Data {
 		for _, d := range quad.Directions {
-			n := qs.NameOf(refs.PreFetched(q.Get(d)))
+			n, err := qs.NameOf(refs.PreFetched(q.Get(d)))
+			if err != nil {
+				return iterator.NewError(err)
+			}
 			if n != nil {
 				set[n.String()] = true
 			}
@@ -225,7 +234,10 @@ func (qs *Store) Stats(ctx context.Context, exact bool) (graph.Stats, error) {
 	set := make(map[string]struct{})
 	for _, q := range qs.Data {
 		for _, d := range quad.Directions {
-			n := qs.NameOf(refs.PreFetched(q.Get(d)))
+			n, err := qs.NameOf(refs.PreFetched(q.Get(d)))
+			if err != nil {
+				return graph.Stats{}, err
+			}
 			if n != nil {
 				set[n.String()] = struct{}{}
 			}
diff --git a/graph/hasa.go b/graph/hasa.go
index 1877fc0..93bdcc5 100644
--- a/graph/hasa.go
+++ b/graph/hasa.go
@@ -127,6 +127,7 @@ type hasANext struct {
 	primary iterator.Scanner
 	dir     quad.Direction
 	result  refs.Ref
+	err     error
 }
 
 // Construct a new HasA iterator, given the quad subiterator, and the quad
@@ -163,11 +164,19 @@ func (it *hasANext) Next(ctx context.Context) bool {
 	if !it.primary.Next(ctx) {
 		return false
 	}
-	it.result = it.qs.QuadDirection(it.primary.Result(), it.dir)
+	var err error
+	it.result, err = it.qs.QuadDirection(it.primary.Result(), it.dir)
+	if err != nil {
+		it.err = err
+		return false
+	}
 	return true
 }
 
 func (it *hasANext) Err() error {
+	if it.err != nil {
+		return it.err
+	}
 	return it.primary.Err()
 }
 
@@ -244,10 +253,20 @@ func (it *hasAContains) nextContains(ctx context.Context) bool {
 	for it.results.Next(ctx) {
 		link := it.results.Result()
 		if clog.V(4) {
-			clog.Infof("Quad is %v", it.qs.Quad(link))
+			qlv, err := it.qs.Quad(link)
+			if err == nil {
+				clog.Infof("Quad is %v", qlv)
+			} else {
+				clog.Warningf("Error looking up result quad: %v", err)
+			}
 		}
 		if it.primary.Contains(ctx, link) {
-			it.result = it.qs.QuadDirection(link, it.dir)
+			var err error
+			it.result, err = it.qs.QuadDirection(link, it.dir)
+			if err != nil {
+				it.err = err
+				return false
+			}
 			return true
 		}
 	}
diff --git a/graph/iterator/count.go b/graph/iterator/count.go
index 31e6807..54f6b03 100644
--- a/graph/iterator/count.go
+++ b/graph/iterator/count.go
@@ -124,8 +124,9 @@ func (it *countNext) String() string { return "CountNext" }
 
 // Count iterator returns one element with size of underlying iterator.
 type countContains struct {
-	it *countNext
-	qs refs.Namer
+	it  *countNext
+	qs  refs.Namer
+	err error
 }
 
 // NewCount creates a new iterator to count a number of results from a provided subiterator.
@@ -140,6 +141,9 @@ func newCountContains(it Shape, qs refs.Namer) *countContains {
 func (it *countContains) TagResults(dst map[string]refs.Ref) {}
 
 func (it *countContains) Err() error {
+	if it.err != nil {
+		return it.err
+	}
 	return it.it.Err()
 }
 
@@ -155,7 +159,12 @@ func (it *countContains) Contains(ctx context.Context, val refs.Ref) bool {
 		return v.NameOf() == it.it.result
 	}
 	if it.qs != nil {
-		return it.qs.NameOf(val) == it.it.result
+		valName, err := it.qs.NameOf(val)
+		if err != nil {
+			it.err = err
+			return false
+		}
+		return valName == it.it.result
 	}
 	return false
 }
diff --git a/graph/iterator/iterate.go b/graph/iterator/iterate.go
index c61130c..da250cb 100644
--- a/graph/iterator/iterate.go
+++ b/graph/iterator/iterate.go
@@ -97,7 +97,7 @@ func (c *Chain) UnOptimized() *Chain {
 }
 
 // Each will run a provided callback for each result of the iterator.
-func (c *Chain) Each(fnc func(refs.Ref)) error {
+func (c *Chain) Each(fnc func(refs.Ref) error) error {
 	c.start()
 	defer c.end()
 	done := c.ctx.Done()
@@ -108,7 +108,10 @@ func (c *Chain) Each(fnc func(refs.Ref)) error {
 			return c.ctx.Err()
 		default:
 		}
-		fnc(c.it.Result())
+		err := fnc(c.it.Result())
+		if err != nil {
+			return err
+		}
 		for c.nextPath() {
 			select {
 			case <-done:
@@ -220,7 +223,7 @@ func (c *Chain) Send(out chan<- refs.Ref) error {
 }
 
 // TagEach will run a provided tag map callback for each result of the iterator.
-func (c *Chain) TagEach(fnc func(map[string]refs.Ref)) error {
+func (c *Chain) TagEach(fnc func(map[string]refs.Ref) error) error {
 	c.start()
 	defer c.end()
 	done := c.ctx.Done()
@@ -237,7 +240,10 @@ func (c *Chain) TagEach(fnc func(map[string]refs.Ref)) error {
 		if n := len(tags); n > mn {
 			mn = n
 		}
-		fnc(tags)
+		err := fnc(tags)
+		if err != nil {
+			return err
+		}
 		for c.nextPath() {
 			select {
 			case <-done:
@@ -249,7 +255,10 @@ func (c *Chain) TagEach(fnc func(map[string]refs.Ref)) error {
 			if n := len(tags); n > mn {
 				mn = n
 			}
-			fnc(tags)
+			err = fnc(tags)
+			if err != nil {
+				return err
+			}
 		}
 	}
 	return c.it.Err()
@@ -259,7 +268,7 @@ var errNoQuadStore = fmt.Errorf("no quad store in Iterate")
 
 // EachValue is an analog of Each, but it will additionally call NameOf
 // for each graph.Ref before passing it to a callback.
-func (c *Chain) EachValue(qs refs.Namer, fnc func(quad.Value)) error {
+func (c *Chain) EachValue(qs refs.Namer, fnc func(quad.Value) error) error {
 	if qs != nil {
 		c.qs = qs
 	}
@@ -267,16 +276,18 @@ func (c *Chain) EachValue(qs refs.Namer, fnc func(quad.Value)) error {
 		return errNoQuadStore
 	}
 	// TODO(dennwc): batch NameOf?
-	return c.Each(func(v refs.Ref) {
-		if nv := c.qs.NameOf(v); nv != nil {
-			fnc(nv)
+	return c.Each(func(v refs.Ref) error {
+		nv, err := c.qs.NameOf(v)
+		if err == nil && nv != nil {
+			err = fnc(nv)
 		}
+		return err
 	})
 }
 
 // EachValuePair is an analog of Each, but it will additionally call NameOf
 // for each graph.Ref before passing it to a callback. Original value will be passed as well.
-func (c *Chain) EachValuePair(qs refs.Namer, fnc func(refs.Ref, quad.Value)) error {
+func (c *Chain) EachValuePair(qs refs.Namer, fnc func(refs.Ref, quad.Value) error) error {
 	if qs != nil {
 		c.qs = qs
 	}
@@ -284,10 +295,12 @@ func (c *Chain) EachValuePair(qs refs.Namer, fnc func(refs.Ref, quad.Value)) err
 		return errNoQuadStore
 	}
 	// TODO(dennwc): batch NameOf?
-	return c.Each(func(v refs.Ref) {
-		if nv := c.qs.NameOf(v); nv != nil {
-			fnc(v, nv)
+	return c.Each(func(v refs.Ref) error {
+		nv, err := c.qs.NameOf(v)
+		if err == nil && nv != nil {
+			err = fnc(v, nv)
 		}
+		return err
 	})
 }
 
@@ -295,8 +308,9 @@ func (c *Chain) EachValuePair(qs refs.Namer, fnc func(refs.Ref, quad.Value)) err
 // for each graph.Ref before returning the results slice.
 func (c *Chain) AllValues(qs refs.Namer) ([]quad.Value, error) {
 	var out []quad.Value
-	err := c.EachValue(qs, func(v quad.Value) {
+	err := c.EachValue(qs, func(v quad.Value) error {
 		out = append(out, v)
+		return nil
 	})
 	return out, err
 }
@@ -313,8 +327,7 @@ func (c *Chain) FirstValue(qs refs.Namer) (quad.Value, error) {
 	if err != nil || v == nil {
 		return nil, err
 	}
-	// TODO: return an error from NameOf once we have it exposed
-	return c.qs.NameOf(v), nil
+	return c.qs.NameOf(v)
 }
 
 // SendValues is an analog of Send, but it will additionally call NameOf
@@ -330,14 +343,18 @@ func (c *Chain) SendValues(qs refs.Namer, out chan<- quad.Value) error {
 	defer c.end()
 	done := c.ctx.Done()
 	send := func(v refs.Ref) error {
-		nv := c.qs.NameOf(c.it.Result())
-		if nv == nil {
-			return nil
+		nv, err := c.qs.NameOf(c.it.Result())
+		if err != nil || nv == nil {
+			return err
+		}
+		nvResult, err := c.qs.NameOf(c.it.Result())
+		if err != nil {
+			return err
 		}
 		select {
 		case <-done:
 			return c.ctx.Err()
-		case out <- c.qs.NameOf(c.it.Result()):
+		case out <- nvResult:
 		}
 		return nil
 	}
@@ -356,18 +373,23 @@ func (c *Chain) SendValues(qs refs.Namer, out chan<- quad.Value) error {
 
 // TagValues is an analog of TagEach, but it will additionally call NameOf
 // for each graph.Ref before passing the map to a callback.
-func (c *Chain) TagValues(qs refs.Namer, fnc func(map[string]quad.Value)) error {
+func (c *Chain) TagValues(qs refs.Namer, fnc func(map[string]quad.Value) error) error {
 	if qs != nil {
 		c.qs = qs
 	}
 	if c.qs == nil {
 		return errNoQuadStore
 	}
-	return c.TagEach(func(m map[string]refs.Ref) {
+	return c.TagEach(func(m map[string]refs.Ref) error {
 		vm := make(map[string]quad.Value, len(m))
 		for k, v := range m {
-			vm[k] = c.qs.NameOf(v) // TODO(dennwc): batch NameOf?
+			var err error
+			vm[k], err = c.qs.NameOf(v) // TODO(dennwc): batch NameOf?
+			if err != nil {
+				return err
+			}
 		}
 		fnc(vm)
+		return nil
 	})
 }
diff --git a/graph/iterator/sort.go b/graph/iterator/sort.go
index c344b95..c8482c4 100644
--- a/graph/iterator/sort.go
+++ b/graph/iterator/sort.go
@@ -154,7 +154,10 @@ func getSortedValues(ctx context.Context, namer refs.Namer, it Scanner) (sortByS
 	for it.Next(ctx) {
 		id := it.Result()
 		// TODO(dennwc): batch and use refs.ValuesOf
-		name := namer.NameOf(id)
+		name, err := namer.NameOf(id)
+		if err != nil {
+			return nil, err
+		}
 		str := name.String()
 		tags := make(map[string]refs.Ref)
 		it.TagResults(tags)
diff --git a/graph/iterator/value_filter.go b/graph/iterator/value_filter.go
index 8e388a0..44db33f 100644
--- a/graph/iterator/value_filter.go
+++ b/graph/iterator/value_filter.go
@@ -90,7 +90,11 @@ func newValueFilterNext(qs refs.Namer, sub Scanner, filter ValueFilterFunc) *val
 }
 
 func (it *valueFilterNext) doFilter(val refs.Ref) bool {
-	qval := it.qs.NameOf(val)
+	qval, err := it.qs.NameOf(val)
+	if err != nil {
+		it.err = err
+		return false
+	}
 	ok, err := it.filter(qval)
 	if err != nil {
 		it.err = err
@@ -153,7 +157,11 @@ func newValueFilterContains(qs refs.Namer, sub Index, filter ValueFilterFunc) *v
 }
 
 func (it *valueFilterContains) doFilter(val refs.Ref) bool {
-	qval := it.qs.NameOf(val)
+	qval, err := it.qs.NameOf(val)
+	if err != nil {
+		it.err = err
+		return false
+	}
 	ok, err := it.filter(qval)
 	if err != nil {
 		it.err = err
diff --git a/graph/kv/indexing.go b/graph/kv/indexing.go
index 10aa668..dc0c941 100644
--- a/graph/kv/indexing.go
+++ b/graph/kv/indexing.go
@@ -26,7 +26,7 @@ import (
 
 	"github.com/cayleygraph/cayley/clog"
 	"github.com/cayleygraph/cayley/graph"
-	"github.com/cayleygraph/cayley/graph/log"
+	graphlog "github.com/cayleygraph/cayley/graph/log"
 	"github.com/cayleygraph/cayley/graph/proto"
 	"github.com/cayleygraph/cayley/graph/refs"
 	"github.com/cayleygraph/quad"
@@ -686,7 +686,7 @@ func (qs *QuadStore) indexNode(tx kv.Tx, p *proto.Primitive, val quad.Value) err
 		qs.valueLRU.Put(string(iri), p.ID)
 	}
 	if qs.mapNodes != nil {
-		qs.mapNodes.Add(hash[:])
+		qs.mapNodes.Add(hash)
 	}
 	return qs.addToLog(tx, p)
 }
diff --git a/graph/kv/quadstore.go b/graph/kv/quadstore.go
index d28ee1d..79bccac 100644
--- a/graph/kv/quadstore.go
+++ b/graph/kv/quadstore.go
@@ -23,9 +23,6 @@ import (
 	"os"
 	"sync"
 
-	"github.com/hidal-go/hidalgo/kv"
-
-	"github.com/cayleygraph/cayley/clog"
 	"github.com/cayleygraph/cayley/graph"
 	"github.com/cayleygraph/cayley/graph/proto"
 	"github.com/cayleygraph/cayley/graph/refs"
@@ -33,6 +30,7 @@ import (
 	"github.com/cayleygraph/cayley/query/shape"
 	"github.com/cayleygraph/quad"
 	"github.com/cayleygraph/quad/pquads"
+	"github.com/hidal-go/hidalgo/kv"
 	boom "github.com/tylertreat/BoomFilters"
 )
 
@@ -364,21 +362,19 @@ func (qs *QuadStore) RefsOf(ctx context.Context, nodes []quad.Value) ([]graph.Re
 	return values, nil
 }
 
-func (qs *QuadStore) NameOf(v graph.Ref) quad.Value {
+func (qs *QuadStore) NameOf(v graph.Ref) (quad.Value, error) {
 	ctx := context.TODO()
 	vals, err := qs.ValuesOf(ctx, []graph.Ref{v})
 	if err != nil {
-		clog.Errorf("error getting NameOf %d: %s", v, err)
-		return nil
+		return nil, fmt.Errorf("error getting NameOf %d: %w", v, err)
 	}
-	return vals[0]
+	return vals[0], nil
 }
 
-func (qs *QuadStore) Quad(k graph.Ref) quad.Quad {
+func (qs *QuadStore) Quad(k graph.Ref) (quad.Quad, error) {
 	key, ok := k.(*proto.Primitive)
 	if !ok {
-		clog.Errorf("passed value was not a quad primitive: %T", k)
-		return quad.Quad{}
+		return quad.Quad{}, fmt.Errorf("passed value was not a quad primitive: %T", k)
 	}
 	ctx := context.TODO()
 	var v quad.Quad
@@ -387,13 +383,13 @@ func (qs *QuadStore) Quad(k graph.Ref) quad.Quad {
 		v, err = qs.primitiveToQuad(ctx, tx, key)
 		return err
 	})
+	if err == kv.ErrNotFound {
+		err = nil
+	}
 	if err != nil {
-		if err != kv.ErrNotFound {
-			clog.Errorf("error fetching quad %#v: %s", key, err)
-		}
-		return quad.Quad{}
+		err = fmt.Errorf("error fetching quad %#v: %w", key, err)
 	}
-	return v
+	return v, err
 }
 
 func (qs *QuadStore) primitiveToQuad(ctx context.Context, tx kv.Tx, p *proto.Primitive) (quad.Quad, error) {
@@ -420,39 +416,42 @@ func (qs *QuadStore) getValFromLog(ctx context.Context, tx kv.Tx, k uint64) (qua
 	return pquads.UnmarshalValue(p.Value)
 }
 
-func (qs *QuadStore) ValueOf(s quad.Value) graph.Ref {
+func (qs *QuadStore) ValueOf(s quad.Value) (graph.Ref, error) {
 	ctx := context.TODO()
 	var out Int64Value
-	_ = kv.View(qs.db, func(tx kv.Tx) error {
+	err := kv.View(qs.db, func(tx kv.Tx) error {
 		v, err := qs.resolveQuadValue(ctx, tx, s)
 		out = Int64Value(v)
 		return err
 	})
+	if err != nil {
+		return nil, err
+	}
 	if out == 0 {
-		return nil
+		return nil, nil
 	}
-	return out
+	return out, nil
 }
 
-func (qs *QuadStore) QuadDirection(val graph.Ref, d quad.Direction) graph.Ref {
+func (qs *QuadStore) QuadDirection(val graph.Ref, d quad.Direction) (graph.Ref, error) {
 	p, ok := val.(*proto.Primitive)
 	if !ok {
-		return nil
+		return nil, nil
 	}
 	switch d {
 	case quad.Subject:
-		return Int64Value(p.Subject)
+		return Int64Value(p.Subject), nil
 	case quad.Predicate:
-		return Int64Value(p.Predicate)
+		return Int64Value(p.Predicate), nil
 	case quad.Object:
-		return Int64Value(p.Object)
+		return Int64Value(p.Object), nil
 	case quad.Label:
 		if p.Label == 0 {
-			return nil
+			return nil, nil
 		}
-		return Int64Value(p.Label)
+		return Int64Value(p.Label), nil
 	}
-	return nil
+	return nil, nil
 }
 
 func (qs *QuadStore) getPrimitives(ctx context.Context, vals []uint64) ([]*proto.Primitive, error) {
diff --git a/graph/linksto.go b/graph/linksto.go
index 48c839e..4d1617c 100644
--- a/graph/linksto.go
+++ b/graph/linksto.go
@@ -237,6 +237,7 @@ type linksToContains struct {
 	primary iterator.Index
 	dir     quad.Direction
 	result  refs.Ref
+	err     error
 }
 
 // Construct a new LinksTo iterator around a direction and a subiterator of
@@ -264,7 +265,11 @@ func (it *linksToContains) String() string {
 // If it checks in the right direction for the subiterator, it is a valid link
 // for the LinksTo.
 func (it *linksToContains) Contains(ctx context.Context, val refs.Ref) bool {
-	node := it.qs.QuadDirection(val, it.dir)
+	node, err := it.qs.QuadDirection(val, it.dir)
+	if err != nil {
+		it.err = err
+		return false
+	}
 	if it.primary.Contains(ctx, node) {
 		it.result = val
 		return true
@@ -273,6 +278,9 @@ func (it *linksToContains) Contains(ctx context.Context, val refs.Ref) bool {
 }
 
 func (it *linksToContains) Err() error {
+	if it.err != nil {
+		return it.err
+	}
 	return it.primary.Err()
 }
 
diff --git a/graph/memstore/quadstore.go b/graph/memstore/quadstore.go
index 2159450..ea9798c 100644
--- a/graph/memstore/quadstore.go
+++ b/graph/memstore/quadstore.go
@@ -469,12 +469,12 @@ func (qs *QuadStore) quad(v graph.Ref) (q internalQuad, ok bool) {
 	return q, !q.Zero()
 }
 
-func (qs *QuadStore) Quad(index graph.Ref) quad.Quad {
+func (qs *QuadStore) Quad(index graph.Ref) (quad.Quad, error) {
 	q, ok := qs.quad(index)
 	if !ok {
-		return quad.Quad{}
+		return quad.Quad{}, nil
 	}
-	return qs.lookupQuadDirs(q)
+	return qs.lookupQuadDirs(q), nil
 }
 
 func (qs *QuadStore) QuadIterator(d quad.Direction, value graph.Ref) iterator.Shape {
@@ -514,47 +514,47 @@ func (qs *QuadStore) Stats(ctx context.Context, exact bool) (graph.Stats, error)
 	}, nil
 }
 
-func (qs *QuadStore) ValueOf(name quad.Value) graph.Ref {
+func (qs *QuadStore) ValueOf(name quad.Value) (graph.Ref, error) {
 	if name == nil {
-		return nil
+		return nil, nil
 	}
 	id := qs.vals[name.String()]
 	if id == 0 {
-		return nil
+		return nil, nil
 	}
-	return bnode(id)
+	return bnode(id), nil
 }
 
-func (qs *QuadStore) NameOf(v graph.Ref) quad.Value {
+func (qs *QuadStore) NameOf(v graph.Ref) (quad.Value, error) {
 	if v == nil {
-		return nil
+		return nil, nil
 	} else if v, ok := v.(refs.PreFetchedValue); ok {
-		return v.NameOf()
+		return v.NameOf(), nil
 	}
 	n, ok := asID(v)
 	if !ok {
-		return nil
+		return nil, nil
 	}
 	if _, ok = qs.prim[n]; !ok {
-		return nil
+		return nil, nil
 	}
-	return qs.lookupVal(n)
+	return qs.lookupVal(n), nil
 }
 
 func (qs *QuadStore) QuadsAllIterator() iterator.Shape {
 	return qs.newAllIterator(false, qs.last)
 }
 
-func (qs *QuadStore) QuadDirection(val graph.Ref, d quad.Direction) graph.Ref {
+func (qs *QuadStore) QuadDirection(val graph.Ref, d quad.Direction) (graph.Ref, error) {
 	q, ok := qs.quad(val)
 	if !ok {
-		return nil
+		return nil, nil
 	}
 	id := q.Dir(d)
 	if id == 0 {
-		return nil
+		return nil, nil
 	}
-	return bnode(id)
+	return bnode(id), nil
 }
 
 func (qs *QuadStore) NodesAllIterator() iterator.Shape {
diff --git a/graph/nosql/iterator.go b/graph/nosql/iterator.go
index 8e55630..c42e669 100644
--- a/graph/nosql/iterator.go
+++ b/graph/nosql/iterator.go
@@ -283,7 +283,11 @@ func (it *iteratorContains) Contains(ctx context.Context, v graph.Ref) bool {
 		it.result = v
 		return true
 	}
-	qv := it.qs.NameOf(v)
+	qv, err := it.qs.NameOf(v)
+	if err != nil {
+		it.err = err
+		return false
+	}
 	if qv == nil {
 		return false
 	}
diff --git a/graph/nosql/quadstore.go b/graph/nosql/quadstore.go
index 9fc8957..1077c85 100644
--- a/graph/nosql/quadstore.go
+++ b/graph/nosql/quadstore.go
@@ -610,14 +610,24 @@ func toQuadValue(opt *Traits, d nosql.Document) (quad.Value, error) {
 	return nil, fmt.Errorf("unsupported value: %#v", d)
 }
 
-func (qs *QuadStore) Quad(val graph.Ref) quad.Quad {
+func (qs *QuadStore) Quad(val graph.Ref) (quad.Quad, error) {
 	h := val.(QuadHash)
-	return quad.Quad{
-		Subject:   qs.NameOf(NodeHash(h.Get(quad.Subject))),
-		Predicate: qs.NameOf(NodeHash(h.Get(quad.Predicate))),
-		Object:    qs.NameOf(NodeHash(h.Get(quad.Object))),
-		Label:     qs.NameOf(NodeHash(h.Get(quad.Label))),
+	var q quad.Quad
+	var err error
+	q.Subject, err = qs.NameOf(NodeHash(h.Get(quad.Subject)))
+	if err != nil {
+		return q, err
+	}
+	q.Predicate, err = qs.NameOf(NodeHash(h.Get(quad.Predicate)))
+	if err != nil {
+		return q, err
 	}
+	q.Object, err = qs.NameOf(NodeHash(h.Get(quad.Object)))
+	if err != nil {
+		return q, err
+	}
+	q.Label, err = qs.NameOf(NodeHash(h.Get(quad.Label)))
+	return q, err
 }
 
 func (qs *QuadStore) QuadIterator(d quad.Direction, val graph.Ref) iterator.Shape {
@@ -655,41 +665,41 @@ func (qs *QuadStore) hashOf(s quad.Value) NodeHash {
 	return NodeHash(hashOf(s))
 }
 
-func (qs *QuadStore) ValueOf(s quad.Value) graph.Ref {
+func (qs *QuadStore) ValueOf(s quad.Value) (graph.Ref, error) {
 	if s == nil {
-		return nil
+		return nil, nil
 	}
-	return qs.hashOf(s)
+	return qs.hashOf(s), nil
 }
 
-func (qs *QuadStore) NameOf(v graph.Ref) quad.Value {
+func (qs *QuadStore) NameOf(v graph.Ref) (quad.Value, error) {
 	if v == nil {
-		return nil
+		return nil, nil
 	} else if v, ok := v.(refs.PreFetchedValue); ok {
-		return v.NameOf()
+		return v.NameOf(), nil
 	}
 	hash := v.(NodeHash)
 	if hash == "" {
-		return nil
+		return nil, nil
 	}
 	if val, ok := qs.ids.Get(string(hash)); ok {
-		return val.(quad.Value)
+		return val.(quad.Value), nil
 	}
 	nd, err := qs.db.FindByKey(context.TODO(), colNodes, hash.key())
 	if err != nil {
 		clog.Errorf("couldn't retrieve node %v: %v", v, err)
-		return nil
+		return nil, err
 	}
 	dv, _ := nd[fldValue].(nosql.Document)
 	qv, err := toQuadValue(&qs.opt, dv)
 	if err != nil {
 		clog.Errorf("couldn't convert node %v: %v", v, err)
-		return nil
+		return nil, err
 	}
 	if id, _ := nd[fldHash].(nosql.String); id == nosql.String(hash) && qv != nil {
 		qs.ids.Put(string(hash), qv)
 	}
-	return qv
+	return qv, nil
 }
 
 func (qs *QuadStore) Stats(ctx context.Context, exact bool) (graph.Stats, error) {
@@ -727,8 +737,8 @@ func (qs *QuadStore) Close() error {
 	return qs.db.Close()
 }
 
-func (qs *QuadStore) QuadDirection(in graph.Ref, d quad.Direction) graph.Ref {
-	return NodeHash(in.(QuadHash).Get(d))
+func (qs *QuadStore) QuadDirection(in graph.Ref, d quad.Direction) (graph.Ref, error) {
+	return NodeHash(in.(QuadHash).Get(d)), nil
 }
 
 func (qs *QuadStore) getSize(col string, constraints []nosql.FieldFilter) (int64, error) {
diff --git a/graph/quadstore.go b/graph/quadstore.go
index 8194960..03be214 100644
--- a/graph/quadstore.go
+++ b/graph/quadstore.go
@@ -54,7 +54,7 @@ func RefsOf(ctx context.Context, qs refs.Namer, nodes []quad.Value) ([]Ref, erro
 
 type QuadIndexer interface {
 	// Given an opaque token, returns the quad for that token from the store.
-	Quad(Ref) quad.Quad
+	Quad(Ref) (quad.Quad, error)
 
 	// Given a direction and a token, creates an iterator of links which have
 	// that node token in that directional field.
@@ -72,7 +72,7 @@ type QuadIndexer interface {
 	//
 	//  qs.ValueOf(qs.Quad(id).Get(dir))
 	//
-	QuadDirection(id Ref, d quad.Direction) Ref
+	QuadDirection(id Ref, d quad.Direction) (Ref, error)
 
 	// Stats returns the number of nodes and quads currently stored.
 	// Exact flag controls the correctness of the value. It can be an estimation, or a precise calculation.
diff --git a/graph/quadwriter.go b/graph/quadwriter.go
index 7b9c750..0ddf989 100644
--- a/graph/quadwriter.go
+++ b/graph/quadwriter.go
@@ -322,7 +322,7 @@ type quadReader struct {
 
 func (r *quadReader) ReadQuad() (quad.Quad, error) {
 	if r.it.Next(context.TODO()) {
-		return r.qs.Quad(r.it.Result()), nil
+		return r.qs.Quad(r.it.Result())
 	}
 	err := r.it.Err()
 	if err == nil {
diff --git a/graph/refs/refs.go b/graph/refs/refs.go
index be6f52d..baab6fb 100644
--- a/graph/refs/refs.go
+++ b/graph/refs/refs.go
@@ -32,10 +32,11 @@ type Ref interface {
 
 type Namer interface {
 	// Given a node ID, return the opaque token used by the QuadStore
-	// to represent that id.
-	ValueOf(quad.Value) Ref
+	// to represent that id. Returns nil, nil on not found.
+	ValueOf(quad.Value) (Ref, error)
 	// Given an opaque token, return the node that it represents.
-	NameOf(Ref) quad.Value
+	// Returns nil, nil on not found.
+	NameOf(Ref) (quad.Value, error)
 }
 
 type BatchNamer interface {
@@ -145,8 +146,12 @@ func ValuesOf(ctx context.Context, qs Namer, vals []Ref) ([]quad.Value, error) {
 		return bq.ValuesOf(ctx, vals)
 	}
 	out := make([]quad.Value, len(vals))
+	var err error
 	for i, v := range vals {
-		out[i] = qs.NameOf(v)
+		out[i], err = qs.NameOf(v)
+		if err != nil {
+			return nil, err
+		}
 	}
 	return out, nil
 }
@@ -157,7 +162,10 @@ func RefsOf(ctx context.Context, qs Namer, nodes []quad.Value) ([]Ref, error) {
 	}
 	values := make([]Ref, len(nodes))
 	for i, node := range nodes {
-		value := qs.ValueOf(node)
+		value, err := qs.ValueOf(node)
+		if err != nil {
+			return nil, err
+		}
 		if value == nil {
 			return nil, fmt.Errorf("not found: %v", node)
 		}
diff --git a/graph/sql/quadstore.go b/graph/sql/quadstore.go
index ed81e2f..72bb067 100644
--- a/graph/sql/quadstore.go
+++ b/graph/sql/quadstore.go
@@ -509,14 +509,24 @@ func (qs *QuadStore) ApplyDeltas(in []graph.Delta, opts graph.IgnoreOpts) error
 	return tx.Commit()
 }
 
-func (qs *QuadStore) Quad(val graph.Ref) quad.Quad {
+func (qs *QuadStore) Quad(val graph.Ref) (quad.Quad, error) {
 	h := val.(QuadHashes)
-	return quad.Quad{
-		Subject:   qs.NameOf(h.Get(quad.Subject)),
-		Predicate: qs.NameOf(h.Get(quad.Predicate)),
-		Object:    qs.NameOf(h.Get(quad.Object)),
-		Label:     qs.NameOf(h.Get(quad.Label)),
+	var q quad.Quad
+	var err error
+	q.Subject, err = qs.NameOf(h.Get(quad.Subject))
+	if err != nil {
+		return q, err
+	}
+	q.Predicate, err = qs.NameOf(h.Get(quad.Predicate))
+	if err != nil {
+		return q, err
 	}
+	q.Object, err = qs.NameOf(h.Get(quad.Object))
+	if err != nil {
+		return q, err
+	}
+	q.Label, err = qs.NameOf(h.Get(quad.Label))
+	return q, err
 }
 
 func (qs *QuadStore) QuadIterator(d quad.Direction, val graph.Ref) iterator.Shape {
@@ -562,8 +572,8 @@ func (qs *QuadStore) QuadsAllIterator() iterator.Shape {
 	return qs.newIterator(AllQuads(""))
 }
 
-func (qs *QuadStore) ValueOf(s quad.Value) graph.Ref {
-	return NodeHash(HashOf(s))
+func (qs *QuadStore) ValueOf(s quad.Value) (graph.Ref, error) {
+	return NodeHash(HashOf(s)), nil
 }
 
 // NullTime represents a time.Time that may be null. NullTime implements the
@@ -603,34 +613,28 @@ func (nt NullTime) Value() (driver.Value, error) {
 	return nt.Time, nil
 }
 
-func (qs *QuadStore) NameOf(v graph.Ref) quad.Value {
+func (qs *QuadStore) NameOf(v graph.Ref) (quad.Value, error) {
 	if v == nil {
-		if clog.V(2) {
-			clog.Infof("NameOf was nil")
-		}
-		return nil
+		return nil, nil
 	} else if v, ok := v.(refs.PreFetchedValue); ok {
-		return v.NameOf()
+		return v.NameOf(), nil
 	}
 	var hash NodeHash
 	switch h := v.(type) {
 	case refs.PreFetchedValue:
-		return h.NameOf()
+		return h.NameOf(), nil
 	case NodeHash:
 		hash = h
 	case refs.ValueHash:
 		hash = NodeHash{h}
 	default:
-		panic(fmt.Errorf("unexpected token: %T", v))
+		return nil, fmt.Errorf("unexpected token: %T", v)
 	}
 	if !hash.Valid() {
-		if clog.V(2) {
-			clog.Infof("NameOf was nil")
-		}
-		return nil
+		return nil, nil
 	}
 	if val, ok := qs.ids.Get(hash.String()); ok {
-		return val.(quad.Value)
+		return val.(quad.Value), nil
 	}
 	query := `SELECT
 		value,
@@ -670,9 +674,8 @@ func (qs *QuadStore) NameOf(v graph.Ref) quad.Value {
 		&vtime,
 	); err != nil {
 		if err != sql.ErrNoRows {
-			clog.Errorf("Couldn't execute value lookup: %v", err)
+			return nil, fmt.Errorf("error executing value lookup: %w", err)
 		}
-		return nil
 	}
 	var val quad.Value
 	if str.Valid {
@@ -704,15 +707,14 @@ func (qs *QuadStore) NameOf(v graph.Ref) quad.Value {
 	} else {
 		qv, err := pquads.UnmarshalValue(data)
 		if err != nil {
-			clog.Errorf("Couldn't unmarshal value: %v", err)
-			return nil
+			return nil, fmt.Errorf("unmarshal value: %w", err)
 		}
 		val = qv
 	}
 	if val != nil {
 		qs.ids.Put(hash.String(), val)
 	}
-	return val
+	return val, nil
 }
 
 func (qs *QuadStore) Stats(ctx context.Context, exact bool) (graph.Stats, error) {
@@ -756,8 +758,8 @@ func (qs *QuadStore) Close() error {
 	return qs.db.Close()
 }
 
-func (qs *QuadStore) QuadDirection(in graph.Ref, d quad.Direction) graph.Ref {
-	return NodeHash{in.(QuadHashes).Get(d)}
+func (qs *QuadStore) QuadDirection(in graph.Ref, d quad.Direction) (graph.Ref, error) {
+	return NodeHash{in.(QuadHashes).Get(d)}, nil
 }
 
 func (qs *QuadStore) sizeForIterator(dir quad.Direction, hash NodeHash) int64 {
diff --git a/internal/decompressor/decompressor.go b/internal/decompressor/decompressor.go
index e8057d4..905f5dc 100644
--- a/internal/decompressor/decompressor.go
+++ b/internal/decompressor/decompressor.go
@@ -36,9 +36,9 @@ func New(r io.Reader) (io.Reader, error) {
 		return nil, err
 	}
 	switch {
-	case bytes.Compare(buf[:2], []byte(gzipMagic)) == 0:
+	case bytes.Equal(buf[:2], []byte(gzipMagic)):
 		return gzip.NewReader(br)
-	case bytes.Compare(buf[:3], []byte(b2zipMagic)) == 0:
+	case bytes.Equal(buf[:3], []byte(b2zipMagic)):
 		return bzip2.NewReader(br), nil
 	default:
 		return br, nil
diff --git a/internal/gephi/stream.go b/internal/gephi/stream.go
index 3125473..c3d8e59 100644
--- a/internal/gephi/stream.go
+++ b/internal/gephi/stream.go
@@ -223,7 +223,12 @@ func (s *GraphStreamHandler) serveRawQuads(ctx context.Context, gs *GraphStream,
 		if qv == nil {
 			continue
 		}
-		q := s.QS.Quad(qv)
+		q, err := s.QS.Quad(qv)
+		if err != nil {
+			// TODO: no error handling
+			clog.Warningf("error fetching quad value: %v", err)
+			continue
+		}
 		quad.HashTo(q.Subject, sh[:])
 		quad.HashTo(q.Object, oh[:])
 		s, o := gs.addNode(q.Subject, sh, nil), gs.addNode(q.Object, oh, nil)
@@ -250,8 +255,9 @@ func (s *GraphStreamHandler) serveNodesWithProps(ctx context.Context, gs *GraphS
 
 	// list of predicates marked as inline properties for gephi
 	inline := make(map[quad.Value]struct{})
-	err := propsPath.Iterate(ctx).EachValue(s.QS, func(v quad.Value) {
+	err := propsPath.Iterate(ctx).EachValue(s.QS, func(v quad.Value) error {
 		inline[v] = struct{}{}
+		return nil
 	})
 	if err != nil {
 		clog.Errorf("cannot iterate over properties: %v", err)
@@ -273,9 +279,9 @@ func (s *GraphStreamHandler) serveNodesWithProps(ctx context.Context, gs *GraphS
 	itc := iterator.Iterate(ictx, nodes).On(s.QS).Limit(limit)
 
 	qi := 0
-	_ = itc.EachValuePair(s.QS, func(v graph.Ref, nv quad.Value) {
+	_ = itc.EachValuePair(s.QS, func(v graph.Ref, nv quad.Value) error {
 		if _, skip := ignore[nv]; skip {
-			return
+			return nil
 		}
 		// list of inline properties
 		props := make(map[quad.Value]quad.Value)
@@ -293,7 +299,10 @@ func (s *GraphStreamHandler) serveNodesWithProps(ctx context.Context, gs *GraphS
 			if sid == "" {
 				sid = gs.addNode(nv, h, props)
 			}
-			q := s.QS.Quad(predIt.Result())
+			q, err := s.QS.Quad(predIt.Result())
+			if err != nil {
+				continue
+			}
 			if _, ok := inline[q.Predicate]; ok {
 				props[q.Predicate] = q.Object
 				ignore[q.Object] = struct{}{}
@@ -309,23 +318,23 @@ func (s *GraphStreamHandler) serveNodesWithProps(ctx context.Context, gs *GraphS
 				qi++
 				if err := gs.Flush(); err != nil {
 					cancel()
-					return
+					return nil
 				}
 			}
 		}
 		if err := predIt.Err(); err != nil {
 			cancel()
-			return
+			return nil
 		} else if sid == "" {
-			return
+			return nil
 		}
 		if len(props) != 0 {
 			gs.ChangeNode(nv, sid, props)
 		}
 		if err := gs.Flush(); err != nil {
 			cancel()
-			return
 		}
+		return nil
 	})
 }
 
diff --git a/query/gizmo/gizmo.go b/query/gizmo/gizmo.go
index b091fcf..12bb6e0 100644
--- a/query/gizmo/gizmo.go
+++ b/query/gizmo/gizmo.go
@@ -135,28 +135,35 @@ func (s *Session) quadValueToNative(v quad.Value) interface{} {
 	return out
 }
 
-func (s *Session) tagsToValueMap(m map[string]graph.Ref) map[string]interface{} {
+func (s *Session) tagsToValueMap(m map[string]graph.Ref) (map[string]interface{}, error) {
 	outputMap := make(map[string]interface{})
 	for k, v := range m {
-		if o := s.quadValueToNative(s.qs.NameOf(v)); o != nil {
+		nv, err := s.qs.NameOf(v)
+		if err != nil {
+			return nil, err
+		}
+		if o := s.quadValueToNative(nv); o != nil {
 			outputMap[k] = o
 		}
 	}
 	if len(outputMap) == 0 {
-		return nil
+		return nil, nil
 	}
-	return outputMap
+	return outputMap, nil
 }
 func (s *Session) runIteratorToArray(it iterator.Shape, limit int) ([]map[string]interface{}, error) {
 	ctx := s.context()
 
 	output := make([]map[string]interface{}, 0)
-	err := iterator.Iterate(ctx, it).Limit(limit).TagEach(func(tags map[string]graph.Ref) {
-		tm := s.tagsToValueMap(tags)
-		if tm == nil {
-			return
+	err := iterator.Iterate(ctx, it).Limit(limit).TagEach(func(tags map[string]graph.Ref) error {
+		tm, err := s.tagsToValueMap(tags)
+		if err != nil {
+			return err
 		}
-		output = append(output, tm)
+		if tm != nil {
+			output = append(output, tm)
+		}
+		return nil
 	})
 	if err != nil {
 		return nil, err
@@ -168,10 +175,11 @@ func (s *Session) runIteratorToArrayNoTags(it iterator.Shape, limit int) ([]inte
 	ctx := s.context()
 
 	output := make([]interface{}, 0)
-	err := iterator.Iterate(ctx, it).Paths(false).Limit(limit).EachValue(s.qs, func(v quad.Value) {
+	err := iterator.Iterate(ctx, it).Paths(false).Limit(limit).EachValue(s.qs, func(v quad.Value) error {
 		if o := s.quadValueToNative(v); o != nil {
 			output = append(output, o)
 		}
+		return nil
 	})
 	if err != nil {
 		return nil, err
@@ -186,21 +194,17 @@ func (s *Session) runIteratorWithCallback(it iterator.Shape, callback goja.Value
 	}
 	ctx, cancel := context.WithCancel(s.context())
 	defer cancel()
-	var gerr error
-	err := iterator.Iterate(ctx, it).Paths(true).Limit(limit).TagEach(func(tags map[string]graph.Ref) {
-		tm := s.tagsToValueMap(tags)
-		if tm == nil {
-			return
+	return iterator.Iterate(ctx, it).Paths(true).Limit(limit).TagEach(func(tags map[string]graph.Ref) error {
+		tm, err := s.tagsToValueMap(tags)
+		if err != nil || tm == nil {
+			return err
 		}
-		if _, err := fnc(this.This, s.vm.ToValue(tm)); err != nil {
-			gerr = err
+		_, err = fnc(this.This, s.vm.ToValue(tm))
+		if err != nil {
 			cancel()
 		}
+		return err
 	})
-	if gerr != nil {
-		err = gerr
-	}
-	return err
 }
 
 func (s *Session) send(ctx context.Context, r *Result) bool {
@@ -226,11 +230,12 @@ func (s *Session) runIterator(it iterator.Shape) error {
 	ctx, cancel := context.WithCancel(s.context())
 	defer cancel()
 	stop := false
-	err := iterator.Iterate(ctx, it).Paths(true).TagEach(func(tags map[string]graph.Ref) {
+	err := iterator.Iterate(ctx, it).Paths(true).TagEach(func(tags map[string]graph.Ref) error {
 		if !s.send(ctx, &Result{Tags: tags}) {
 			cancel()
 			stop = true
 		}
+		return nil
 	})
 	if stop {
 		err = nil
@@ -386,7 +391,12 @@ func (it *results) jsonResult() interface{} {
 	}
 	sort.Strings(tagKeys)
 	for _, k := range tagKeys {
-		if name := it.s.qs.NameOf(tags[k]); name != nil {
+		name, err := it.s.qs.NameOf(tags[k])
+		if err != nil {
+			it.err = err
+			return nil
+		}
+		if name != nil {
 			obj[k] = it.s.quadValueToNative(name)
 		} else {
 			delete(obj, k)
@@ -423,7 +433,12 @@ func (it *results) replResult() interface{} {
 			if k == "$_" {
 				continue
 			}
-			out += fmt.Sprintf("%s : %s\n", k, quadValueToString(it.s.qs.NameOf(tags[k])))
+			knv, err := it.s.qs.NameOf(tags[k])
+			if err != nil {
+				// ignore
+				continue
+			}
+			out += fmt.Sprintf("%s : %s\n", k, quadValueToString(knv))
 		}
 	} else {
 		switch export := data.Val.(type) {
diff --git a/query/graphql/graphql.go b/query/graphql/graphql.go
index f24d729..eb3b51a 100644
--- a/query/graphql/graphql.go
+++ b/query/graphql/graphql.go
@@ -225,19 +225,25 @@ func iterateObject(ctx context.Context, qs graph.QuadStore, f *field, p *path.Pa
 			}
 			nv := it.Result()
 			obj := make(map[string]interface{})
-			obj[ValueKey] = qs.NameOf(nv)
-			func() {
-				sit := qs.QuadIterator(quad.Subject, nv).Iterate()
-				defer sit.Close()
-				for sit.Next(ctx) {
-					q := qs.Quad(sit.Result())
-					if p, ok := q.Predicate.(quad.IRI); ok {
-						obj[string(p)] = q.Object
-					} else {
-						obj[quad.ToString(q.Predicate)] = q.Object
-					}
+			var err error
+			obj[ValueKey], err = qs.NameOf(nv)
+			if err != nil {
+				return nil, err
+			}
+			sit := qs.QuadIterator(quad.Subject, nv).Iterate()
+			for sit.Next(ctx) {
+				q, err := qs.Quad(sit.Result())
+				if err != nil {
+					sit.Close()
+					return nil, err
+				}
+				if p, ok := q.Predicate.(quad.IRI); ok {
+					obj[string(p)] = q.Object
+				} else {
+					obj[quad.ToString(q.Predicate)] = q.Object
 				}
-			}()
+			}
+			sit.Close()
 			out = append(out, obj)
 		}
 		return out, it.Err()
diff --git a/query/linkedql/iter_tags.go b/query/linkedql/iter_tags.go
index 6846fdf..b63b203 100644
--- a/query/linkedql/iter_tags.go
+++ b/query/linkedql/iter_tags.go
@@ -39,7 +39,11 @@ func (it *TagsIterator) Next(ctx context.Context) bool {
 
 func (it *TagsIterator) addQuadFromRef(dataset *ld.RDFDataset, subject ld.Node, tag string, ref refs.Ref) error {
 	p := ld.NewIRI(tag)
-	o, err := jsonld.ToNode(it.ValueIt.Namer.NameOf(ref))
+	rname, err := it.ValueIt.Namer.NameOf(ref)
+	if err != nil {
+		return err
+	}
+	o, err := jsonld.ToNode(rname)
 	if err != nil {
 		return err
 	}
@@ -49,7 +53,10 @@ func (it *TagsIterator) addQuadFromRef(dataset *ld.RDFDataset, subject ld.Node,
 }
 
 func toSubject(namer refs.Namer, result refs.Ref) (ld.Node, error) {
-	v := namer.NameOf(result)
+	v, err := namer.NameOf(result)
+	if err != nil {
+		return nil, err
+	}
 	id, ok := v.(quad.Identifier)
 	if !ok {
 		return nil, fmt.Errorf("Expected subject to be an entity identifier but instead received: %v", v)
diff --git a/query/linkedql/iter_values.go b/query/linkedql/iter_values.go
index 8c2e4a9..f3035e2 100644
--- a/query/linkedql/iter_values.go
+++ b/query/linkedql/iter_values.go
@@ -20,6 +20,7 @@ type ValueIterator struct {
 	Namer   refs.Namer
 	path    *path.Path
 	scanner iterator.Scanner
+	err     error
 }
 
 // NewValueIterator returns a new ValueIterator for a path and namer.
@@ -50,7 +51,11 @@ func (it *ValueIterator) Value() quad.Value {
 	if it.scanner == nil {
 		return nil
 	}
-	return it.Namer.NameOf(it.scanner.Result())
+	rname, err := it.Namer.NameOf(it.scanner.Result())
+	if err != nil {
+		it.err = err
+	}
+	return rname
 }
 
 // Result implements query.Iterator.
@@ -61,6 +66,9 @@ func (it *ValueIterator) Result() interface{} {
 
 // Err implements query.Iterator.
 func (it *ValueIterator) Err() error {
+	if it.err != nil {
+		return it.err
+	}
 	if it.scanner == nil {
 		return nil
 	}
diff --git a/query/mql/fill.go b/query/mql/fill.go
index 8b3aa6a..706f351 100644
--- a/query/mql/fill.go
+++ b/query/mql/fill.go
@@ -22,14 +22,18 @@ import (
 	"github.com/cayleygraph/quad"
 )
 
-func (q *Query) treeifyResult(tags map[string]graph.Ref) map[ResultPath]string {
+func (q *Query) treeifyResult(tags map[string]graph.Ref) (map[ResultPath]string, error) {
 	// Transform the map into something a little more interesting.
 	results := make(map[Path]string)
 	for k, v := range tags {
 		if v == nil {
 			continue
 		}
-		results[Path(k)] = quadValueToNative(q.ses.qs.NameOf(v))
+		nv, err := q.ses.qs.NameOf(v)
+		if err != nil {
+			return nil, err
+		}
+		results[Path(k)] = quadValueToNative(nv)
 	}
 	resultPaths := make(map[ResultPath]string)
 	for k, v := range results {
@@ -110,7 +114,7 @@ func (q *Query) treeifyResult(tags map[string]graph.Ref) map[ResultPath]string {
 		}
 	}
 
-	return resultPaths
+	return resultPaths, nil
 }
 
 func (q *Query) buildResults() {
diff --git a/query/sexp/parser.go b/query/sexp/parser.go
index 8a90450..34c95fa 100644
--- a/query/sexp/parser.go
+++ b/query/sexp/parser.go
@@ -190,7 +190,7 @@ func getIdentString(tree *peg.ExpressionTree) string {
 		}
 	} else {
 		if tree.Value != '"' {
-			out += string(tree.Value)
+			out += string([]rune{rune(tree.Value)})
 		}
 	}
 	return out
diff --git a/query/sexp/session.go b/query/sexp/session.go
index bd3dcf2..47bcf78 100644
--- a/query/sexp/session.go
+++ b/query/sexp/session.go
@@ -97,6 +97,7 @@ type results struct {
 	col      query.Collation
 	it       iterator.Scanner
 	nextPath bool
+	err      error
 }
 
 func (it *results) Next(ctx context.Context) bool {
@@ -129,7 +130,12 @@ func (it *results) Result() interface{} {
 		if k == "$_" {
 			continue
 		}
-		out += fmt.Sprintf("%s : %s\n", k, it.s.qs.NameOf(m[k]))
+		knv, err := it.s.qs.NameOf(m[k])
+		if err != nil {
+			it.err = err
+			return nil
+		}
+		out += fmt.Sprintf("%s : %s\n", k, knv)
 	}
 	return out
 }
diff --git a/query/shape/shape.go b/query/shape/shape.go
index 3ce233c..eebe21f 100644
--- a/query/shape/shape.go
+++ b/query/shape/shape.go
@@ -51,7 +51,10 @@ type resolveValues struct {
 
 func (r resolveValues) OptimizeShape(ctx context.Context, s Shape) (Shape, bool) {
 	if l, ok := s.(Lookup); ok {
-		return l.resolve(r.qs), true
+		lv, err := l.resolve(r.qs)
+		if err == nil {
+			return lv, true
+		}
 	}
 	return s, false
 }
@@ -818,24 +821,31 @@ func (s *Lookup) Add(v ...quad.Value) {
 var _ valueResolver = graph.QuadStore(nil)
 
 type valueResolver interface {
-	ValueOf(v quad.Value) refs.Ref
+	ValueOf(v quad.Value) (refs.Ref, error)
 }
 
-func (s Lookup) resolve(qs valueResolver) Shape {
+func (s Lookup) resolve(qs valueResolver) (Shape, error) {
 	// TODO: check if QS supports batch lookup
 	vals := make([]refs.Ref, 0, len(s))
 	for _, v := range s {
-		if gv := qs.ValueOf(v); gv != nil {
+		gv, err := qs.ValueOf(v)
+		if err != nil {
+			return nil, err
+		}
+		if gv != nil {
 			vals = append(vals, gv)
 		}
 	}
 	if len(vals) == 0 {
-		return nil
+		return nil, nil
 	}
-	return Fixed(vals)
+	return Fixed(vals), nil
 }
 func (s Lookup) BuildIterator(qs graph.QuadStore) iterator.Shape {
-	f := s.resolve(qs)
+	f, err := s.resolve(qs)
+	if err != nil {
+		return iterator.NewError(err)
+	}
 	if IsNull(f) {
 		return iterator.NewNull()
 	}
@@ -850,7 +860,10 @@ func (s Lookup) Optimize(ctx context.Context, r Optimizer) (Shape, bool) {
 		return ns, true
 	}
 	if qs, ok := r.(valueResolver); ok {
-		ns, opt = s.resolve(qs), true
+		res, err := s.resolve(qs)
+		if err == nil {
+			ns, opt = res, true
+		}
 	}
 	return ns, opt
 }
diff --git a/schema/loader.go b/schema/loader.go
index 64b9620..9fca40e 100644
--- a/schema/loader.go
+++ b/schema/loader.go
@@ -103,7 +103,11 @@ func (c *Config) LoadToDepth(ctx context.Context, qs graph.QuadStore, dst interf
 	if len(ids) != 0 {
 		fixed := iterator.NewFixed()
 		for _, id := range ids {
-			fixed.Add(qs.ValueOf(id))
+			idv, err := qs.ValueOf(id)
+			if err != nil {
+				return err
+			}
+			fixed.Add(idv)
 		}
 		it = fixed
 	}
@@ -360,7 +364,10 @@ func (l *loader) loadToValue(ctx context.Context, dst reflect.Value, depth int,
 			var sv reflect.Value
 			if recursive {
 				if ptr {
-					fv := l.qs.NameOf(fv)
+					fv, err := l.qs.NameOf(fv)
+					if err != nil {
+						return err
+					}
 					var ok bool
 					sv, ok = l.seen[fv]
 					if ok && sv.Type().AssignableTo(f.Type) {
@@ -376,7 +383,10 @@ func (l *loader) loadToValue(ctx context.Context, dst reflect.Value, depth int,
 					return err
 				}
 			} else {
-				fv := l.qs.NameOf(fv)
+				fv, err := l.qs.NameOf(fv)
+				if err != nil {
+					return err
+				}
 				if fv == nil {
 					continue
 				}
@@ -459,7 +469,10 @@ func (l *loader) loadIteratorToDepth(ctx context.Context, dst reflect.Value, dep
 		if ctxDone() {
 			return ctx.Err()
 		}
-		id := l.qs.NameOf(it.Result())
+		id, err := l.qs.NameOf(it.Result())
+		if err != nil {
+			return err
+		}
 		if id != nil {
 			if sv, ok := l.seen[id]; ok {
 				if slice {
@@ -508,7 +521,7 @@ func (l *loader) loadIteratorToDepth(ctx context.Context, dst reflect.Value, dep
 			}
 			l.seen[id] = sv
 		}
-		err := l.loadToValue(ctx, cur, depth, mo, "")
+		err = l.loadToValue(ctx, cur, depth, mo, "")
 		if err == errRequiredFieldIsMissing {
 			if !slice && !chanl {
 				return err
diff --git a/writer/single.go b/writer/single.go
index 42a58d4..26ed9fb 100644
--- a/writer/single.go
+++ b/writer/single.go
@@ -82,7 +82,10 @@ func (s *Single) RemoveQuad(q quad.Quad) error {
 //
 // It returns ErrNodeNotExists if node is missing.
 func (s *Single) RemoveNode(v quad.Value) error {
-	gv := s.qs.ValueOf(v)
+	gv, err := s.qs.ValueOf(v)
+	if err != nil {
+		return err
+	}
 	if gv == nil {
 		return graph.ErrNodeNotExists
 	}


Test patch:
diff --git a/cmd/cayleyexport/cayleyexport_test.go b/cmd/cayleyexport/cayleyexport_test.go
index f05b514..c25fd80 100644
--- a/cmd/cayleyexport/cayleyexport_test.go
+++ b/cmd/cayleyexport/cayleyexport_test.go
@@ -53,7 +53,7 @@ func TestCayleyExport(t *testing.T) {
 	addr := fmt.Sprintf("127.0.0.1:%d", port)
 	uri := fmt.Sprintf("http://%s", addr)
 	go serve(addr)
-	time.Sleep(3)
+	time.Sleep(300 * time.Millisecond)
 	cmd := NewCmd()
 	b := bytes.NewBufferString("")
 	cmd.SetOut(b)
diff --git a/cmd/cayleyimport/cayleyimport_test.go b/cmd/cayleyimport/cayleyimport_test.go
index 5bf7f15..b655a83 100644
--- a/cmd/cayleyimport/cayleyimport_test.go
+++ b/cmd/cayleyimport/cayleyimport_test.go
@@ -35,7 +35,7 @@ func TestCayleyImport(t *testing.T) {
 	addr := fmt.Sprintf("127.0.0.1:%d", port)
 	uri := fmt.Sprintf("http://%s", addr)
 	go serve(addr)
-	time.Sleep(3)
+	time.Sleep(3 * time.Nanosecond)
 	cmd := NewCmd()
 	b := bytes.NewBufferString("")
 	cmd.SetOut(b)
diff --git a/graph/graphtest/graphtest.go b/graph/graphtest/graphtest.go
index 29b13a0..cfb9884 100644
--- a/graph/graphtest/graphtest.go
+++ b/graph/graphtest/graphtest.go
@@ -137,7 +137,9 @@ func IteratedQuadsNext(t testing.TB, qs graph.QuadStore, it iterator.Scanner) []
 	ctx := context.TODO()
 	var res quad.ByQuadString
 	for it.Next(ctx) {
-		res = append(res, qs.Quad(it.Result()))
+		qsq, err := qs.Quad(it.Result())
+		require.NoError(t, err)
+		res = append(res, qsq)
 	}
 	require.Nil(t, it.Err())
 	sort.Sort(res)
@@ -191,7 +193,9 @@ func IteratedStrings(t testing.TB, qs graph.QuadStore, s iterator.Shape) []strin
 	defer it.Close()
 	var res []string
 	for it.Next(ctx) {
-		res = append(res, quad.ToString(qs.NameOf(it.Result())))
+		qsn, err := qs.NameOf(it.Result())
+		require.Nil(t, err)
+		res = append(res, quad.ToString(qsn))
 	}
 	require.Nil(t, it.Err())
 	sort.Strings(res)
@@ -203,7 +207,9 @@ func IteratedValues(t testing.TB, qs graph.QuadStore, s iterator.Shape) []quad.V
 	it := s.Iterate()
 	var res []quad.Value
 	for it.Next(ctx) {
-		res = append(res, qs.NameOf(it.Result()))
+		itn, err := qs.NameOf(it.Result())
+		require.Nil(t, err)
+		res = append(res, itn)
 	}
 	require.Nil(t, it.Err())
 	sort.Sort(quad.ByValueString(res))
@@ -226,9 +232,11 @@ func TestLoadOneQuad(t testing.TB, gen testutil.DatabaseFunc, c *Config) {
 	err := w.AddQuad(q)
 	require.NoError(t, err)
 	for _, pq := range []quad.String{"Something", "points_to", "Something Else", "context"} {
-		tok := qs.ValueOf(pq)
+		tok, err := qs.ValueOf(pq)
+		require.Nil(t, err)
 		require.NotNil(t, tok, "quad store failed to find value: %q", pq)
-		val := qs.NameOf(tok)
+		val, err := qs.NameOf(tok)
+		require.Nil(t, err)
 		require.NotNil(t, val, "quad store failed to decode value: %q", pq)
 		require.Equal(t, pq, val, "quad store failed to roundtrip value: %q", pq)
 	}
@@ -490,7 +498,9 @@ func TestSizes(t testing.TB, gen testutil.DatabaseFunc, conf *Config) {
 	require.Equal(t, exp, st, "Unexpected quadstore size")
 
 	if qss, ok := qs.(ValueSizer); ok {
-		s := qss.SizeOf(qs.ValueOf(quad.String("B")))
+		sn, err := qs.ValueOf(quad.String("B"))
+		require.Nil(t, err)
+		s := qss.SizeOf(sn)
 		require.Equal(t, int64(5), s, "Unexpected quadstore value size")
 	}
 
@@ -527,7 +537,9 @@ func TestSizes(t testing.TB, gen testutil.DatabaseFunc, conf *Config) {
 	}
 
 	if qss, ok := qs.(ValueSizer); ok {
-		s := qss.SizeOf(qs.ValueOf(quad.String("B")))
+		vn, err := qs.ValueOf(quad.String("B"))
+		require.NoError(t, err)
+		s := qss.SizeOf(vn)
 		require.Equal(t, int64(4), s, "Unexpected quadstore value size")
 	}
 }
@@ -574,7 +586,9 @@ func TestIterator(t testing.TB, gen testutil.DatabaseFunc, _ *Config) {
 	itc := it.Lookup()
 	defer itc.Close()
 	for _, pq := range expect {
-		ok := itc.Contains(ctx, qs.ValueOf(quad.Raw(pq)))
+		qsv, err := qs.ValueOf(quad.Raw(pq))
+		require.NoError(t, err)
+		ok := itc.Contains(ctx, qsv)
 		require.NoError(t, itc.Err())
 		require.True(t, ok, "Failed to find and check %q correctly", pq)
 
@@ -596,7 +610,8 @@ func TestIterator(t testing.TB, gen testutil.DatabaseFunc, _ *Config) {
 	defer itn.Close()
 	require.True(t, itn.Next(ctx))
 
-	q := qs.Quad(itn.Result())
+	q, err := qs.Quad(itn.Result())
+	require.NoError(t, err)
 	require.Nil(t, itn.Err())
 	require.True(t, q.IsValid(), "Invalid quad returned: %q", q)
 	set := MakeQuadSet()
@@ -643,7 +658,9 @@ func TestSetIterator(t testing.TB, gen testutil.DatabaseFunc, _ *Config) {
 	}
 
 	// Subject iterator.
-	it := qs.QuadIterator(quad.Subject, qs.ValueOf(quad.String("C")))
+	qsv, err := qs.ValueOf(quad.String("C"))
+	require.NoError(t, err)
+	it := qs.QuadIterator(quad.Subject, qsv)
 
 	expectIteratedQuads(it, []quad.Quad{
 		quad.Make("C", "follows", "B", nil),
@@ -661,15 +678,19 @@ func TestSetIterator(t testing.TB, gen testutil.DatabaseFunc, _ *Config) {
 	})
 
 	// Object iterator.
-	it = qs.QuadIterator(quad.Object, qs.ValueOf(quad.String("F")))
+	qsv, err = qs.ValueOf(quad.String("F"))
+	require.NoError(t, err)
+	it = qs.QuadIterator(quad.Object, qsv)
 
 	expectIteratedQuads(it, []quad.Quad{
 		quad.Make("B", "follows", "F", nil),
 		quad.Make("E", "follows", "F", nil),
 	})
 
+	qsv, err = qs.ValueOf(quad.String("B"))
+	require.NoError(t, err)
 	and = iterator.NewAnd(
-		qs.QuadIterator(quad.Subject, qs.ValueOf(quad.String("B"))),
+		qs.QuadIterator(quad.Subject, qsv),
 		it,
 	)
 
@@ -678,7 +699,9 @@ func TestSetIterator(t testing.TB, gen testutil.DatabaseFunc, _ *Config) {
 	})
 
 	// Predicate iterator.
-	it = qs.QuadIterator(quad.Predicate, qs.ValueOf(quad.String("status")))
+	qsv, err = qs.ValueOf(quad.String("status"))
+	require.NoError(t, err)
+	it = qs.QuadIterator(quad.Predicate, qsv)
 
 	expectIteratedQuads(it, []quad.Quad{
 		quad.Make("B", "status", "cool", "status_graph"),
@@ -687,7 +710,9 @@ func TestSetIterator(t testing.TB, gen testutil.DatabaseFunc, _ *Config) {
 	})
 
 	// Label iterator.
-	it = qs.QuadIterator(quad.Label, qs.ValueOf(quad.String("status_graph")))
+	qsv, err = qs.ValueOf(quad.String("status_graph"))
+	require.NoError(t, err)
+	it = qs.QuadIterator(quad.Label, qsv)
 
 	expectIteratedQuads(it, []quad.Quad{
 		quad.Make("B", "status", "cool", "status_graph"),
@@ -696,8 +721,10 @@ func TestSetIterator(t testing.TB, gen testutil.DatabaseFunc, _ *Config) {
 	})
 
 	// Order is important
+	qsv, err = qs.ValueOf(quad.String("B"))
+	require.NoError(t, err)
 	and = iterator.NewAnd(
-		qs.QuadIterator(quad.Subject, qs.ValueOf(quad.String("B"))),
+		qs.QuadIterator(quad.Subject, qsv),
 		it,
 	)
 
@@ -706,9 +733,11 @@ func TestSetIterator(t testing.TB, gen testutil.DatabaseFunc, _ *Config) {
 	})
 
 	// Order is important
+	qsv, err = qs.ValueOf(quad.String("B"))
+	require.NoError(t, err)
 	and = iterator.NewAnd(
 		it,
-		qs.QuadIterator(quad.Subject, qs.ValueOf(quad.String("B"))),
+		qs.QuadIterator(quad.Subject, qsv),
 	)
 
 	expectIteratedQuads(and, []quad.Quad{
@@ -722,7 +751,8 @@ func TestDeleteQuad(t testing.TB, gen testutil.DatabaseFunc, _ *Config) {
 
 	w := testutil.MakeWriter(t, qs, opts, MakeQuadSet()...)
 
-	vn := qs.ValueOf(quad.Raw("E"))
+	vn, err := qs.ValueOf(quad.Raw("E"))
+	require.NoError(t, err)
 	require.NotNil(t, vn)
 
 	it := qs.QuadIterator(quad.Subject, vn)
@@ -730,10 +760,12 @@ func TestDeleteQuad(t testing.TB, gen testutil.DatabaseFunc, _ *Config) {
 		quad.Make("E", "follows", "F", nil),
 	}, false)
 
-	err := w.RemoveQuad(quad.Make("E", "follows", "F", nil))
+	err = w.RemoveQuad(quad.Make("E", "follows", "F", nil))
 	require.NoError(t, err)
 
-	it = qs.QuadIterator(quad.Subject, qs.ValueOf(quad.Raw("E")))
+	qsv, err := qs.ValueOf(quad.Raw("E"))
+	require.NoError(t, err)
+	it = qs.QuadIterator(quad.Subject, qsv)
 	ExpectIteratedQuads(t, qs, it, nil, false)
 
 	it = qs.QuadsAllIterator()
@@ -761,7 +793,9 @@ func TestDeletedFromIterator(t testing.TB, gen testutil.DatabaseFunc, conf *Conf
 	w := testutil.MakeWriter(t, qs, opts, MakeQuadSet()...)
 
 	// Subject iterator.
-	it := qs.QuadIterator(quad.Subject, qs.ValueOf(quad.Raw("E")))
+	qsv, err := qs.ValueOf(quad.Raw("E"))
+	require.NoError(t, err)
+	it := qs.QuadIterator(quad.Subject, qsv)
 
 	ExpectIteratedQuads(t, qs, it, []quad.Quad{
 		quad.Make("E", "follows", "F", nil),
@@ -800,7 +834,10 @@ func TestLoadTypedQuads(t testing.TB, gen testutil.DatabaseFunc, conf *Config) {
 	})
 	require.NoError(t, err)
 	for _, pq := range values {
-		got := qs.NameOf(qs.ValueOf(pq))
+		qsv, err := qs.ValueOf(pq)
+		require.NoError(t, err)
+		got, err := qs.NameOf(qsv)
+		require.NoError(t, err)
 		if !conf.UnTyped {
 			if pt, ok := pq.(quad.Time); ok {
 				var trim int64
@@ -827,7 +864,10 @@ func TestLoadTypedQuads(t testing.TB, gen testutil.DatabaseFunc, conf *Config) {
 				assert.Equal(t, pq, got, "Failed to roundtrip %q (%T)", pq, pq)
 			}
 			// check if we can get received value again (hash roundtrip)
-			got2 := qs.NameOf(qs.ValueOf(got))
+			gotv, err := qs.ValueOf(got)
+			require.NoError(t, err)
+			got2, err := qs.NameOf(gotv)
+			require.NoError(t, err)
 			assert.Equal(t, got, got2, "Failed to use returned value to get it again")
 		} else {
 			assert.Equal(t, quad.StringOf(pq), quad.StringOf(got), "Failed to roundtrip raw %q (%T)", pq, pq)
@@ -953,9 +993,13 @@ func TestIteratorsAndNextResultOrderA(t testing.TB, gen testutil.DatabaseFunc, c
 	require.NoError(t, err)
 	require.Equal(t, exp, st, "Unexpected quadstore size")
 
-	fixed := iterator.NewFixed(qs.ValueOf(quad.Raw("C")))
+	qsv, err := qs.ValueOf(quad.Raw("C"))
+	require.NoError(t, err)
+	fixed := iterator.NewFixed(qsv)
 
-	fixed2 := iterator.NewFixed(qs.ValueOf(quad.Raw("follows")))
+	qsv, err = qs.ValueOf(quad.Raw("follows"))
+	require.NoError(t, err)
+	fixed2 := iterator.NewFixed(qsv)
 
 	all := qs.NodesAllIterator()
 
@@ -971,7 +1015,9 @@ func TestIteratorsAndNextResultOrderA(t testing.TB, gen testutil.DatabaseFunc, c
 	require.True(t, outerAnd.Next(ctx), "Expected one matching subtree")
 
 	val := outerAnd.Result()
-	require.Equal(t, quad.Raw("C"), qs.NameOf(val))
+	qsn, err := qs.NameOf(val)
+	require.NoError(t, err)
+	require.Equal(t, quad.Raw("C"), qsn)
 
 	var (
 		got    []string
@@ -980,7 +1026,9 @@ func TestIteratorsAndNextResultOrderA(t testing.TB, gen testutil.DatabaseFunc, c
 	for {
 		m := make(map[string]graph.Ref, 1)
 		outerAnd.TagResults(m)
-		got = append(got, quad.ToString(qs.NameOf(m[allTag])))
+		qsn, err = qs.NameOf(m[allTag])
+		require.NoError(t, err)
+		got = append(got, quad.ToString(qsn))
 		if !outerAnd.NextPath(ctx) {
 			break
 		}
diff --git a/graph/iterator/recursive_test.go b/graph/iterator/recursive_test.go
index 248aba5..22185b9 100644
--- a/graph/iterator/recursive_test.go
+++ b/graph/iterator/recursive_test.go
@@ -63,7 +63,9 @@ func TestRecursiveNext(t *testing.T) {
 	expected := []string{"bob", "charlie", "dani", "emily"}
 	var got []string
 	for r.Next(ctx) {
-		got = append(got, quad.ToString(qs.NameOf(r.Result())))
+		qn, err := qs.NameOf(r.Result())
+		require.NoError(t, err)
+		got = append(got, quad.ToString(qn))
 	}
 	sort.Strings(expected)
 	sort.Strings(got)
@@ -80,7 +82,9 @@ func TestRecursiveContains(t *testing.T) {
 	expected := []bool{true, true, false}
 
 	for i, v := range values {
-		ok := r.Contains(ctx, qs.ValueOf(quad.Raw(v)))
+		vn, err := qs.ValueOf(quad.Raw(v))
+		require.NoError(t, err)
+		ok := r.Contains(ctx, vn)
 		require.Equal(t, expected[i], ok)
 	}
 }
@@ -103,11 +107,15 @@ func TestRecursiveNextPath(t *testing.T) {
 	for r.Next(ctx) {
 		res := make(map[string]refs.Ref)
 		r.TagResults(res)
-		got = append(got, quad.ToString(qs.NameOf(res["person"])))
+		vn, err := qs.NameOf(res["person"])
+		require.NoError(t, err)
+		got = append(got, quad.ToString(vn))
 		for r.NextPath(ctx) {
 			res := make(map[string]refs.Ref)
 			r.TagResults(res)
-			got = append(got, quad.ToString(qs.NameOf(res["person"])))
+			vn, err := qs.NameOf(res["person"])
+			require.NoError(t, err)
+			got = append(got, quad.ToString(vn))
 		}
 	}
 	sort.Strings(expected)
diff --git a/graph/iterator/resolver_test.go b/graph/iterator/resolver_test.go
index 9cdd83a..f65c981 100644
--- a/graph/iterator/resolver_test.go
+++ b/graph/iterator/resolver_test.go
@@ -31,7 +31,9 @@ func TestResolverIteratorIterate(t *testing.T) {
 	}
 	expected := make(map[quad.Value]refs.Ref)
 	for _, node := range nodes {
-		expected[node] = qs.ValueOf(node)
+		var err error
+		expected[node], err = qs.ValueOf(node)
+		require.NoError(t, err)
 	}
 	it := iterator.NewResolver(qs, nodes...).Iterate()
 	for _, node := range nodes {
diff --git a/graph/iterator/value_comparison_test.go b/graph/iterator/value_comparison_test.go
index 534ea66..8782356 100644
--- a/graph/iterator/value_comparison_test.go
+++ b/graph/iterator/value_comparison_test.go
@@ -148,7 +148,9 @@ func TestValueComparison(t *testing.T) {
 
 		var got []quad.Value
 		for vc.Next(ctx) {
-			got = append(got, qs.NameOf(vc.Result()))
+			qsv, err := qs.NameOf(vc.Result())
+			require.NoError(t, err)
+			got = append(got, qsv)
 		}
 		if !reflect.DeepEqual(got, test.expect) {
 			t.Errorf("Failed to show %s, got:%q expect:%q", test.message, got, test.expect)
diff --git a/graph/kv/quadstore_test.go b/graph/kv/quadstore_test.go
index 95c1bf3..f5e4325 100644
--- a/graph/kv/quadstore_test.go
+++ b/graph/kv/quadstore_test.go
@@ -53,7 +53,7 @@ func be(v ...uint64) []byte {
 	for i, vi := range v {
 		binary.BigEndian.PutUint64(b[i*8:], vi)
 	}
-	return b[:]
+	return b
 }
 func le(v uint64) []byte {
 	var b [8]byte
diff --git a/graph/linksto_test.go b/graph/linksto_test.go
index 4bd3817..22599bc 100644
--- a/graph/linksto_test.go
+++ b/graph/linksto_test.go
@@ -35,10 +35,13 @@ func TestLinksTo(t *testing.T) {
 	}
 	fixed := iterator.NewFixed()
 
-	val := qs.ValueOf(object)
+	val, err := qs.ValueOf(object)
+	require.NoError(t, err)
 
 	fixed.Add(val)
 	lto := graph.NewLinksTo(qs, fixed, quad.Object).Iterate()
 	require.True(t, lto.Next(ctx))
-	require.Equal(t, q, qs.Quad(lto.Result()))
+	qv, err := qs.Quad(lto.Result())
+	require.NoError(t, err)
+	require.Equal(t, q, qv)
 }
diff --git a/graph/memstore/quadstore_test.go b/graph/memstore/quadstore_test.go
index 42b77f4..0330d11 100644
--- a/graph/memstore/quadstore_test.go
+++ b/graph/memstore/quadstore_test.go
@@ -114,7 +114,8 @@ func TestMemstoreValueOf(t *testing.T) {
 	require.Equal(t, exp, st, "Unexpected quadstore size")
 
 	for _, test := range index {
-		v := qs.ValueOf(quad.Raw(test.query))
+		v, err := qs.ValueOf(quad.Raw(test.query))
+		require.NoError(t, err)
 		switch v := v.(type) {
 		default:
 			t.Errorf("ValueOf(%q) returned unexpected type, got:%T expected int64", test.query, v)
@@ -129,10 +130,14 @@ func TestIteratorsAndNextResultOrderA(t *testing.T) {
 	qs, _, _ := makeTestStore(simpleGraph)
 
 	fixed := iterator.NewFixed()
-	fixed.Add(qs.ValueOf(quad.Raw("C")))
+	qsv, err := qs.ValueOf(quad.Raw("C"))
+	require.NoError(t, err)
+	fixed.Add(qsv)
 
 	fixed2 := iterator.NewFixed()
-	fixed2.Add(qs.ValueOf(quad.Raw("follows")))
+	qsv, err = qs.ValueOf(quad.Raw("follows"))
+	require.NoError(t, err)
+	fixed2.Add(qsv)
 
 	all := qs.NodesAllIterator()
 
@@ -149,8 +154,10 @@ func TestIteratorsAndNextResultOrderA(t *testing.T) {
 		t.Error("Expected one matching subtree")
 	}
 	val := outerAnd.Result()
-	if qs.NameOf(val) != quad.Raw("C") {
-		t.Errorf("Matching subtree should be %s, got %s", "barak", qs.NameOf(val))
+	vn, err := qs.NameOf(val)
+	require.NoError(t, err)
+	if vn != quad.Raw("C") {
+		t.Errorf("Matching subtree should be %s, got %s", "barak", vn)
 	}
 
 	var (
@@ -160,7 +167,9 @@ func TestIteratorsAndNextResultOrderA(t *testing.T) {
 	for {
 		m := make(map[string]graph.Ref, 1)
 		outerAnd.TagResults(m)
-		got = append(got, quad.ToString(qs.NameOf(m[allTag])))
+		mv, err := qs.NameOf(m[allTag])
+		require.NoError(t, err)
+		got = append(got, quad.ToString(mv))
 		if !outerAnd.NextPath(ctx) {
 			break
 		}
@@ -208,10 +217,14 @@ func TestRemoveQuad(t *testing.T) {
 	}
 
 	fixed := iterator.NewFixed()
-	fixed.Add(qs.ValueOf(quad.Raw("E")))
+	qsv, err := qs.ValueOf(quad.Raw("E"))
+	require.NoError(t, err)
+	fixed.Add(qsv)
 
 	fixed2 := iterator.NewFixed()
-	fixed2.Add(qs.ValueOf(quad.Raw("follows")))
+	qsv, err = qs.ValueOf(quad.Raw("follows"))
+	require.NoError(t, err)
+	fixed2.Add(qsv)
 
 	innerAnd := iterator.NewAnd(
 		graph.NewLinksTo(qs, fixed, quad.Subject),
diff --git a/graph/sql/sqltest/sqltest.go b/graph/sql/sqltest/sqltest.go
index 1c5d3a9..7ffd412 100644
--- a/graph/sql/sqltest/sqltest.go
+++ b/graph/sql/sqltest/sqltest.go
@@ -89,5 +89,9 @@ func testZeroRune(t testing.TB, create testutil.DatabaseFunc) {
 		Object:    obj,
 	})
 	require.NoError(t, err)
-	require.Equal(t, obj, qs.NameOf(qs.ValueOf(quad.Raw(obj.String()))))
+	qsv, err := qs.ValueOf(quad.Raw(obj.String()))
+	require.NoError(t, err)
+	qsn, err := qs.NameOf(qsv)
+	require.NoError(t, err)
+	require.Equal(t, obj, qsn)
 }
diff --git a/internal/decompressor/decompressor_test.go b/internal/decompressor/decompressor_test.go
index d7f742b..d3437d3 100644
--- a/internal/decompressor/decompressor_test.go
+++ b/internal/decompressor/decompressor_test.go
@@ -89,7 +89,7 @@ func TestDecompressor(t *testing.T) {
 		if err != test.readErr && err != io.EOF {
 			t.Fatalf("Unexpected error for reading %s, got:%v expect:%v", test.message, err, test.err)
 		}
-		if bytes.Compare(p[:n], test.expect) != 0 {
+		if !bytes.Equal(p[:n], test.expect) {
 			t.Errorf("Unexpected read result for %s, got:%q expect:%q", test.message, p[:n], test.expect)
 		}
 	}
diff --git a/query/gizmo/gizmo_test.go b/query/gizmo/gizmo_test.go
index a374dc2..b22ecee 100644
--- a/query/gizmo/gizmo_test.go
+++ b/query/gizmo/gizmo_test.go
@@ -710,7 +710,11 @@ func runQueryGetTag(rec func(), g []quad.Quad, qu string, tag string, limit int)
 		data := it.Result().(*Result)
 		if data.Val == nil {
 			if val := data.Tags[tag]; val != nil {
-				results = append(results, quadValueToString(js.qs.NameOf(val)))
+				nv, err := js.qs.NameOf(val)
+				if err != nil {
+					return nil, err
+				}
+				results = append(results, quadValueToString(nv))
 			}
 		} else {
 			switch v := data.Val.(type) {
diff --git a/query/linkedql/iter_tags_test.go b/query/linkedql/iter_tags_test.go
index 98c29dd..0e2163e 100644
--- a/query/linkedql/iter_tags_test.go
+++ b/query/linkedql/iter_tags_test.go
@@ -63,7 +63,8 @@ func TestToSubject(t *testing.T) {
 	for _, testCase := range testCases {
 		t.Run(testCase.name, func(t *testing.T) {
 			store := memstore.New(testCase.data)
-			r := store.ValueOf(testCase.value)
+			r, err := store.ValueOf(testCase.value)
+			require.NoError(t, err)
 			s, err := toSubject(store, r)
 			if testCase.err == nil {
 				require.NoError(t, err)
diff --git a/query/linkedql/steps/steps_test.go b/query/linkedql/steps/steps_test.go
index d8e3db2..05782f6 100644
--- a/query/linkedql/steps/steps_test.go
+++ b/query/linkedql/steps/steps_test.go
@@ -56,14 +56,19 @@ func readQuery(raw interface{}) (linkedql.Step, error) {
 
 func TestLinkedQL(t *testing.T) {
 	// Using files
-	direcotry := "test-cases"
-	files, err := ioutil.ReadDir(direcotry)
+	directory := "test-cases"
+	files, err := ioutil.ReadDir(directory)
 	if err != nil {
 		require.NoError(t, err)
 	}
 	for _, info := range files {
 		fileName := info.Name()
-		filePath := filepath.Join(direcotry, fileName)
+		filePath := filepath.Join(directory, fileName)
+
+		if !strings.HasSuffix(fileName, ".json") {
+			// skip non-JSON files
+			continue
+		}
 
 		testName := strings.TrimSuffix(fileName, filepath.Ext(fileName))
 		t.Run(testName, func(t *testing.T) {
diff --git a/query/linkedql/steps/test-cases/Back.json b/query/linkedql/steps/test-cases/Back.json
deleted file mode 100644
index 65e2bd4..0000000
--- a/query/linkedql/steps/test-cases/Back.json
+++ /dev/null
@@ -1,24 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@id": "alice",
-    "likes": { "@id": "bob" }
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Back",
-    "from": {
-      "@type": "Visit",
-      "from": {
-        "@type": "Match",
-        "pattern": { "@id": "http://example.com/alice" }
-      },
-      "properties": ["http://example.com/likes"]
-    },
-    "name": ""
-  },
-  "results": [{ "@id": "http://example.com/alice" }]
-}
diff --git a/query/linkedql/steps/test-cases/Both.json b/query/linkedql/steps/test-cases/Both.json
deleted file mode 100644
index a932671..0000000
--- a/query/linkedql/steps/test-cases/Both.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@graph": [
-      { "@id": "bob", "likes": { "@id": "alice" } },
-      { "@id": "dan", "likes": { "@id": "bob" } }
-    ]
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Both",
-    "from": {
-      "@type": "Match",
-      "pattern": { "@id": "http://example.com/bob" }
-    },
-    "properties": "http://example.com/likes"
-  },
-  "results": [
-    { "@id": "http://example.com/dan" },
-    { "@id": "http://example.com/alice" }
-  ]
-}
diff --git a/query/linkedql/steps/test-cases/Count.json b/query/linkedql/steps/test-cases/Count.json
deleted file mode 100644
index ff7339e..0000000
--- a/query/linkedql/steps/test-cases/Count.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@id": "alice",
-    "likes": { "@id": "bob" }
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Count",
-    "from": { "@type": "Match", "pattern": {} }
-  },
-  "results": [4]
-}
diff --git a/query/linkedql/steps/test-cases/Difference.json b/query/linkedql/steps/test-cases/Difference.json
deleted file mode 100644
index 7897eb4..0000000
--- a/query/linkedql/steps/test-cases/Difference.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@id": "alice",
-    "likes": { "@id": "bob" }
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Difference",
-    "from": {
-      "@type": "Vertex",
-      "values": [
-        { "@id": "http://example.com/alice" },
-        { "@id": "http://example.com/likes" }
-      ]
-    },
-    "steps": [
-      { "@type": "Match", "pattern": { "@id": "http://example.com/likes" } }
-    ]
-  },
-  "results": [{ "@id": "http://example.com/alice" }]
-}
diff --git a/query/linkedql/steps/test-cases/Documents.json b/query/linkedql/steps/test-cases/Documents.json
deleted file mode 100644
index 275b113..0000000
--- a/query/linkedql/steps/test-cases/Documents.json
+++ /dev/null
@@ -1,35 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@graph": [
-      { "@id": "alice", "likes": { "@id": "bob" }, "name": "Alice" },
-      { "@id": "bob", "likes": { "@id": "alice" }, "name": "Bob" }
-    ]
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Documents",
-    "from": {
-      "@type": "Properties",
-      "from": { "@type": "Match", "pattern": {} },
-      "names": ["http://example.com/name", "http://example.com/likes"]
-    }
-  },
-  "results": {
-    "@graph": [
-      {
-        "@id": "http://example.com/alice",
-        "http://example.com/likes": [{ "@id": "http://example.com/bob" }],
-        "http://example.com/name": ["Alice"]
-      },
-      {
-        "@id": "http://example.com/bob",
-        "http://example.com/likes": [{ "@id": "http://example.com/alice" }],
-        "http://example.com/name": ["Bob"]
-      }
-    ]
-  }
-}
diff --git a/query/linkedql/steps/test-cases/Has.json b/query/linkedql/steps/test-cases/Has.json
deleted file mode 100644
index 5c62efa..0000000
--- a/query/linkedql/steps/test-cases/Has.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@id": "alice",
-    "likes": { "@id": "bob" }
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Has",
-    "from": { "@type": "Match", "pattern": {} },
-    "property": "http://example.com/likes",
-    "values": [{ "@id": "http://example.com/bob" }]
-  },
-  "results": [{ "@id": "http://example.com/alice" }]
-}
diff --git a/query/linkedql/steps/test-cases/Intersect.json b/query/linkedql/steps/test-cases/Intersect.json
deleted file mode 100644
index 341127b..0000000
--- a/query/linkedql/steps/test-cases/Intersect.json
+++ /dev/null
@@ -1,35 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@graph": [
-      { "@id": "bob", "likes": { "@id": "alice" } },
-      { "@id": "dan", "likes": { "@id": "alice" } }
-    ]
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Intersect",
-    "from": {
-      "@type": "Visit",
-      "from": {
-        "@type": "Match",
-        "pattern": { "@id": "http://example.com/bob" }
-      },
-      "properties": "http://example.com/likes"
-    },
-    "steps": [
-      {
-        "@type": "Visit",
-        "from": {
-          "@type": "Match",
-          "values": { "@id": "http://example.com/bob" }
-        },
-        "properties": "http://example.com/likes"
-      }
-    ]
-  },
-  "results": [{ "@id": "http://example.com/alice" }]
-}
diff --git a/query/linkedql/steps/test-cases/Like.json b/query/linkedql/steps/test-cases/Like.json
deleted file mode 100644
index 2f6917b..0000000
--- a/query/linkedql/steps/test-cases/Like.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@id": "alice",
-    "name": "Alice"
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Like",
-    "from": { "@type": "Match", "pattern": {} },
-    "likePattern": "%ali%"
-  },
-  "results": [{ "@id": "http://example.com/alice" }]
-}
diff --git a/query/linkedql/steps/test-cases/Limit.json b/query/linkedql/steps/test-cases/Limit.json
deleted file mode 100644
index 6c9a297..0000000
--- a/query/linkedql/steps/test-cases/Limit.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@id": "alice",
-    "likes": { "@id": "bob" }
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Limit",
-    "from": { "@type": "Match", "pattern": {} },
-    "limit": 2
-  },
-  "results": [
-    { "@id": "http://example.com/alice" },
-    { "@id": "http://example.com/likes" }
-  ]
-}
diff --git a/query/linkedql/steps/test-cases/Optional.json b/query/linkedql/steps/test-cases/Optional.json
deleted file mode 100644
index 96937dc..0000000
--- a/query/linkedql/steps/test-cases/Optional.json
+++ /dev/null
@@ -1,37 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@graph": [
-      { "@id": "alice", "likes": { "@id": "bob" }, "name": "Alice" },
-      { "@id": "bob", "name": "Bob" }
-    ]
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Select",
-    "from": {
-      "@type": "Optional",
-      "from": {
-        "@type": "Properties",
-        "from": { "@type": "Match", "pattern": {} },
-        "names": ["http://example.com/name"]
-      },
-      "step": {
-        "@type": "Properties",
-        "from": { "@type": "Placeholder" },
-        "names": ["http://example.com/likes"]
-      }
-    },
-    "tags": []
-  },
-  "results": [
-    {
-      "http://example.com/likes": { "@id": "http://example.com/bob" },
-      "http://example.com/name": "Alice"
-    },
-    { "http://example.com/name": "Bob" }
-  ]
-}
diff --git a/query/linkedql/steps/test-cases/Order.json b/query/linkedql/steps/test-cases/Order.json
deleted file mode 100644
index 7f9af17..0000000
--- a/query/linkedql/steps/test-cases/Order.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@id": "alice",
-    "likes": { "@id": "bob" }
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Order",
-    "from": { "@type": "Match", "pattern": {} }
-  },
-  "results": [
-    { "@id": "http://example.com/alice" },
-    { "@id": "http://example.com/bob" },
-    { "@id": "http://example.com/likes" }
-  ]
-}
diff --git a/query/linkedql/steps/test-cases/Properties.json b/query/linkedql/steps/test-cases/Properties.json
deleted file mode 100644
index 687d665..0000000
--- a/query/linkedql/steps/test-cases/Properties.json
+++ /dev/null
@@ -1,23 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@id": "alice",
-    "likes": { "@id": "bob" }
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Select",
-    "from": {
-      "@type": "Properties",
-      "from": { "@type": "Match", "pattern": {} },
-      "names": ["http://example.com/likes"]
-    },
-    "tags": []
-  },
-  "results": [
-    { "http://example.com/likes": { "@id": "http://example.com/bob" } }
-  ]
-}
diff --git a/query/linkedql/steps/test-cases/Select.json b/query/linkedql/steps/test-cases/Select.json
deleted file mode 100644
index f14b303..0000000
--- a/query/linkedql/steps/test-cases/Select.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@id": "alice",
-    "likes": { "@id": "bob" }
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Select",
-    "from": {
-      "@type": "Visit",
-      "from": {
-        "@type": "As",
-        "from": { "@type": "Match", "pattern": {} },
-        "name": "http://example.com/liker"
-      },
-      "properties": "http://example.com/likes"
-    },
-    "tags": []
-  },
-  "results": [
-    { "http://example.com/liker": { "@id": "http://example.com/alice" } }
-  ]
-}
diff --git a/query/linkedql/steps/test-cases/Skip.json b/query/linkedql/steps/test-cases/Skip.json
deleted file mode 100644
index 076bd60..0000000
--- a/query/linkedql/steps/test-cases/Skip.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@id": "alice",
-    "likes": { "@id": "bob" }
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Skip",
-    "from": { "@type": "Match", "pattern": {} },
-    "offset": 2
-  },
-  "results": [{ "@id": "http://example.com/bob" }]
-}
diff --git a/query/linkedql/steps/test-cases/Union.json b/query/linkedql/steps/test-cases/Union.json
deleted file mode 100644
index 12941ce..0000000
--- a/query/linkedql/steps/test-cases/Union.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@id": "alice",
-    "likes": { "@id": "bob" }
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Union",
-    "from": {
-      "@type": "Match",
-      "pattern": { "@id": "http://example.com/alice" }
-    },
-    "steps": [
-      { "@type": "Match", "pattern": { "@id": "http://example.com/bob" } }
-    ]
-  },
-  "results": [
-    { "@id": "http://example.com/alice" },
-    { "@id": "http://example.com/bob" }
-  ]
-}
diff --git a/query/linkedql/steps/test-cases/Unique.json b/query/linkedql/steps/test-cases/Unique.json
deleted file mode 100644
index 6c5cfa8..0000000
--- a/query/linkedql/steps/test-cases/Unique.json
+++ /dev/null
@@ -1,26 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@id": "alice",
-    "likes": { "@id": "bob" }
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Unique",
-    "from": {
-      "@type": "Vertex",
-      "values": [
-        { "@id": "http://example.com/alice" },
-        { "@id": "http://example.com/alice" },
-        { "@id": "http://example.com/bob" }
-      ]
-    }
-  },
-  "results": [
-    { "@id": "http://example.com/alice" },
-    { "@id": "http://example.com/bob" }
-  ]
-}
diff --git a/query/linkedql/steps/test-cases/View.json b/query/linkedql/steps/test-cases/View.json
deleted file mode 100644
index d6cc830..0000000
--- a/query/linkedql/steps/test-cases/View.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@id": "alice",
-    "likes": { "@id": "bob" }
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Visit",
-    "from": { "@type": "Match", "pattern": {} },
-    "properties": "http://example.com/likes"
-  },
-  "results": [{ "@id": "http://example.com/bob" }]
-}
diff --git a/query/linkedql/steps/test-cases/Where.json b/query/linkedql/steps/test-cases/Where.json
deleted file mode 100644
index 8ab87d2..0000000
--- a/query/linkedql/steps/test-cases/Where.json
+++ /dev/null
@@ -1,32 +0,0 @@
-{
-  "data": {
-    "@context": {
-      "@base": "http://example.com/",
-      "@vocab": "http://example.com/"
-    },
-    "@graph": [
-      { "@id": "alice", "likes": { "@id": "bob" }, "name": "Alice" },
-      { "@id": "bob", "name": "Bob" }
-    ]
-  },
-  "query": {
-    "@context": { "@vocab": "http://cayley.io/linkedql#" },
-    "@type": "Select",
-    "from": {
-      "@type": "Properties",
-      "from": {
-        "@type": "Where",
-        "condition": {
-          "@type": "Has",
-          "from": { "@type": "Placeholder" },
-          "property": "http://example.com/likes",
-          "values": [{ "@id": "http://example.com/bob" }]
-        },
-        "from": { "@type": "Match", "pattern": {} }
-      },
-      "names": ["http://example.com/name"]
-    },
-    "tags": []
-  },
-  "results": [{ "http://example.com/name": "Alice" }]
-}
diff --git a/query/path/pathtest/pathtest.go b/query/path/pathtest/pathtest.go
index 5aab763..a3eb0a1 100644
--- a/query/path/pathtest/pathtest.go
+++ b/query/path/pathtest/pathtest.go
@@ -77,12 +77,17 @@ func runTag(qs graph.QuadStore, path *path.Path, tag string, opt, keepEmpty bool
 	if !opt {
 		pb = pb.UnOptimized()
 	}
-	err := pb.Paths(true).TagEach(func(tags map[string]graph.Ref) {
+	err := pb.Paths(true).TagEach(func(tags map[string]graph.Ref) error {
 		if t, ok := tags[tag]; ok {
-			out = append(out, qs.NameOf(t))
+			tv, err := qs.NameOf(t)
+			if err != nil {
+				return err
+			}
+			out = append(out, tv)
 		} else if keepEmpty {
 			out = append(out, vEmpty)
 		}
+		return nil
 	})
 	return out, err
 }
@@ -93,8 +98,9 @@ func runAllTags(qs graph.QuadStore, path *path.Path, opt bool) ([]map[string]qua
 	if !opt {
 		pb = pb.UnOptimized()
 	}
-	err := pb.Paths(true).TagValues(qs, func(tags map[string]quad.Value) {
+	err := pb.Paths(true).TagValues(qs, func(tags map[string]quad.Value) error {
 		out = append(out, tags)
+		return nil
 	})
 	return out, err
 }
diff --git a/query/sexp/parser_test.go b/query/sexp/parser_test.go
index 757a093..7585fb8 100644
--- a/query/sexp/parser_test.go
+++ b/query/sexp/parser_test.go
@@ -174,12 +174,15 @@ func TestSexp(t *testing.T) {
 				t.Errorf("Failed to %s", test.message)
 			}
 			if test.expect != "" {
-				require.Equal(t, qs.ValueOf(quad.StringToValue(test.expect)), it.Result())
+				qv, err := qs.ValueOf(quad.StringToValue(test.expect))
+				require.NoError(t, err)
+				require.Equal(t, qv, it.Result())
 
 				tags := make(map[string]graph.Ref)
 				it.TagResults(tags)
 				for k, v := range test.tags {
-					name := qs.NameOf(tags[k])
+					name, err := qs.NameOf(tags[k])
+					require.NoError(t, err)
 					require.Equal(t, v, quad.ToString(name))
 				}
 				if it.Next(ctx) {
diff --git a/query/shape/shape_test.go b/query/shape/shape_test.go
index 8bb36c9..0511209 100644
--- a/query/shape/shape_test.go
+++ b/query/shape/shape_test.go
@@ -42,8 +42,8 @@ type ValLookup map[quad.Value]refs.Ref
 func (qs ValLookup) OptimizeShape(ctx context.Context, s Shape) (Shape, bool) {
 	return s, false // emulate dumb quad store
 }
-func (qs ValLookup) ValueOf(v quad.Value) refs.Ref {
-	return qs[v]
+func (qs ValLookup) ValueOf(v quad.Value) (refs.Ref, error) {
+	return qs[v], nil
 }
 
 func (ValLookup) NewQuadWriter() (quad.WriteCloser, error) {
@@ -52,7 +52,7 @@ func (ValLookup) NewQuadWriter() (quad.WriteCloser, error) {
 func (ValLookup) ApplyDeltas(_ []graph.Delta, _ graph.IgnoreOpts) error {
 	panic("not implemented")
 }
-func (ValLookup) Quad(_ refs.Ref) quad.Quad {
+func (ValLookup) Quad(_ refs.Ref) (quad.Quad, error) {
 	panic("not implemented")
 }
 func (ValLookup) QuadIterator(_ quad.Direction, _ refs.Ref) iterator.Shape {
@@ -67,7 +67,7 @@ func (ValLookup) NodesAllIterator() iterator.Shape {
 func (ValLookup) QuadsAllIterator() iterator.Shape {
 	panic("not implemented")
 }
-func (ValLookup) NameOf(_ refs.Ref) quad.Value {
+func (ValLookup) NameOf(_ refs.Ref) (quad.Value, error) {
 	panic("not implemented")
 }
 func (ValLookup) Stats(ctx context.Context, exact bool) (graph.Stats, error) {
@@ -76,7 +76,7 @@ func (ValLookup) Stats(ctx context.Context, exact bool) (graph.Stats, error) {
 func (ValLookup) Close() error {
 	panic("not implemented")
 }
-func (ValLookup) QuadDirection(_ refs.Ref, _ quad.Direction) refs.Ref {
+func (ValLookup) QuadDirection(_ refs.Ref, _ quad.Direction) (refs.Ref, error) {
 	panic("not implemented")
 }
 func (ValLookup) Type() string {
diff --git a/schema/loader_test.go b/schema/loader_test.go
index db6d322..92a5999 100644
--- a/schema/loader_test.go
+++ b/schema/loader_test.go
@@ -8,6 +8,7 @@ import (
 	"github.com/cayleygraph/cayley/graph/memstore"
 	"github.com/cayleygraph/cayley/schema"
 	"github.com/cayleygraph/quad"
+	"github.com/stretchr/testify/require"
 )
 
 func TestLoadLoop(t *testing.T) {
@@ -86,7 +87,9 @@ func TestLoadIteratorTo(t *testing.T) {
 			if c.from != nil {
 				fixed := iterator.NewFixed()
 				for _, id := range c.from {
-					fixed.Add(qs.ValueOf(id))
+					qsv, err := qs.ValueOf(id)
+					require.NoError(t, err)
+					fixed.Add(qsv)
 				}
 				it = fixed
 			}