-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pillar/assignableadapters: clear error strings #4238
pillar/assignableadapters: clear error strings #4238
Conversation
This only happens when the manifest has been changed; should I backport this? |
1eb1e11
to
06869fa
Compare
I would say yes... It's a bug fix... |
06869fa
to
0188042
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I think it should be backported.
Waiting for https://api.github.com/repos/lf-edge/eve/actions/workflows/build.yml/runs?head_sha=01880429c1dd5e1dbc2b1da62c894b29a3032dba&status=success to return a non-empty list and rerun the tests. |
0188042
to
0755f2f
Compare
I think the same issue exists for the cycle detection of |
Ok, but we can still merge it in different PRs, if you want |
0755f2f
to
fa8b1a1
Compare
01f9ca3
to
7eccd17
Compare
7eccd17
to
72f7847
Compare
72f7847
to
80f1910
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, looks fine. Minor comments only.
Oh, I expected the go tests to pass =D |
fix for it is:
I will fixup ... |
f02dc67
to
502a7ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
type ownParentError struct{} | ||
|
||
func (o ownParentError) Error() string { | ||
return "IOBundle cannot be it's own parent" | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this approach the recommended golang approach to define error strings?
I think the old/original standard packages just define a well-known string for the exported errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the standard library I see for example:
var EOF = errors.New("EOF")
for most of the newly introduced errors, this approach would work (I guess), but not for the collision error, because the error string is different depending with what it is colliding.
var me3 = errors.New("myErr3")
var me4 = errors.New("myErr4")
errors.Is(me3, me3)
evaluates to false
, because it is evaluating the members.
An alternative approach would be to use errors.Is
and have global instances of ownParentError
, parentAssigngrpMismatchError
, emptyAssigngrpWithParentError
and cycleDetectedError
and then create
the ioBundleCollisionErr
with a
func (i ioBundleCollisisonErr) Is(target err) bool {
return reflect.TypeOf(i) == reflect.TypeOf(m)
}
But are those the same error if they are different collisions?
I have to think about it a bit more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But are those the same error if they are different collisions?
I have to think about it a bit more.
But the Is() implementation can consider the fields in the error struct as well...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the Is() implementation can consider the fields in the error struct as well...
I think that is the default implementation anyways.
I am now using errors.New
and according to the documentation:
func New(text string) error
New returns an error that formats as the given text. Each call to New
returns a distinct error value even if the text is identical.
so that works and the collisionError still uses different error strings, but because I check with reflect.TypeOf
they are detected as the same.
@@ -533,6 +659,7 @@ func (aa *AssignableAdapters) CheckBadUSBBundles() { | |||
continue | |||
} | |||
|
|||
ioBundle.Error.removeByType(ioBundleCollisionErr{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding (which could be wrong) is that when there is a collision the collision error is added to both of the colliding bundles. Is that correct?
If it is, then wouldn't you want to remove all the collisions before scanning for new collisions i.e., do the removal in a separate loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the collision error is added to both of the colliding bundles
That is correct.
do the removal in a separate loop?
I think it is not a problem doing it this way, because the cycleDetectedError
is added in a separate loop.
But I will change it, because indeed it makes it more readable.
collisions: []ioBundleCollision{}, | ||
} | ||
} | ||
|
||
// CheckBadUSBBundles sets ib.Error/ErrorTime if bundle collides in regards of USB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the comment to say that this re-evaluates/updates the set of errors (is it only collision errors) across all of the bundles?
THe current comment doesn't indicate that it will clear existing errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now: // CheckBadUSBBundles sets and clears ib.Error/ErrorTime if bundle collides in regards of USB
func (c cycleDetectedError) Error() string { | ||
return "Cycle detected, please check provided parentassigngrp/assigngrp" | ||
} | ||
|
||
// CheckParentAssigngrp finds dependency loops between ioBundles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the comment to say that it will re-evaluate/update (clear and set any new) errors relating to the parent assigngrp. Current comment implies it doesn't clear any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now: // CheckParentAssigngrp finds dependency loops between ioBundles and sets/clears the error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason a number of eden tests fail and the log shows the state of an app instance flip-flopping between INSTALLED, UNKNOWN, and INITIAL.
I can't see how the iobundle code can do that, but didn't see it on earlier PRs.
502a7ea
to
5f90fb9
Compare
@christoph-zededa rebase the branch, please... Otherwise, it will show the linter issue. I'll try to fix it now |
5f90fb9
to
d999e90
Compare
Seems this is the issue:
|
Why was it not caught by the unit test?.. |
d999e90
to
977b46d
Compare
There was no unit test; now -> https://github.com/lf-edge/eve/pull/4238/files#diff-12fc573707d1d64e810b0b070ad566c6f912c07d10bd1891f13b5d7f9ef95274R902 |
Argh... The issue was not the error itself but the structure that contained this error got it. |
for usb collisions: 1. create two usb adapters with collision 2. change the usbaddr of one of the adapters now the collision should be gone, but as the error string for both adapters has been set, it was not cleared for parentassigngrp cycles: 1. create two usb adapters that have each other as parentassigngrp 2. change the parentassignrp of one of the adapters now the cycle should be gone, but as the error string for both adapters has been set, it was not cleared Also don't overwrite errors and be able to clear specific error types Signed-off-by: Christoph Ostarek <christoph@zededa.com>
977b46d
to
28a08bb
Compare
So, @christoph-zededa, now let's do the backports =) |
now the collision should be gone, but
as the error string for both adapters has been set, it was not cleared