]> Cypherpunks repositories - keks.git/commitdiff
add new error types
authorAnton Rudenko <rudenko.ad@phystech.edu>
Thu, 30 Jan 2025 12:31:31 +0000 (15:31 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 10 Feb 2025 15:40:10 +0000 (18:40 +0300)
go/atom-decode.go

index 98e62ab822279b8342473b352b62c443ca44404f40406c62f90e3266ff92127f..0cbcc53828c829c7fc8e8fbc80a93eb774b694170e4948efb2e2cf01274d61eb 100644 (file)
@@ -35,6 +35,10 @@ var (
        ErrBadUTF8       = errors.New("invalid UTF-8")
        ErrBadInt        = errors.New("bad int value")
        ErrBadMagic      = errors.New("bad magic value")
+       ErrTaiReserved   = errors.New("reserved TAI64 values in use")
+       ErrTaiNonMinimal = errors.New("non-minimal TAI64")
+       ErrTooManyNsecs  = errors.New("too many nanoseconds")
+       ErrTooManyAsecs  = errors.New("too many attoseconds")
 )
 
 func (ctx *Decoder) DecodeAtom() (t types.Type, err error) {
@@ -208,28 +212,28 @@ func (ctx *Decoder) DecodeAtom() (t types.Type, err error) {
                        return
                }
                if be.Get([]byte(s)[:8]) > (1 << 63) {
-                       err = errors.New("reserved TAI64 values in use")
+                       err = ErrTaiReserved
                        return
                }
                if l > 8 {
                        nsecs := be.Get([]byte(s)[8 : 8+4])
                        if l == 12 && nsecs == 0 {
-                               err = errors.New("non-minimal TAI64N")
+                               err = ErrTaiNonMinimal
                                return
                        }
                        if nsecs > 999999999 {
-                               err = errors.New("too many nanoseconds")
+                               err = ErrTooManyNsecs
                                return
                        }
                }
                if l > 12 {
                        asecs := be.Get([]byte(s)[8+4 : 8+4+4])
                        if asecs == 0 {
-                               err = errors.New("non-minimal TAI64NA")
+                               err = ErrTaiNonMinimal
                                return
                        }
                        if asecs > 999999999 {
-                               err = errors.New("too many attoseconds")
+                               err = ErrTooManyAsecs
                                return
                        }
                }