mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-01 22:17:29 +08:00
Reducing the number of types of errors returned
This commit is contained in:
parent
9de46c5b9f
commit
347c2ee0e4
@ -188,8 +188,7 @@ func GetString(obj PdfObject) (string, error) {
|
||||
if s, ok := obj.(*PdfObjectString); ok {
|
||||
return string(*s), nil
|
||||
}
|
||||
err := errors.New("Not a string")
|
||||
return "", err
|
||||
return "", ErrTypeCheck
|
||||
}
|
||||
|
||||
// GetStringBytes returns the bytes represented by `obj` if `obj` is a PdfObjectString or an error if it isn't.
|
||||
@ -197,8 +196,7 @@ func GetStringBytes(obj PdfObject) ([]byte, error) {
|
||||
if s, ok := obj.(*PdfObjectString); ok {
|
||||
return []byte(*s), nil
|
||||
}
|
||||
err := errors.New("Not a string")
|
||||
return []byte{}, err
|
||||
return []byte{}, ErrTypeCheck
|
||||
}
|
||||
|
||||
// GetName returns the string represented by `obj` if `obj` is a PdfObjectName or an error if it isn't.
|
||||
@ -206,8 +204,7 @@ func GetName(obj PdfObject) (string, error) {
|
||||
if s, ok := obj.(*PdfObjectName); ok {
|
||||
return string(*s), nil
|
||||
}
|
||||
err := errors.New("Not a name")
|
||||
return "", err
|
||||
return "", ErrTypeCheck
|
||||
}
|
||||
|
||||
// GetInteger returns the int represented by `obj` if `obj` is a PdfObjectInteger or an error if it isn't.
|
||||
@ -215,8 +212,7 @@ func GetInteger(obj PdfObject) (int, error) {
|
||||
if i, ok := obj.(*PdfObjectInteger); ok {
|
||||
return int(*i), nil
|
||||
}
|
||||
err := errors.New("Not an integer")
|
||||
return 0, err
|
||||
return 0, ErrTypeCheck
|
||||
}
|
||||
|
||||
// GetArray returns the slice of PdfObjects represented by `obj` if `obj` is a PdfObjectArray or an
|
||||
@ -225,8 +221,7 @@ func GetArray(obj PdfObject) ([]PdfObject, error) {
|
||||
if s, ok := obj.(*PdfObjectArray); ok {
|
||||
return []PdfObject(*s), nil
|
||||
}
|
||||
err := errors.New("Not an array")
|
||||
return nil, err
|
||||
return nil, ErrTypeCheck
|
||||
}
|
||||
|
||||
// EqualObjects returns true if `obj1` and `obj2` have the same contents.
|
||||
|
Loading…
x
Reference in New Issue
Block a user