icns

Easily create .icns files (Mac Icons) with this Go library or the included CLI.
Log | Files | Refs | LICENSE

error.go (1124B)


      1 package icns
      2 
      3 import (
      4 	"errors"
      5 	"fmt"
      6 	"image"
      7 )
      8 
      9 // Errors returned by the decoder. They are wrapped with detail, so compare
     10 // with errors.Is.
     11 var (
     12 	// ErrInvalidHeader means the data does not begin with an icns header.
     13 	ErrInvalidHeader = errors.New("invalid header for icns file")
     14 	// ErrMalformed means an element's declared length disagrees with the
     15 	// data present; the file is truncated or corrupt.
     16 	ErrMalformed = errors.New("malformed icns file")
     17 	// ErrNoIcons means the file is well formed but contains no icons of a
     18 	// type this package understands.
     19 	ErrNoIcons = errors.New("no icons found")
     20 	// ErrUnsupportedFormat means every icon present uses an image format
     21 	// this package cannot decode (JPEG 2000).
     22 	ErrUnsupportedFormat = errors.New("unsupported image format")
     23 )
     24 
     25 // ErrImageTooSmall is returned when the image is too small to process.
     26 type ErrImageTooSmall struct {
     27 	need  int
     28 	image image.Image
     29 }
     30 
     31 func (err ErrImageTooSmall) Error() string {
     32 	b := err.image.Bounds()
     33 	format := "image is too small: %dx%d, need at least %dx%d"
     34 	return fmt.Sprintf(format, b.Dx(), b.Dy(), err.need, err.need)
     35 }