github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/node/errors.go (about)

     1  // This file is part of the go-sberex library. The go-sberex library is 
     2  // free software: you can redistribute it and/or modify it under the terms 
     3  // of the GNU Lesser General Public License as published by the Free 
     4  // Software Foundation, either version 3 of the License, or (at your option)
     5  // any later version.
     6  //
     7  // The go-sberex library is distributed in the hope that it will be useful, 
     8  // but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
    10  // General Public License <http://www.gnu.org/licenses/> for more details.
    11  
    12  package node
    13  
    14  import (
    15  	"errors"
    16  	"fmt"
    17  	"reflect"
    18  	"syscall"
    19  )
    20  
    21  var (
    22  	ErrDatadirUsed    = errors.New("datadir already used by another process")
    23  	ErrNodeStopped    = errors.New("node not started")
    24  	ErrNodeRunning    = errors.New("node already running")
    25  	ErrServiceUnknown = errors.New("unknown service")
    26  
    27  	datadirInUseErrnos = map[uint]bool{11: true, 32: true, 35: true}
    28  )
    29  
    30  func convertFileLockError(err error) error {
    31  	if errno, ok := err.(syscall.Errno); ok && datadirInUseErrnos[uint(errno)] {
    32  		return ErrDatadirUsed
    33  	}
    34  	return err
    35  }
    36  
    37  // DuplicateServiceError is returned during Node startup if a registered service
    38  // constructor returns a service of the same type that was already started.
    39  type DuplicateServiceError struct {
    40  	Kind reflect.Type
    41  }
    42  
    43  // Error generates a textual representation of the duplicate service error.
    44  func (e *DuplicateServiceError) Error() string {
    45  	return fmt.Sprintf("duplicate service: %v", e.Kind)
    46  }
    47  
    48  // StopError is returned if a Node fails to stop either any of its registered
    49  // services or itself.
    50  type StopError struct {
    51  	Server   error
    52  	Services map[reflect.Type]error
    53  }
    54  
    55  // Error generates a textual representation of the stop error.
    56  func (e *StopError) Error() string {
    57  	return fmt.Sprintf("server: %v, services: %v", e.Server, e.Services)
    58  }