github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/node/errors.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 19:16:40</date>
    10  //</624450102370504704>
    11  
    12  
    13  package node
    14  
    15  import (
    16  	"errors"
    17  	"fmt"
    18  	"reflect"
    19  	"syscall"
    20  )
    21  
    22  var (
    23  	ErrDatadirUsed    = errors.New("datadir already used by another process")
    24  	ErrNodeStopped    = errors.New("node not started")
    25  	ErrNodeRunning    = errors.New("node already running")
    26  	ErrServiceUnknown = errors.New("unknown service")
    27  
    28  	datadirInUseErrnos = map[uint]bool{11: true, 32: true, 35: true}
    29  )
    30  
    31  func convertFileLockError(err error) error {
    32  	if errno, ok := err.(syscall.Errno); ok && datadirInUseErrnos[uint(errno)] {
    33  		return ErrDatadirUsed
    34  	}
    35  	return err
    36  }
    37  
    38  //如果注册的服务在节点启动期间返回DuplicateServiceError
    39  //构造函数返回已启动的同一类型的服务。
    40  type DuplicateServiceError struct {
    41  	Kind reflect.Type
    42  }
    43  
    44  //错误生成重复服务错误的文本表示形式。
    45  func (e *DuplicateServiceError) Error() string {
    46  	return fmt.Sprintf("duplicate service: %v", e.Kind)
    47  }
    48  
    49  //如果节点未能停止其任何注册节点,则返回stopError。
    50  //服务或其本身。
    51  type StopError struct {
    52  	Server   error
    53  	Services map[reflect.Type]error
    54  }
    55  
    56  //错误生成停止错误的文本表示形式。
    57  func (e *StopError) Error() string {
    58  	return fmt.Sprintf("server: %v, services: %v", e.Server, e.Services)
    59  }
    60