github.com/pawelgaczynski/gain@v0.4.0-alpha.0.20230821120126-41f1e60a18da/pkg/errors/errors.go (about)

     1  // Copyright (c) 2023 Paweł Gaczyński
     2  // Copyright (c) 2019 Andy Pan
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package errors
    17  
    18  import (
    19  	"errors"
    20  	"fmt"
    21  )
    22  
    23  var (
    24  	// ErrUnsupportedProtocol occurs when trying to use protocol that is not supported.
    25  	ErrUnsupportedProtocol = errors.New("only unix, tcp/tcp4/tcp6, udp/udp4/udp6 are supported")
    26  	// ErrUnsupportedTCPProtocol occurs when trying to use an unsupported TCP protocol.
    27  	ErrUnsupportedTCPProtocol = errors.New("only tcp/tcp4/tcp6 are supported")
    28  	// ErrUnsupportedUDPProtocol occurs when trying to use an unsupported UDP protocol.
    29  	ErrUnsupportedUDPProtocol = errors.New("only udp/udp4/udp6 are supported")
    30  	// ErrNoIPv4AddressOnInterface occurs when an IPv4 multicast address is set on an interface but IPv4 is not configured.
    31  	ErrNoIPv4AddressOnInterface = errors.New("no IPv4 address on interface")
    32  	// ErrNotSupported occurs when not supported feature is used.
    33  	ErrNotSupported = errors.New("not supported")
    34  	// ErrSkippable indicates an error that can be skipped and not handled as an usual flow breaking error.
    35  	ErrSkippable = errors.New("skippable")
    36  	// ErrIsEmpty indicates that data holder, data magazine or buffer is empty.
    37  	ErrIsEmpty = errors.New("is empty")
    38  	// ErrConnectionAlreadyClosed when trying to close already closed connection.
    39  	ErrConnectionAlreadyClosed = errors.New("connection already closed")
    40  	// ErrConnectionAlreadyClosed when trying to work with closed connection.
    41  	ErrConnectionClosed = errors.New("connection closed")
    42  	// ErrOpNotAvailableInMode occurs when trying to run operation that is not available in current mode.
    43  	ErrOpNotAvailableInMode = errors.New("op is not available in mode")
    44  	// ErrConnectionQueueIsNil occurs when trying to access connection queue that is not initialized.
    45  	ErrConnectionQueueIsNil = errors.New("connection queue is nil")
    46  	// ErrUnknownConnectionState occurs when connection state is unknown.
    47  	ErrUnknownConnectionState = errors.New("unknown connection state")
    48  	// ErrInvalidTimeDuration occure when specyfied time duration is not valid.
    49  	ErrInvalidTimeDuration = errors.New("invalid time duration")
    50  	// ErrInvalidState occurs when operation is called in invalid state.
    51  	ErrInvalidState = errors.New("invalid state")
    52  	// ErrAddressNotFound occurs when network address of fd could not be found.
    53  	ErrAddressNotFound = errors.New("address could not be found")
    54  	// ErrServerAlreadyRunning occurs when trying to start already running server.
    55  	ErrServerAlreadyRunning = errors.New("server already running")
    56  	// ErrGettingSQE occurs when SQE could not be obtained.
    57  	ErrGettingSQE = errors.New("error getting SQE")
    58  )
    59  
    60  func ErrorOpNotAvailableInMode(op, mode string) error {
    61  	return fmt.Errorf("%w, op: %s, mode: %s", ErrOpNotAvailableInMode, op, mode)
    62  }
    63  
    64  func ErrorUnknownConnectionState(state int) error {
    65  	return fmt.Errorf("%w, state: %d", ErrUnknownConnectionState, state)
    66  }
    67  
    68  func ErrorAddressNotFound(fd int) error {
    69  	return fmt.Errorf("%w, fd: %d", ErrAddressNotFound, fd)
    70  }