Skip to content

Commit 8890672

Browse files
authored
[#105]: bug(init): fix panic on zero value
[#105]: bug(init): fix panic on zero value
2 parents 047a8a2 + 76fb721 commit 8890672

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

pkg/container/endure.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,6 @@ START:
379379

380380
head := e.runList.Head
381381
for head != nil {
382-
// do not initialize twice
383-
if ok := e.initialized[head.Vertex.ID]; ok {
384-
head = head.Next
385-
continue
386-
}
387-
388382
// check for disabled, because that can be interface
389383
if _, ok := e.disabled[head.Vertex.ID]; ok {
390384
err = e.removeVertex(head)

pkg/container/init.go

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,35 @@ func (e *Endure) callInitFn(init reflect.Method, vrtx *vertex.Vertex) error {
5050
}
5151
// Iterate over dependencies
5252
// And search in Vertices for the provided types
53-
ret := init.Func.Call(in)
54-
rErr := ret[0].Interface()
55-
if rErr != nil {
56-
var ok bool
57-
if err, ok = rErr.(error); ok && err != nil {
58-
/*
59-
If vertex is disabled we skip all processing for it:
60-
1. We don't add Init function args as dependencies
61-
*/
62-
if errors.Is(errors.Disabled, err) {
53+
54+
// do not initialize twice, but we should add the init args to the global provider
55+
if _, ok := e.initialized[vrtx.ID]; !ok {
56+
ret := init.Func.Call(in)
57+
rErr := ret[0].Interface()
58+
if rErr != nil {
59+
var ok bool
60+
if err, ok = rErr.(error); ok && err != nil {
6361
/*
64-
DisableById vertex
65-
1. But if vertex is disabled it can't PROVIDE via v.Provided value of itself for other vertices
66-
and we should recalculate whole three without this dep.
62+
If vertex is disabled we skip all processing for it:
63+
1. We don't add Init function args as dependencies
6764
*/
68-
e.logger.Warn("vertex disabled", zap.String("id", vrtx.ID), zap.Error(err))
69-
// disable current vertex
70-
vrtx.IsDisabled = true
71-
// Disabled is actually to an error, just notification to the graph, that it has some vertices which are disabled
72-
return errors.E(op, errors.Disabled)
73-
}
65+
if errors.Is(errors.Disabled, err) {
66+
/*
67+
DisableById vertex
68+
1. But if vertex is disabled it can't PROVIDE via v.Provided value of itself for other vertices, and we should recalculate whole three without this dep.
69+
*/
70+
e.logger.Warn("vertex disabled", zap.String("id", vrtx.ID), zap.Error(err))
71+
// disable current vertex
72+
vrtx.IsDisabled = true
73+
// Disabled is actually to an error, just notification to the graph, that it has some vertices which are disabled
74+
return errors.E(op, errors.Disabled)
75+
}
7476

75-
e.logger.Error("error calling internal_init", zap.String("id", vrtx.ID), zap.Error(err))
76-
return errors.E(op, errors.FunctionCall, err)
77+
e.logger.Error("error calling internal_init", zap.String("id", vrtx.ID), zap.Error(err))
78+
return errors.E(op, errors.FunctionCall, err)
79+
}
80+
return errors.E(op, errors.FunctionCall, errors.Str("unknown error occurred during the function call"))
7781
}
78-
return errors.E(op, errors.FunctionCall, errors.Str("unknown error occurred during the function call"))
7982
}
8083

8184
// just to be safe here

0 commit comments

Comments
 (0)