Skip to content

Commit 0aa656a

Browse files
committed
improve error handling
Signed-off-by: Florian Lehner <[email protected]>
1 parent 4938b38 commit 0aa656a

18 files changed

+40
-52
lines changed

f_route4.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func unmarshalRoute4(data []byte, info *Route4) error {
4444
return fmt.Errorf("unmarshalRoute4()\t%d\n\t%v", ad.Type(), ad.Bytes())
4545
}
4646
}
47-
return nil
47+
return ad.Err()
4848
}
4949

5050
// marshalRoute4 returns the binary encoding of Route4

f_tcindex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,5 @@ func unmarshalTcIndex(data []byte, info *TcIndex) error {
7676
return fmt.Errorf("unmarshalTcIndex()\t%d\n\t%v", ad.Type(), ad.Bytes())
7777
}
7878
}
79-
return nil
79+
return ad.Err()
8080
}

f_u32.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func unmarshalU32(data []byte, info *U32) error {
154154
return fmt.Errorf("unmarshalU32()\t%d\n\t%v", ad.Type(), ad.Bytes())
155155
}
156156
}
157-
return multiError
157+
return concatError(multiError, ad.Err())
158158
}
159159

160160
// U32Sel from include/uapi/linux/pkt_sched.h

q_atm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func unmarshalAtm(data []byte, info *Atm) error {
4949

5050
}
5151
}
52-
return nil
52+
return ad.Err()
5353
}
5454

5555
// marshalAtm returns the binary encoding of Atm

q_cake.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func unmarshalCake(data []byte, info *Cake) error {
115115
return fmt.Errorf("unmarshalCake()\t%d\n\t%v", ad.Type(), ad.Bytes())
116116
}
117117
}
118-
return nil
118+
return ad.Err()
119119
}
120120

121121
// marshalCake returns the binary encoding of Red

q_cbq.go

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,51 +34,46 @@ func unmarshalCbq(data []byte, info *Cbq) error {
3434
if err != nil {
3535
return err
3636
}
37+
var multiError error
3738
for ad.Next() {
3839
switch ad.Type() {
3940
case tcaCbqLssOpt:
4041
arg := &CbqLssOpt{}
41-
if err := unmarshalStruct(ad.Bytes(), arg); err != nil {
42-
return err
43-
}
42+
err := unmarshalStruct(ad.Bytes(), arg)
43+
concatError(multiError, err)
4444
info.LssOpt = arg
4545
case tcaCbqWrrOpt:
4646
arg := &CbqWrrOpt{}
47-
if err := unmarshalStruct(ad.Bytes(), arg); err != nil {
48-
return err
49-
}
47+
err := unmarshalStruct(ad.Bytes(), arg)
48+
concatError(multiError, err)
5049
info.WrrOpt = arg
5150
case tcaCbqFOpt:
5251
arg := &CbqFOpt{}
53-
if err := unmarshalStruct(ad.Bytes(), arg); err != nil {
54-
return err
55-
}
52+
err := unmarshalStruct(ad.Bytes(), arg)
53+
concatError(multiError, err)
5654
info.FOpt = arg
5755
case tcaCbqOVLStrategy:
5856
arg := &CbqOvl{}
59-
if err := unmarshalStruct(ad.Bytes(), arg); err != nil {
60-
return err
61-
}
57+
err := unmarshalStruct(ad.Bytes(), arg)
58+
concatError(multiError, err)
6259
info.OVLStrategy = arg
6360
case tcaCbqRate:
6461
arg := &RateSpec{}
65-
if err := unmarshalStruct(ad.Bytes(), arg); err != nil {
66-
return err
67-
}
62+
err := unmarshalStruct(ad.Bytes(), arg)
63+
concatError(multiError, err)
6864
info.Rate = arg
6965
case tcaCbqRTab:
7066
info.RTab = ad.Bytes()
7167
case tcaCbqPolice:
7268
arg := &CbqPolice{}
73-
if err := unmarshalStruct(ad.Bytes(), arg); err != nil {
74-
return err
75-
}
69+
err := unmarshalStruct(ad.Bytes(), arg)
70+
concatError(multiError, err)
7671
info.Police = arg
7772
default:
7873
return fmt.Errorf("unmarshalCbq()\t%d\n\t%v", ad.Type(), ad.Bytes())
7974
}
8075
}
81-
return nil
76+
return concatError(multiError, ad.Err())
8277
}
8378

8479
// marshalCbq returns the binary encoding of Qfq
@@ -90,42 +85,35 @@ func marshalCbq(info *Cbq) ([]byte, error) {
9085
}
9186
// TODO: improve logic and check combinations
9287

88+
var multiError error
9389
if info.LssOpt != nil {
9490
data, err := marshalStruct(info.LssOpt)
95-
if err != nil {
96-
return []byte{}, err
97-
}
91+
concatError(multiError, err)
9892
options = append(options, tcOption{Interpretation: vtBytes, Type: tcaCbqLssOpt, Data: data})
9993
}
10094
if info.WrrOpt != nil {
10195
data, err := marshalStruct(info.WrrOpt)
102-
if err != nil {
103-
return []byte{}, err
104-
}
96+
concatError(multiError, err)
10597
options = append(options, tcOption{Interpretation: vtBytes, Type: tcaCbqWrrOpt, Data: data})
10698
}
10799
if info.FOpt != nil {
108100
data, err := marshalStruct(info.FOpt)
109-
if err != nil {
110-
return []byte{}, err
111-
}
101+
concatError(multiError, err)
112102
options = append(options, tcOption{Interpretation: vtBytes, Type: tcaCbqFOpt, Data: data})
113103
}
114104
if info.OVLStrategy != nil {
115105
data, err := marshalStruct(info.OVLStrategy)
116-
if err != nil {
117-
return []byte{}, err
118-
}
106+
concatError(multiError, err)
119107
options = append(options, tcOption{Interpretation: vtBytes, Type: tcaCbqOVLStrategy, Data: data})
120108
}
121109
if info.Police != nil {
122110
data, err := marshalStruct(info.Police)
123-
if err != nil {
124-
return []byte{}, err
125-
}
111+
concatError(multiError, err)
126112
options = append(options, tcOption{Interpretation: vtBytes, Type: tcaCbqPolice, Data: data})
127113
}
128-
114+
if multiError != nil {
115+
return []byte{}, multiError
116+
}
129117
return marshalAttributes(options)
130118
}
131119

q_choke.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func unmarshalChoke(data []byte, info *Choke) error {
3939
return fmt.Errorf("unmarshalChoke()\t%d\n\t%v", ad.Type(), ad.Bytes())
4040
}
4141
}
42-
return nil
42+
return ad.Err()
4343
}
4444

4545
// marshalChoke returns the binary encoding of Choke

q_codel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func unmarshalCodel(data []byte, info *Codel) error {
4646
return fmt.Errorf("unmarshalCodel()\t%d\n\t%v", ad.Type(), ad.Bytes())
4747
}
4848
}
49-
return nil
49+
return ad.Err()
5050
}
5151

5252
// marshalCodel returns the binary encoding of Red

q_drr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func unmarshalDrr(data []byte, info *Drr) error {
3030
return fmt.Errorf("UnmarshalDrr()\t%d\n\t%v", ad.Type(), ad.Bytes())
3131
}
3232
}
33-
return nil
33+
return ad.Err()
3434
}
3535

3636
// marshalDrr returns the binary encoding of Qfq

q_dsmark.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func unmarshalDsmark(data []byte, info *Dsmark) error {
4646
return fmt.Errorf("UnmarshalDsmark()\t%d\n\t%v", ad.Type(), ad.Bytes())
4747
}
4848
}
49-
return nil
49+
return ad.Err()
5050
}
5151

5252
// marshalDsmark returns the binary encoding of Qfq

q_ets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func unmarshalEtsQuanta(data []byte, info *[]uint32) error {
3939
return fmt.Errorf("unmarshalEtsQuanta()\t%d\n\t%v", ad.Type(), ad.Bytes())
4040
}
4141
}
42-
return nil
42+
return ad.Err()
4343
}
4444

4545
// marshalEtsQuanta

q_fq.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func unmarshalFq(data []byte, info *Fq) error {
7474
return fmt.Errorf("unmarshalFq()\t%d\n\t%v", ad.Type(), ad.Bytes())
7575
}
7676
}
77-
return nil
77+
return ad.Err()
7878
}
7979

8080
// marshalFq returns the binary encoding of Fq

q_fqCodel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,5 @@ func unmarshalFqCodel(data []byte, info *FqCodel) error {
115115
return fmt.Errorf("unmarshalFqCodel()\t%d\n\t%v", ad.Type(), ad.Bytes())
116116
}
117117
}
118-
return nil
118+
return ad.Err()
119119
}

q_hhf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func unmarshalHhf(data []byte, info *Hhf) error {
5454
return fmt.Errorf("unmarshalHhf()\t%d\n\t%v", ad.Type(), ad.Bytes())
5555
}
5656
}
57-
return nil
57+
return ad.Err()
5858
}
5959

6060
// marshalHhf returns the binary encoding of Hhf

q_pie.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func unmarshalPie(data []byte, info *Pie) error {
5454
return fmt.Errorf("extractPieOptions()\t%d\n\t%v", ad.Type(), ad.Bytes())
5555
}
5656
}
57-
return nil
57+
return ad.Err()
5858
}
5959

6060
// marshalPie returns the binary encoding of Qfq

q_qfq.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func unmarshalQfq(data []byte, info *Qfq) error {
3434
return fmt.Errorf("UnmarshalQfq()\t%d\n\t%v", ad.Type(), ad.Bytes())
3535
}
3636
}
37-
return nil
37+
return ad.Err()
3838
}
3939

4040
// marshalQfq returns the binary encoding of Qfq

q_red.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func unmarshalRed(data []byte, info *Red) error {
3939
return fmt.Errorf("unmarshalRed()\t%d\n\t%v", ad.Type(), ad.Bytes())
4040
}
4141
}
42-
return nil
42+
return ad.Err()
4343
}
4444

4545
// marshalRed returns the binary encoding of Red

q_sfb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func unmarshalSfb(data []byte, info *Sfb) error {
3434
return fmt.Errorf("extractSfbOptions()\t%d\n\t%v", ad.Type(), ad.Bytes())
3535
}
3636
}
37-
return nil
37+
return ad.Err()
3838
}
3939

4040
// marshalSfb returns the binary encoding of Sfb

0 commit comments

Comments
 (0)