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

     1  // Package jsp (JSON persistence) provides utilities to store and load arbitrary
     2  // JSON-encoded structures with optional checksumming and compression.
     3  /*
     4   * Copyright (c) 2021-2024, NVIDIA CORPORATION. All rights reserved.
     5   */
     6  package jsp
     7  
     8  import "fmt"
     9  
    10  type (
    11  	ErrBadSignature struct {
    12  		tag      string
    13  		got      string
    14  		expected string
    15  	}
    16  	ErrVersion struct {
    17  		tag      string
    18  		got      uint32
    19  		expected uint32
    20  	}
    21  	ErrJspCompatibleVersion struct {
    22  		ErrVersion
    23  	}
    24  	ErrUnsupportedMetaVersion struct {
    25  		ErrVersion
    26  	}
    27  )
    28  
    29  func (e *ErrBadSignature) Error() string {
    30  	return fmt.Sprintf("bad signature %q: got %s, expected %s", e.tag, e.got, e.expected)
    31  }
    32  
    33  func newErrVersion(tag string, got, expected uint32, compatibles ...uint32) error {
    34  	err := &ErrVersion{tag, got, expected}
    35  	for _, v := range compatibles {
    36  		if got == v {
    37  			return &ErrJspCompatibleVersion{*err}
    38  		}
    39  	}
    40  	return &ErrUnsupportedMetaVersion{*err}
    41  }
    42  
    43  func (e *ErrVersion) Version() uint32 { return e.got }
    44  
    45  func (e *ErrUnsupportedMetaVersion) Error() string {
    46  	return fmt.Sprintf("unsupported meta-version %q: got %d, expected %d", e.tag, e.got, e.expected)
    47  }
    48  
    49  func (e *ErrJspCompatibleVersion) Error() string {
    50  	return fmt.Sprintf("older but still compatible meta-version %q: %d (the current meta-version is %d)",
    51  		e.tag, e.got, e.expected)
    52  }