Skip to content

Error handling

Daria Kolistratova edited this page Dec 20, 2017 · 3 revisions

Yanff functions return a special type of error - NFError

NFError has inside: message, code and error cause (it can be another error or nil).

There are functions in common package that help to process errors:

func GetNFErrorCode(err error) ErrorCode - returns Code from NFError or -1 if error is of different type.

func GetNFError(err error) (nferr *NFError) - returns pointer to NFError if given agrument was of type NFError or *NFError and nil otherwise.

func (err *NFError) Cause() error - returns error cause or err if there is no cause.

Moreover there are Error and Format methods, the first makes NFError implement error interface, the last helps print error with format specifier "%+v" which prints error with stack.

The following list has functions and NFError errors they return:

flow.go:

func SystemInit(args *Config) error

  • common.ParseCPUListErr
  • common.MaxCPUExceedErr

func SystemStart() error

  • common.OpenedFlowAtTheEnd
  • common.PortHasNoQueues
  • common.NotAllQueuesUsed
  • common.FailToInitPort

func SetWriter(IN *Flow, filename string) error

  • common.UseNilFlowErr
  • common.UseClosedFlowErr

func SetReceiver(par interface{}) (OUT *Flow, err error)

  • common.ReqTooManyPorts
  • common.BadArgument

func SetGenerator(generateFunction interface{}, targetSpeed uint64, context UserContext) (OUT *Flow, err error)

  • common.BadArgument

func SetSender(IN *Flow, par interface{}) error

  • common.ReqTooManyPorts
  • common.BadArgument

func SetCopier(IN *Flow) (OUT *Flow, err error)

  • common.UseNilFlowErr
  • common.UseClosedFlowErr

func SetPartitioner(IN *Flow, N uint64, M uint64) (OUT *Flow, err error)

  • common.UseNilFlowErr
  • common.UseClosedFlowErr

func SetSeparator(IN *Flow, separateFunction interface{}, context UserContext) (OUT *Flow, err error)

  • common.UseNilFlowErr
  • common.UseClosedFlowErr
  • common.BadArgument

func SetSplitter(IN *Flow, splitFunction SplitFunction, flowNumber uint, context UserContext) (OutArray [](*Flow), err error)

  • common.UseNilFlowErr
  • common.UseClosedFlowErr

func SetStopper(IN *Flow) error

  • common.UseNilFlowErr
  • common.UseClosedFlowErr

func SetHandler(IN *Flow, handleFunction interface{}, context UserContext) error

  • common.UseNilFlowErr
  • common.UseClosedFlowErr
  • common.BadArgument

func SetMerger(InArray ...*Flow) (OUT *Flow, err error)

  • common.UseNilFlowErr
  • common.UseClosedFlowErr

scheduler.go:

func (scheduler *Scheduler) SystemStart() (err error)

  • common.NotEnoughCores

low.go:

func CreatePort(port uint8, receiveQueuesNumber uint16, sendQueuesNumber uint16, hwtxchecksum bool) error

  • common.FailToInitPort

func AllocateMbufs(mb []uintptr, mempool *Mempool, n uint) error

  • common.AllocMbufErr

func SetPacketStructSize(t int) error

  • common.PktMbufHeadRoomTooSmall

common.go:

func ParseCPUs(s string, coresNumber uint) ([]uint, error)

  • common.ParseCPUListErr
  • common.MaxCPUExceedErr

acl.go:

func GetL2ACLFromJSON(filename string) (*L2Rules, error)

  • common.ParseRuleJSONErr
  • common.FileError
  • common.IncorrectArgInRules
  • common.IncorrectRule

func GetL2ACLFromORIG(filename string) (*L2Rules, error)

  • common.FileError
  • common.ParseRuleError
  • common.IncorrectArgInRules
  • common.IncorrectRule

func GetL3ACLFromJSON(filename string)(*L3Rules, error)

  • common.FileError
  • common.ParseRuleJSONErr
  • common.IncorrectArgInRules
  • common.IncorrectRule

func GetL3ACLFromORIG(filename string) (*L3Rules, error)

  • common.FileError
  • common.ParseRuleError
  • common.IncorrectArgInRules
  • common.IncorrectRule

pcap_utils.go:

func WritePcapGlobalHdr(f io.Writer) error

  • common.PcapWriteFail

func (pkt *Packet) WritePcapOnePacket(f io.Writer) error

  • common.PcapWriteFail

func ReadPcapGlobalHdr(f io.Reader, glHdr *PcapGlobHdr) error

  • common.PcapReadFail

func (pkt *Packet) ReadPcapOnePacket(f io.Reader) (bool, error)

  • common.PcapReadFail