File: errors.go

package info (click to toggle)
golang-github-marcinbor85-gohex 0.0~git20210308.55fb1c6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 140 kB
  • sloc: makefile: 4
file content (39 lines) | stat: -rw-r--r-- 774 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package gohex

import (
	"fmt"
)

type parseErrorType uint

const (
	_SYNTAX_ERROR   parseErrorType = 1
	_RECORD_ERROR   parseErrorType = 2
	_DATA_ERROR     parseErrorType = 3
	_CHECKSUM_ERROR parseErrorType = 4
)

type parseError struct {
	errorType parseErrorType
	message   string
	lineNum   uint
}

func (e *parseError) Error() string {
	var str string = "error"
	switch e.errorType {
	case _SYNTAX_ERROR:
		str = "syntax error"
	case _RECORD_ERROR:
		str = "record error"
	case _DATA_ERROR:
		str = "data error"
	case _CHECKSUM_ERROR:
		str = "checksum error"
	}
	return fmt.Sprintf("%s: %s at line %d", str, e.message, e.lineNum)
}

func newParseError(et parseErrorType, msg string, line uint) error {
	return &parseError{errorType: et, message: msg, lineNum: line}
}