Commit 174e562d authored by Eric Myhre's avatar Eric Myhre

ErrNoSuchField now uses PathSegment instead of string.

This will become relevant when we have structs with tuple representation!
parent 2b1aabc2
...@@ -79,7 +79,7 @@ func (n Msg3) LookupByString(key string) (ipld.Node, error) { ...@@ -79,7 +79,7 @@ func (n Msg3) LookupByString(key string) (ipld.Node, error) {
case "waga": case "waga":
return &n.waga, nil return &n.waga, nil
default: default:
return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, FieldName: key} return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)}
} }
} }
func (n Msg3) LookupByNode(key ipld.Node) (ipld.Node, error) { func (n Msg3) LookupByNode(key ipld.Node) (ipld.Node, error) {
...@@ -560,7 +560,7 @@ func (n *_Msg3__Repr) LookupByString(key string) (ipld.Node, error) { ...@@ -560,7 +560,7 @@ func (n *_Msg3__Repr) LookupByString(key string) (ipld.Node, error) {
case "waga": case "waga":
return n.waga.Representation(), nil return n.waga.Representation(), nil
default: default:
return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, FieldName: key} return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)}
} }
} }
func (n *_Msg3__Repr) LookupByNode(key ipld.Node) (ipld.Node, error) { func (n *_Msg3__Repr) LookupByNode(key ipld.Node) (ipld.Node, error) {
......
...@@ -2,6 +2,8 @@ package schema ...@@ -2,6 +2,8 @@ package schema
import ( import (
"fmt" "fmt"
"github.com/ipld/go-ipld-prime"
) )
// TODO: errors in this package remain somewhat slapdash. // TODO: errors in this package remain somewhat slapdash.
...@@ -20,19 +22,22 @@ import ( ...@@ -20,19 +22,22 @@ import (
// - it's possible that we should wrap *all* schema-level errors in a single "ipld.ErrSchemaNoMatch" error of some kind, to fix the above. as yet undecided. // - it's possible that we should wrap *all* schema-level errors in a single "ipld.ErrSchemaNoMatch" error of some kind, to fix the above. as yet undecided.
// ErrNoSuchField may be returned from lookup functions on the Node // ErrNoSuchField may be returned from lookup functions on the Node
// interface when a field is requested which doesn't exist, or from Insert // interface when a field is requested which doesn't exist,
// on a MapBuilder when a key doesn't match a field name in the structure. // or from assigning data into on a MapAssembler for a struct
// when the key doesn't match a field name in the structure
// (or, when assigning data into a ListAssembler and the list size has
// reached out of bounds, in case of a struct with list-like representations!).
type ErrNoSuchField struct { type ErrNoSuchField struct {
Type Type Type Type
FieldName string Field ipld.PathSegment
} }
func (e ErrNoSuchField) Error() string { func (e ErrNoSuchField) Error() string {
if e.Type == nil { if e.Type == nil {
return fmt.Sprintf("no such field: {typeinfomissing}.%s", e.FieldName) return fmt.Sprintf("no such field: {typeinfomissing}.%s", e.Field)
} }
return fmt.Sprintf("no such field: %s.%s", e.Type.Name(), e.FieldName) return fmt.Sprintf("no such field: %s.%s", e.Type.Name(), e.Field)
} }
// ErrNotUnionStructure means data was fed into a union assembler that can't match the union. // ErrNotUnionStructure means data was fed into a union assembler that can't match the union.
......
...@@ -113,7 +113,7 @@ func (g structGenerator) EmitNodeMethodLookupByString(w io.Writer) { ...@@ -113,7 +113,7 @@ func (g structGenerator) EmitNodeMethodLookupByString(w io.Writer) {
{{- end}} {{- end}}
{{- end}} {{- end}}
default: default:
return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, FieldName: key} return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)}
} }
} }
`, w, g.AdjCfg, g) `, w, g.AdjCfg, g)
......
...@@ -102,7 +102,7 @@ func (g structReprMapReprGenerator) EmitNodeMethodLookupByString(w io.Writer) { ...@@ -102,7 +102,7 @@ func (g structReprMapReprGenerator) EmitNodeMethodLookupByString(w io.Writer) {
{{- end}} {{- end}}
{{- end}} {{- end}}
default: default:
return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, FieldName: key} return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)}
} }
} }
`, w, g.AdjCfg, g) `, w, g.AdjCfg, g)
......
...@@ -160,7 +160,7 @@ func (g unionGenerator) EmitNodeMethodLookupByString(w io.Writer) { ...@@ -160,7 +160,7 @@ func (g unionGenerator) EmitNodeMethodLookupByString(w io.Writer) {
{{- end}} {{- end}}
{{- end}} {{- end}}
default: default:
return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, FieldName: key} return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)}
} }
} }
`, w, g.AdjCfg, g) `, w, g.AdjCfg, g)
......
...@@ -98,7 +98,7 @@ func (g unionReprKeyedReprGenerator) EmitNodeMethodLookupByString(w io.Writer) { ...@@ -98,7 +98,7 @@ func (g unionReprKeyedReprGenerator) EmitNodeMethodLookupByString(w io.Writer) {
{{- end}} {{- end}}
{{- end}} {{- end}}
default: default:
return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, FieldName: key} return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)}
} }
} }
`, w, g.AdjCfg, g) `, w, g.AdjCfg, g)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment