Skip to content

Commit

Permalink
Merge pull request #63 from ipld/struct-tuple-repr-codegen
Browse files Browse the repository at this point in the history
Struct tuple representation codegen
  • Loading branch information
warpfork authored Jul 30, 2020
2 parents 2b1aabc + bfd1bba commit d70a19d
Show file tree
Hide file tree
Showing 11 changed files with 611 additions and 15 deletions.
4 changes: 2 additions & 2 deletions node/gendemo/tMsg3.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions schema/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package schema

import (
"fmt"

"github.com/ipld/go-ipld-prime"
)

// TODO: errors in this package remain somewhat slapdash.
Expand All @@ -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.

// ErrNoSuchField may be returned from lookup functions on the Node
// interface when a field is requested which doesn't exist, or from Insert
// on a MapBuilder when a key doesn't match a field name in the structure.
// interface when a field is requested which doesn't exist,
// 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 Type

FieldName string
Field ipld.PathSegment
}

func (e ErrNoSuchField) Error() string {
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.
Expand Down
8 changes: 4 additions & 4 deletions schema/gen/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ Legend:
| ... ... including optional |||
| ... ... including renames |||
| ... ... including implicits |||
| ... tuple representation | | |
| ... ... including optional | | |
| ... ... including renames | | |
| ... ... including implicits | | |
| ... tuple representation | | |
| ... ... including optional | | |
| ... ... including renames | - | - |
| ... ... including implicits | | |
| ... stringjoin representation |||
| ... ... including optional | - | - |
| ... ... including renames | - | - |
Expand Down
2 changes: 1 addition & 1 deletion schema/gen/go/genStruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (g structGenerator) EmitNodeMethodLookupByString(w io.Writer) {
{{- end}}
{{- end}}
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)
Expand Down
2 changes: 1 addition & 1 deletion schema/gen/go/genStructReprMap.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (g structReprMapReprGenerator) EmitNodeMethodLookupByString(w io.Writer) {
{{- end}}
{{- end}}
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)
Expand Down
Loading

0 comments on commit d70a19d

Please sign in to comment.