error handling

master
Jordan Orelli 8 years ago
parent 51135ce070
commit 5beddd91a3

@ -75,7 +75,10 @@ func (d *Dict) createEntity(id int) error {
e := class.New(serial, false) e := class.New(serial, false)
d.entities[id] = e d.entities[id] = e
Debug.Printf("create entity id: %d serial: %d classId: %d className: %v class: %v\n", id, serial, classId, className, class) Debug.Printf("create entity id: %d serial: %d classId: %d className: %v class: %v\n", id, serial, classId, className, class)
return fillSlots(e, class.Name.String(), d.sr, d.br) if err := fillSlots(e, class.Name.String(), d.sr, d.br); err != nil {
return fmt.Errorf("failed to create entity %d (%s): %v", id, className, err)
}
return nil
} }
func (d *Dict) getEntity(id int) *Entity { func (d *Dict) getEntity(id int) *Entity {
@ -92,13 +95,23 @@ func (d *Dict) updateEntity(id int) error {
if e == nil { if e == nil {
return fmt.Errorf("update entity %d refused: no such entity", id) return fmt.Errorf("update entity %d refused: no such entity", id)
} }
return fillSlots(e, e.Class.String(), d.sr, d.br) if err := fillSlots(e, e.Class.String(), d.sr, d.br); err != nil {
return fmt.Errorf("failed to update entity %d (%s): %v", id, e.Class.Name.String(), err)
}
return nil
} }
func (d *Dict) deleteEntity(id int) error { func (d *Dict) deleteEntity(id int) error {
Debug.Printf("delete entity id: %d\n", id) Debug.Printf("delete entity id: %d\n", id)
if id < 0 || id >= e_limit { if id < 0 || id >= e_limit {
return fmt.Errorf("delete entity %d refused: no such entity", id) // we're probably reading corrupt shit if we get here
return fmt.Errorf("delete entity %d refused: id is out of bounds", id)
}
if d.entities[id] == nil {
// this one's probably ok to let fly, but it's probably a sign that
// something is wrong elsewhere.
Debug.Printf("delete entity %d refused: no such entity", id)
return nil
} }
d.entities[id] = nil d.entities[id] = nil
return nil return nil
@ -122,7 +135,7 @@ func (d *Dict) Handle(m proto.Message) {
case *dota.CSVCMsg_PacketEntities: case *dota.CSVCMsg_PacketEntities:
if err := d.mergeEntities(v); err != nil { if err := d.mergeEntities(v); err != nil {
Debug.Printf("merge entities error: %v", err) Info.Fatalf("merge entities error: %v", err)
} }
} }
} }
@ -154,7 +167,7 @@ func (d *Dict) mergeEntities(m *dota.CSVCMsg_PacketEntities) error {
} }
if err := fn(id); err != nil { if err := fn(id); err != nil {
return fmt.Errorf("entity merge error: %v", err) return fmt.Errorf("error on entity %d: %v", id, err)
} }
} }
return nil return nil
@ -165,15 +178,14 @@ func (d *Dict) updateBaselines(t *stbl.Table) {
d.syncBaselines() d.syncBaselines()
} }
func (d *Dict) syncBaselines() { func (d *Dict) syncBaselines() error {
if !d.hasClassinfo() { if !d.hasClassinfo() {
Debug.Printf("syncBaselines skip: no classInfo yet") Debug.Printf("syncBaselines skip: no classInfo yet")
return return nil
} }
Debug.Printf("syncBaselines start") Debug.Printf("syncBaselines start")
if d.base == nil { if d.base == nil {
Debug.Printf("syncBaselines failed: reference to baseline string table is nil") return fmt.Errorf("syncBaselines failed: reference to baseline string table is nil")
return
} }
for _, e := range d.base.Entries() { for _, e := range d.base.Entries() {
@ -201,8 +213,8 @@ func (d *Dict) syncBaselines() {
d.br.SetSource(e.Value) d.br.SetSource(e.Value)
Debug.Printf("syncBaselines has new baseline for class %v", c) Debug.Printf("syncBaselines has new baseline for class %v", c)
if err := fillSlots(c.baseline, c.Name.String(), d.sr, d.br); err != nil { if err := fillSlots(c.baseline, c.Name.String(), d.sr, d.br); err != nil {
Debug.Printf("syncBaselines failed to fill a baseline: %v", err) return fmt.Errorf("syncBaselines failed to fill a baseline: %v", err)
continue
} }
} }
return nil
} }

@ -20,7 +20,6 @@ func (s selection) String() string { return fmt.Sprint(s.path()) }
func (s selection) path() []int { return s.vals[:s.count] } func (s selection) path() []int { return s.vals[:s.count] }
func (s selection) fill(offset int, displayPath string, dest slotted, br bit.Reader) error { func (s selection) fill(offset int, displayPath string, dest slotted, br bit.Reader) error {
Debug.Printf("fill selection: %s offset: %d displayPath: %s dest: %v", s, offset, displayPath, dest)
slot := s.vals[offset] slot := s.vals[offset]
if s.count-offset <= 0 { if s.count-offset <= 0 {
panic("selection makes no sense") panic("selection makes no sense")
@ -48,8 +47,7 @@ func (s selection) fill(offset int, displayPath string, dest slotted, br bit.Rea
v := dest.slotValue(slot) v := dest.slotValue(slot)
vs, ok := v.(slotted) vs, ok := v.(slotted)
if !ok { if !ok {
Info.Printf("child selection %s at offset %d refers to a slot (%d: %s) that contains a non-slotted type: %s with value: %v", s, offset, slot, fmt.Sprintf("%s.%s", displayPath, dest.slotName(slot)), dest.slotType(slot), v) return fmt.Errorf("selection %s at offset %d (%d) refers to a slot (%s) that contains a non-slotted type (%s) with value %v", s, offset, slot, fmt.Sprintf("%s.%s", displayPath, dest.slotName(slot)), dest.slotType(slot), v)
return fmt.Errorf("child selection refers to a slot that doesn't contain a slotted value")
} }
return s.fill(offset+1, fmt.Sprintf("%s.%s", displayPath, dest.slotName(slot)), vs, br) return s.fill(offset+1, fmt.Sprintf("%s.%s", displayPath, dest.slotName(slot)), vs, br)
} }

@ -1,6 +1,7 @@
package ent package ent
import ( import (
"fmt"
"github.com/jordanorelli/hyperstone/bit" "github.com/jordanorelli/hyperstone/bit"
) )
@ -15,12 +16,12 @@ type slotted interface {
func fillSlots(dest slotted, displayPath string, sr *selectionReader, br bit.Reader) error { func fillSlots(dest slotted, displayPath string, sr *selectionReader, br bit.Reader) error {
selections, err := sr.readSelections(br, htree) selections, err := sr.readSelections(br, htree)
if err != nil { if err != nil {
return err return fmt.Errorf("error filling slots: %v", err)
} }
for _, s := range selections { for _, s := range selections {
if err := s.fill(0, displayPath, dest, br); err != nil { if err := s.fill(0, displayPath, dest, br); err != nil {
return err return fmt.Errorf("error filling slots: %v", err)
} }
} }
return nil return nil

Loading…
Cancel
Save