1 package nbt 2 3 import ( 4 "errors" 5 "strconv" 6 ) 7 8 // ReadError is an error returned when a read error occurs 9 type ReadError struct { 10 Where string 11 Err error 12 } 13 14 func (r ReadError) Error() string { 15 return "encountered an error while trying to read a " + r.Where + ": " + r.Err.Error() 16 } 17 18 // WriteError is an error returned when a write error occurs 19 type WriteError struct { 20 Where string 21 Err error 22 } 23 24 func (w WriteError) Error() string { 25 return "encountered an error while trying to write a " + w.Where + ": " + w.Err.Error() 26 } 27 28 // UnknownTag is an error that occurs when an unknown tag id is discovered. 29 // This could also indicate corrupted or non-compliant data. 30 type UnknownTag struct { 31 TagID 32 } 33 34 func (u UnknownTag) Error() string { 35 return "discovered unknown TagId with id " + strconv.FormatUint(uint64(u.TagID), 10) 36 } 37 38 // WrongTag is an error returned when a tag of the incorrect type was intended 39 // to be added to a list. 40 type WrongTag struct { 41 Expecting, Got TagID 42 } 43 44 func (w WrongTag) Error() string { 45 return "expecting tag id " + w.Expecting.String() + ", got " + w.Got.String() 46 } 47 48 // ErrBadRange is an error that occurs when trying to set an item on a list which 49 // is outside of the current limits of the list. 50 var ErrBadRange = errors.New("given index was out-of-range") 51