github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/log/errors.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package log
     7  
     8  import "fmt"
     9  
    10  // ErrTimeout represents a "Timeout" kind of error.
    11  type ErrTimeout struct {
    12  	Name     string
    13  	Provider string
    14  }
    15  
    16  // IsErrTimeout checks if an error is a ErrTimeout.
    17  func IsErrTimeout(err error) bool {
    18  	if err == nil {
    19  		return false
    20  	}
    21  	_, ok := err.(ErrTimeout)
    22  	return ok
    23  }
    24  
    25  func (err ErrTimeout) Error() string {
    26  	return fmt.Sprintf("Log Timeout for %s (%s)", err.Name, err.Provider)
    27  }
    28  
    29  // ErrUnknownProvider represents a "Unknown Provider" kind of error.
    30  type ErrUnknownProvider struct {
    31  	Provider string
    32  }
    33  
    34  // IsErrUnknownProvider checks if an error is a ErrUnknownProvider.
    35  func IsErrUnknownProvider(err error) bool {
    36  	if err == nil {
    37  		return false
    38  	}
    39  	_, ok := err.(ErrUnknownProvider)
    40  	return ok
    41  }
    42  
    43  func (err ErrUnknownProvider) Error() string {
    44  	return fmt.Sprintf("Unknown Log Provider \"%s\" (Was it registered?)", err.Provider)
    45  }
    46  
    47  // ErrDuplicateName represents a Duplicate Name error
    48  type ErrDuplicateName struct {
    49  	Name string
    50  }
    51  
    52  // IsErrDuplicateName checks if an error is a ErrDuplicateName.
    53  func IsErrDuplicateName(err error) bool {
    54  	if err == nil {
    55  		return false
    56  	}
    57  	_, ok := err.(ErrDuplicateName)
    58  	return ok
    59  }
    60  
    61  func (err ErrDuplicateName) Error() string {
    62  	return fmt.Sprintf("Duplicate named logger: %s", err.Name)
    63  }