github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/cmn/archive/err.go (about)

     1  // Package archive: write, read, copy, append, list primitives
     2  // across all supported formats
     3  /*
     4   * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
     5   */
     6  package archive
     7  
     8  import (
     9  	"errors"
    10  	"fmt"
    11  
    12  	"github.com/NVIDIA/aistore/cmn/cos"
    13  )
    14  
    15  const TarBlockSize = 512 // Size of each block in a tar stream
    16  
    17  // assorted errors
    18  type (
    19  	ErrUnknownMime struct{ detail string }
    20  
    21  	ErrUnknownFileExt struct {
    22  		filename string
    23  		detail   string
    24  	}
    25  )
    26  
    27  var ErrTarIsEmpty = errors.New("tar is empty")
    28  
    29  func NewErrUnknownMime(d string) *ErrUnknownMime { return &ErrUnknownMime{d} }
    30  func (e *ErrUnknownMime) Error() string          { return "unknown mime type \"" + e.detail + "\"" }
    31  
    32  func IsErrUnknownMime(err error) bool {
    33  	_, ok := err.(*ErrUnknownMime)
    34  	return ok
    35  }
    36  
    37  func NewErrUnknownFileExt(filename, detail string) (e *ErrUnknownFileExt) {
    38  	e = &ErrUnknownFileExt{filename: filename, detail: detail}
    39  	return
    40  }
    41  
    42  func (e *ErrUnknownFileExt) Error() (s string) {
    43  	s = fmt.Sprintf("unknown filename extension (%q, %q)", e.filename, cos.Ext(e.filename))
    44  	if e.detail != "" {
    45  		s += " - " + e.detail
    46  	}
    47  	return
    48  }
    49  
    50  func IsErrUnknownFileExt(err error) bool {
    51  	_, ok := err.(*ErrUnknownFileExt)
    52  	return ok
    53  }