Commit fe4aa0a8 authored by Eric Myhre's avatar Eric Myhre

Add TypeName field to ErrWrongKind.

In general, picking a consistent strategy with this error and sticking
with it.  The strings were starting to accumulate too much ~stuff~,
otherwise.

It might not be a bad idea to upgrade the MethodName strings to a bunch
of consts, but I don't think it will get any harder to do that in the
future if we should so choose either, so, meh.
Signed-off-by: default avatarEric Myhre <hash@exultant.us>
parent c38adf62
......@@ -11,14 +11,14 @@ import (
// For example, calling AsString on a map will return ErrWrongKind.
// Calling Lookup on an int will similarly return ErrWrongKind.
type ErrWrongKind struct {
// CONSIDER: if we should add a `TypeName string` here as well?
// It seems to be useful information, and in many places we've shoved it
// along with the MethodName; but while that's fine for the printed message,
// we could do better internally (and it would enable `typed.wrapnode*` to
// touch this field on its way out in a nice reusable way).
// TypeName may optionally indicate the named type of a node the function
// was called on (if the node was typed!), or, may be the empty string.
TypeName string
// MethodName is literally the string for the operation attempted, e.g.
// "AsString".
//
// For methods on nodebuilders, we say e.g. "NodeBuilder.CreateMap".
MethodName string
// ApprorpriateKind describes which ReprKinds the erroring method would
......@@ -33,7 +33,11 @@ type ErrWrongKind struct {
}
func (e ErrWrongKind) Error() string {
return fmt.Sprintf("func called on wrong kind: %s called on a %s node, but only makes sense on %s", e.MethodName, e.ActualKind, e.AppropriateKind)
if e.TypeName == "" {
return fmt.Sprintf("func called on wrong kind: %s called on a %s node, but only makes sense on %s", e.MethodName, e.ActualKind, e.AppropriateKind)
} else {
return fmt.Sprintf("func called on wrong kind: %s called on a %s node (kind: %s), but only makes sense on %s", e.MethodName, e.TypeName, e.ActualKind, e.AppropriateKind)
}
}
// ErrNotExists may be returned from the lookup functions of the Node interface
......
......@@ -69,35 +69,35 @@ func (justString) NodeBuilder() ipld.NodeBuilder {
type justStringNodeBuilder struct{}
func (nb justStringNodeBuilder) CreateMap() (ipld.MapBuilder, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{MethodName: "NodeBuilder.CreateMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: ipld.ReprKind_String}
}
func (nb justStringNodeBuilder) AmendMap() (ipld.MapBuilder, error) {
return nil, ipld.ErrWrongKind{MethodName: "AmendMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{MethodName: "NodeBuilder.AmendMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: ipld.ReprKind_String}
}
func (nb justStringNodeBuilder) CreateList() (ipld.ListBuilder, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{MethodName: "NodeBuilder.CreateList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_String}
}
func (nb justStringNodeBuilder) AmendList() (ipld.ListBuilder, error) {
return nil, ipld.ErrWrongKind{MethodName: "AmendList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{MethodName: "NodeBuilder.AmendList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_String}
}
func (nb justStringNodeBuilder) CreateNull() (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateNull", AppropriateKind: ipld.ReprKindSet_JustNull, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{MethodName: "NodeBuilder.CreateNull", AppropriateKind: ipld.ReprKindSet_JustNull, ActualKind: ipld.ReprKind_String}
}
func (nb justStringNodeBuilder) CreateBool(v bool) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateBool", AppropriateKind: ipld.ReprKindSet_JustBool, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{MethodName: "NodeBuilder.CreateBool", AppropriateKind: ipld.ReprKindSet_JustBool, ActualKind: ipld.ReprKind_String}
}
func (nb justStringNodeBuilder) CreateInt(v int) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateInt", AppropriateKind: ipld.ReprKindSet_JustInt, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{MethodName: "NodeBuilder.CreateInt", AppropriateKind: ipld.ReprKindSet_JustInt, ActualKind: ipld.ReprKind_String}
}
func (nb justStringNodeBuilder) CreateFloat(v float64) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateFloat", AppropriateKind: ipld.ReprKindSet_JustFloat, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{MethodName: "NodeBuilder.CreateFloat", AppropriateKind: ipld.ReprKindSet_JustFloat, ActualKind: ipld.ReprKind_String}
}
func (nb justStringNodeBuilder) CreateString(v string) (ipld.Node, error) {
return justString(v), nil
}
func (nb justStringNodeBuilder) CreateBytes(v []byte) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateBytes", AppropriateKind: ipld.ReprKindSet_JustBytes, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{MethodName: "NodeBuilder.CreateBytes", AppropriateKind: ipld.ReprKindSet_JustBytes, ActualKind: ipld.ReprKind_String}
}
func (nb justStringNodeBuilder) CreateLink(v ipld.Link) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateLink", AppropriateKind: ipld.ReprKindSet_JustLink, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{MethodName: "NodeBuilder.CreateLink", AppropriateKind: ipld.ReprKindSet_JustLink, ActualKind: ipld.ReprKind_String}
}
......@@ -125,31 +125,31 @@ func (nb wrapnodeStruct_Builder) AmendMap() (ipld.MapBuilder, error) {
panic("TODO") // TODO
}
func (nb wrapnodeStruct_Builder) CreateList() (ipld.ListBuilder, error) {
return nil, ipld.ErrWrongKind{MethodName: string(nb.typ.Name()) + ".CreateList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_Map}
return nil, ipld.ErrWrongKind{TypeName: string(nb.typ.Name()), MethodName: "NodeBuilder.CreateList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_Map}
}
func (nb wrapnodeStruct_Builder) AmendList() (ipld.ListBuilder, error) {
return nil, ipld.ErrWrongKind{MethodName: string(nb.typ.Name()) + ".AmendList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_Map}
return nil, ipld.ErrWrongKind{TypeName: string(nb.typ.Name()), MethodName: "NodeBuilder.AmendList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_Map}
}
func (nb wrapnodeStruct_Builder) CreateNull() (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: string(nb.typ.Name()) + ".CreateNull", AppropriateKind: ipld.ReprKindSet_JustNull, ActualKind: ipld.ReprKind_Map}
return nil, ipld.ErrWrongKind{TypeName: string(nb.typ.Name()), MethodName: "NodeBuilder.CreateNull", AppropriateKind: ipld.ReprKindSet_JustNull, ActualKind: ipld.ReprKind_Map}
}
func (nb wrapnodeStruct_Builder) CreateBool(v bool) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: string(nb.typ.Name()) + ".CreateBool", AppropriateKind: ipld.ReprKindSet_JustBool, ActualKind: ipld.ReprKind_Map}
return nil, ipld.ErrWrongKind{TypeName: string(nb.typ.Name()), MethodName: "NodeBuilder.CreateBool", AppropriateKind: ipld.ReprKindSet_JustBool, ActualKind: ipld.ReprKind_Map}
}
func (nb wrapnodeStruct_Builder) CreateInt(v int) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: string(nb.typ.Name()) + ".CreateInt", AppropriateKind: ipld.ReprKindSet_JustInt, ActualKind: ipld.ReprKind_Map}
return nil, ipld.ErrWrongKind{TypeName: string(nb.typ.Name()), MethodName: "NodeBuilder.CreateInt", AppropriateKind: ipld.ReprKindSet_JustInt, ActualKind: ipld.ReprKind_Map}
}
func (nb wrapnodeStruct_Builder) CreateFloat(v float64) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: string(nb.typ.Name()) + ".CreateFloat", AppropriateKind: ipld.ReprKindSet_JustFloat, ActualKind: ipld.ReprKind_Map}
return nil, ipld.ErrWrongKind{TypeName: string(nb.typ.Name()), MethodName: "NodeBuilder.CreateFloat", AppropriateKind: ipld.ReprKindSet_JustFloat, ActualKind: ipld.ReprKind_Map}
}
func (nb wrapnodeStruct_Builder) CreateString(v string) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: string(nb.typ.Name()) + ".CreateString", AppropriateKind: ipld.ReprKindSet_JustString, ActualKind: ipld.ReprKind_Map}
return nil, ipld.ErrWrongKind{TypeName: string(nb.typ.Name()), MethodName: "NodeBuilder.CreateString", AppropriateKind: ipld.ReprKindSet_JustString, ActualKind: ipld.ReprKind_Map}
}
func (nb wrapnodeStruct_Builder) CreateBytes(v []byte) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: string(nb.typ.Name()) + ".CreateBytes", AppropriateKind: ipld.ReprKindSet_JustBytes, ActualKind: ipld.ReprKind_Map}
return nil, ipld.ErrWrongKind{TypeName: string(nb.typ.Name()), MethodName: "NodeBuilder.CreateBytes", AppropriateKind: ipld.ReprKindSet_JustBytes, ActualKind: ipld.ReprKind_Map}
}
func (nb wrapnodeStruct_Builder) CreateLink(v ipld.Link) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: string(nb.typ.Name()) + ".CreateLink", AppropriateKind: ipld.ReprKindSet_JustLink, ActualKind: ipld.ReprKind_Map}
return nil, ipld.ErrWrongKind{TypeName: string(nb.typ.Name()), MethodName: "NodeBuilder.CreateLink", AppropriateKind: ipld.ReprKindSet_JustLink, ActualKind: ipld.ReprKind_Map}
}
type wrapnodeStruct_MapBuilder struct {
......
......@@ -11,7 +11,7 @@ type generateKindedRejections struct{}
func (generateKindedRejections) emitNodeMethodLookupString(w io.Writer, t schema.Type) {
doTemplate(`
func ({{ .Name }}) LookupString(string) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "{{ .Name }}.LookupString", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "LookupString", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
}
`, w, t)
}
......@@ -19,7 +19,7 @@ func (generateKindedRejections) emitNodeMethodLookupString(w io.Writer, t schema
func (generateKindedRejections) emitNodeMethodLookup(w io.Writer, t schema.Type) {
doTemplate(`
func ({{ .Name }}) Lookup(ipld.Node) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "{{ .Name }}.Lookup", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "Lookup", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
}
`, w, t)
}
......@@ -27,7 +27,7 @@ func (generateKindedRejections) emitNodeMethodLookup(w io.Writer, t schema.Type)
func (generateKindedRejections) emitNodeMethodLookupIndex(w io.Writer, t schema.Type) {
doTemplate(`
func ({{ .Name }}) LookupIndex(idx int) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "{{ .Name }}.LookupIndex", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "LookupIndex", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
}
`, w, t)
}
......@@ -35,7 +35,7 @@ func (generateKindedRejections) emitNodeMethodLookupIndex(w io.Writer, t schema.
func (generateKindedRejections) emitNodeMethodMapIterator(w io.Writer, t schema.Type) {
doTemplate(`
func ({{ .Name }}) MapIterator() ipld.MapIterator {
return mapIteratorReject{ipld.ErrWrongKind{MethodName: "{{ .Name }}.MapIterator", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}}
return mapIteratorReject{ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "MapIterator", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}}
}
`, w, t)
}
......@@ -43,7 +43,7 @@ func (generateKindedRejections) emitNodeMethodMapIterator(w io.Writer, t schema.
func (generateKindedRejections) emitNodeMethodListIterator(w io.Writer, t schema.Type) {
doTemplate(`
func ({{ .Name }}) ListIterator() ipld.ListIterator {
return listIteratorReject{ipld.ErrWrongKind{MethodName: "{{ .Name }}.ListIterator", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}}
return listIteratorReject{ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "ListIterator", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}}
}
`, w, t)
}
......@@ -75,7 +75,7 @@ func (generateKindedRejections) emitNodeMethodIsNull(w io.Writer, t schema.Type)
func (generateKindedRejections) emitNodeMethodAsBool(w io.Writer, t schema.Type) {
doTemplate(`
func ({{ .Name }}) AsBool() (bool, error) {
return false, ipld.ErrWrongKind{MethodName: "{{ .Name }}.AsBool", AppropriateKind: ipld.ReprKindSet_JustBool, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
return false, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AsBool", AppropriateKind: ipld.ReprKindSet_JustBool, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
}
`, w, t)
}
......@@ -83,7 +83,7 @@ func (generateKindedRejections) emitNodeMethodAsBool(w io.Writer, t schema.Type)
func (generateKindedRejections) emitNodeMethodAsInt(w io.Writer, t schema.Type) {
doTemplate(`
func ({{ .Name }}) AsInt() (int, error) {
return 0, ipld.ErrWrongKind{MethodName: "{{ .Name }}.AsInt", AppropriateKind: ipld.ReprKindSet_JustInt, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
return 0, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AsInt", AppropriateKind: ipld.ReprKindSet_JustInt, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
}
`, w, t)
}
......@@ -91,7 +91,7 @@ func (generateKindedRejections) emitNodeMethodAsInt(w io.Writer, t schema.Type)
func (generateKindedRejections) emitNodeMethodAsFloat(w io.Writer, t schema.Type) {
doTemplate(`
func ({{ .Name }}) AsFloat() (float64, error) {
return 0, ipld.ErrWrongKind{MethodName: "{{ .Name }}.AsFloat", AppropriateKind: ipld.ReprKindSet_JustFloat, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
return 0, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AsFloat", AppropriateKind: ipld.ReprKindSet_JustFloat, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
}
`, w, t)
}
......@@ -99,7 +99,7 @@ func (generateKindedRejections) emitNodeMethodAsFloat(w io.Writer, t schema.Type
func (generateKindedRejections) emitNodeMethodAsString(w io.Writer, t schema.Type) {
doTemplate(`
func ({{ .Name }}) AsString() (string, error) {
return "", ipld.ErrWrongKind{MethodName: "{{ .Name }}.AsString", AppropriateKind: ipld.ReprKindSet_JustString, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
return "", ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AsString", AppropriateKind: ipld.ReprKindSet_JustString, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
}
`, w, t)
}
......@@ -107,7 +107,7 @@ func (generateKindedRejections) emitNodeMethodAsString(w io.Writer, t schema.Typ
func (generateKindedRejections) emitNodeMethodAsBytes(w io.Writer, t schema.Type) {
doTemplate(`
func ({{ .Name }}) AsBytes() ([]byte, error) {
return nil, ipld.ErrWrongKind{MethodName: "{{ .Name }}.AsBytes", AppropriateKind: ipld.ReprKindSet_JustBytes, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AsBytes", AppropriateKind: ipld.ReprKindSet_JustBytes, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
}
`, w, t)
}
......@@ -115,7 +115,7 @@ func (generateKindedRejections) emitNodeMethodAsBytes(w io.Writer, t schema.Type
func (generateKindedRejections) emitNodeMethodAsLink(w io.Writer, t schema.Type) {
doTemplate(`
func ({{ .Name }}) AsLink() (ipld.Link, error) {
return nil, ipld.ErrWrongKind{MethodName: "{{ .Name }}.AsLink", AppropriateKind: ipld.ReprKindSet_JustLink, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Name }}", MethodName: "AsLink", AppropriateKind: ipld.ReprKindSet_JustLink, ActualKind: {{ .Kind.ActsLike | ReprKindConst }}}
}
`, w, t)
}
......
......@@ -32,37 +32,37 @@ func (gk generateKindString) EmitNodeMethodNodeBuilder(w io.Writer) {
type {{ .Type.Name }}__NodeBuilder struct{}
func (nb {{ .Type.Name }}__NodeBuilder) CreateMap() (ipld.MapBuilder, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Type.Name }}", MethodName: "NodeBuilder.CreateMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: ipld.ReprKind_String}
}
func (nb {{ .Type.Name }}__NodeBuilder) AmendMap() (ipld.MapBuilder, error) {
return nil, ipld.ErrWrongKind{MethodName: "AmendMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Type.Name }}", MethodName: "NodeBuilder.AmendMap", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: ipld.ReprKind_String}
}
func (nb {{ .Type.Name }}__NodeBuilder) CreateList() (ipld.ListBuilder, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Type.Name }}", MethodName: "NodeBuilder.CreateList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_String}
}
func (nb {{ .Type.Name }}__NodeBuilder) AmendList() (ipld.ListBuilder, error) {
return nil, ipld.ErrWrongKind{MethodName: "AmendList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Type.Name }}", MethodName: "NodeBuilder.AmendList", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: ipld.ReprKind_String}
}
func (nb {{ .Type.Name }}__NodeBuilder) CreateNull() (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateNull", AppropriateKind: ipld.ReprKindSet_JustNull, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Type.Name }}", MethodName: "NodeBuilder.CreateNull", AppropriateKind: ipld.ReprKindSet_JustNull, ActualKind: ipld.ReprKind_String}
}
func (nb {{ .Type.Name }}__NodeBuilder) CreateBool(v bool) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateBool", AppropriateKind: ipld.ReprKindSet_JustBool, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Type.Name }}", MethodName: "NodeBuilder.CreateBool", AppropriateKind: ipld.ReprKindSet_JustBool, ActualKind: ipld.ReprKind_String}
}
func (nb {{ .Type.Name }}__NodeBuilder) CreateInt(v int) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateInt", AppropriateKind: ipld.ReprKindSet_JustInt, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Type.Name }}", MethodName: "NodeBuilder.CreateInt", AppropriateKind: ipld.ReprKindSet_JustInt, ActualKind: ipld.ReprKind_String}
}
func (nb {{ .Type.Name }}__NodeBuilder) CreateFloat(v float64) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateFloat", AppropriateKind: ipld.ReprKindSet_JustFloat, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Type.Name }}", MethodName: "NodeBuilder.CreateFloat", AppropriateKind: ipld.ReprKindSet_JustFloat, ActualKind: ipld.ReprKind_String}
}
func (nb {{ .Type.Name }}__NodeBuilder) CreateString(v string) (ipld.Node, error) {
return {{ .Type.Name }}{v}, nil
}
func (nb {{ .Type.Name }}__NodeBuilder) CreateBytes(v []byte) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateBytes", AppropriateKind: ipld.ReprKindSet_JustBytes, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Type.Name }}", MethodName: "NodeBuilder.CreateBytes", AppropriateKind: ipld.ReprKindSet_JustBytes, ActualKind: ipld.ReprKind_String}
}
func (nb {{ .Type.Name }}__NodeBuilder) CreateLink(v ipld.Link) (ipld.Node, error) {
return nil, ipld.ErrWrongKind{MethodName: "CreateLink", AppropriateKind: ipld.ReprKindSet_JustLink, ActualKind: ipld.ReprKind_String}
return nil, ipld.ErrWrongKind{TypeName: "{{ .Type.Name }}", MethodName: "NodeBuilder.CreateLink", AppropriateKind: ipld.ReprKindSet_JustLink, ActualKind: ipld.ReprKind_String}
}
`, w, gk)
}
......@@ -9,19 +9,19 @@ func (nullNode) ReprKind() ReprKind {
return ReprKind_Null
}
func (nullNode) LookupString(key string) (Node, error) {
return nil, ErrWrongKind{MethodName: "<null>.LookupString", AppropriateKind: ReprKindSet_JustMap, ActualKind: ReprKind_Null}
return nil, ErrWrongKind{MethodName: "LookupString", AppropriateKind: ReprKindSet_JustMap, ActualKind: ReprKind_Null}
}
func (nullNode) Lookup(key Node) (Node, error) {
return nil, ErrWrongKind{MethodName: "<null>.Lookup", AppropriateKind: ReprKindSet_JustMap, ActualKind: ReprKind_Null}
return nil, ErrWrongKind{MethodName: "Lookup", AppropriateKind: ReprKindSet_JustMap, ActualKind: ReprKind_Null}
}
func (nullNode) LookupIndex(idx int) (Node, error) {
return nil, ErrWrongKind{MethodName: "<null>.LookupIndex", AppropriateKind: ReprKindSet_JustList, ActualKind: ReprKind_Null}
return nil, ErrWrongKind{MethodName: "LookupIndex", AppropriateKind: ReprKindSet_JustList, ActualKind: ReprKind_Null}
}
func (nullNode) MapIterator() MapIterator {
return mapIteratorReject{ErrWrongKind{MethodName: "<null>.MapIterator", AppropriateKind: ReprKindSet_JustMap, ActualKind: ReprKind_Null}}
return mapIteratorReject{ErrWrongKind{MethodName: "MapIterator", AppropriateKind: ReprKindSet_JustMap, ActualKind: ReprKind_Null}}
}
func (nullNode) ListIterator() ListIterator {
return listIteratorReject{ErrWrongKind{MethodName: "<null>.ListIterator", AppropriateKind: ReprKindSet_JustList, ActualKind: ReprKind_Null}}
return listIteratorReject{ErrWrongKind{MethodName: "ListIterator", AppropriateKind: ReprKindSet_JustList, ActualKind: ReprKind_Null}}
}
func (nullNode) Length() int {
return -1
......@@ -33,22 +33,22 @@ func (nullNode) IsNull() bool {
return true
}
func (nullNode) AsBool() (bool, error) {
return false, ErrWrongKind{MethodName: "<null>.AsBool", AppropriateKind: ReprKindSet_JustBool, ActualKind: ReprKind_Null}
return false, ErrWrongKind{MethodName: "AsBool", AppropriateKind: ReprKindSet_JustBool, ActualKind: ReprKind_Null}
}
func (nullNode) AsInt() (int, error) {
return 0, ErrWrongKind{MethodName: "<null>.AsInt", AppropriateKind: ReprKindSet_JustInt, ActualKind: ReprKind_Null}
return 0, ErrWrongKind{MethodName: "AsInt", AppropriateKind: ReprKindSet_JustInt, ActualKind: ReprKind_Null}
}
func (nullNode) AsFloat() (float64, error) {
return 0, ErrWrongKind{MethodName: "<null>.AsFloat", AppropriateKind: ReprKindSet_JustFloat, ActualKind: ReprKind_Null}
return 0, ErrWrongKind{MethodName: "AsFloat", AppropriateKind: ReprKindSet_JustFloat, ActualKind: ReprKind_Null}
}
func (nullNode) AsString() (string, error) {
return "", ErrWrongKind{MethodName: "<null>.AsString", AppropriateKind: ReprKindSet_JustString, ActualKind: ReprKind_Null}
return "", ErrWrongKind{MethodName: "AsString", AppropriateKind: ReprKindSet_JustString, ActualKind: ReprKind_Null}
}
func (nullNode) AsBytes() ([]byte, error) {
return nil, ErrWrongKind{MethodName: "<null>.AsBytes", AppropriateKind: ReprKindSet_JustBytes, ActualKind: ReprKind_Null}
return nil, ErrWrongKind{MethodName: "AsBytes", AppropriateKind: ReprKindSet_JustBytes, ActualKind: ReprKind_Null}
}
func (nullNode) AsLink() (Link, error) {
return nil, ErrWrongKind{MethodName: "<null>.AsLink", AppropriateKind: ReprKindSet_JustLink, ActualKind: ReprKind_Null}
return nil, ErrWrongKind{MethodName: "AsLink", AppropriateKind: ReprKindSet_JustLink, ActualKind: ReprKind_Null}
}
func (nullNode) NodeBuilder() NodeBuilder {
panic("cannot build null nodes")
......
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