File: errors.go

package info (click to toggle)
golang-gopkg-gcfg.v1 1.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 268 kB
  • sloc: makefile: 7
file content (57 lines) | stat: -rw-r--r-- 1,095 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package gcfg

import warnings "gopkg.in/warnings.v0"

// FatalOnly filters the results of a Read*Into invocation and returns only
// fatal errors. That is, errors (warnings) indicating data for unknown
// sections / variables is ignored. Example invocation:
//
//  err := gcfg.FatalOnly(gcfg.ReadFileInto(&cfg, configFile))
//  if err != nil {
//      ...
//
func FatalOnly(err error) error {
	return warnings.FatalOnly(err)
}

func isFatal(err error) bool {
	_, ok := err.(extraData)
	return !ok
}

type loc struct {
	section    string
	subsection *string
	variable   *string
}

type extraData struct {
	loc
}

type locErr struct {
	msg string
	loc
}

func (l loc) String() string {
	s := "section \"" + l.section + "\""
	if l.subsection != nil {
		s += ", subsection \"" + *l.subsection + "\""
	}
	if l.variable != nil {
		s += ", variable \"" + *l.variable + "\""
	}
	return s
}

func (e extraData) Error() string {
	return "can't store data at " + e.loc.String()
}

func (e locErr) Error() string {
	return e.msg + " at " + e.loc.String()
}

var _ error = extraData{}
var _ error = locErr{}