forked from awalterschulze/gographviz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
catch.go
101 lines (87 loc) · 2.83 KB
/
catch.go
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//Copyright 2017 GoGraphviz Authors
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
package gographviz
import (
"fmt"
"strings"
)
type errInterface interface {
SetStrict(strict bool)
SetDir(directed bool)
SetName(name string)
AddPortEdge(src, srcPort, dst, dstPort string, directed bool, attrs map[string]string)
AddEdge(src, dst string, directed bool, attrs map[string]string)
AddNode(parentGraph string, name string, attrs map[string]string)
AddAttr(parentGraph string, field, value string)
AddSubGraph(parentGraph string, name string, attrs map[string]string)
String() string
getError() error
}
func newErrCatcher(g Interface) errInterface {
return &errCatcher{g, nil}
}
type errCatcher struct {
Interface
errs []error
}
func (e *errCatcher) SetStrict(strict bool) {
if err := e.Interface.SetStrict(strict); err != nil {
e.errs = append(e.errs, err)
}
}
func (e *errCatcher) SetDir(directed bool) {
if err := e.Interface.SetDir(directed); err != nil {
e.errs = append(e.errs, err)
}
}
func (e *errCatcher) SetName(name string) {
if err := e.Interface.SetName(name); err != nil {
e.errs = append(e.errs, err)
}
}
func (e *errCatcher) AddPortEdge(src, srcPort, dst, dstPort string, directed bool, attrs map[string]string) {
if err := e.Interface.AddPortEdge(src, srcPort, dst, dstPort, directed, attrs); err != nil {
e.errs = append(e.errs, err)
}
}
func (e *errCatcher) AddEdge(src, dst string, directed bool, attrs map[string]string) {
if err := e.Interface.AddEdge(src, dst, directed, attrs); err != nil {
e.errs = append(e.errs, err)
}
}
func (e *errCatcher) AddAttr(parentGraph string, field, value string) {
if err := e.Interface.AddAttr(parentGraph, field, value); err != nil {
e.errs = append(e.errs, err)
}
}
func (e *errCatcher) AddSubGraph(parentGraph string, name string, attrs map[string]string) {
if err := e.Interface.AddSubGraph(parentGraph, name, attrs); err != nil {
e.errs = append(e.errs, err)
}
}
func (e *errCatcher) AddNode(parentGraph string, name string, attrs map[string]string) {
if err := e.Interface.AddNode(parentGraph, name, attrs); err != nil {
e.errs = append(e.errs, err)
}
}
func (e *errCatcher) getError() error {
if len(e.errs) == 0 {
return nil
}
ss := make([]string, len(e.errs))
for i, err := range e.errs {
ss[i] = err.Error()
}
return fmt.Errorf("errors: [%s]", strings.Join(ss, ","))
}