Skip to content
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

Add common error prefix #291

Merged
merged 2 commits into from
Oct 4, 2019
Merged

Conversation

kung-foo
Copy link
Member

@kung-foo kung-foo commented Oct 2, 2019

Fixes #253

@magiconair magiconair added this to the v0.1.6 milestone Oct 2, 2019
Copy link
Member

@magiconair magiconair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost. Can you clean it up and then we merge?

@@ -391,3 +392,13 @@ func TestSetNamespace(t *testing.T) {
})
}
}

func compareErrors(err1, err2 error) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think reflect.DeepEqual does exactly what compareErrors does.

https://play.golang.org/p/iBDNJELixui

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The underlying stack trace captures will be different:

https://play.golang.org/p/1WqB7u4BUf7

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn. That's not nice since the error itself doesn't change. It doesn't really matter where it occurs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment to this function referring to your play.golang.org link. My guess is that this will bite us at some point when users expect reflect.DeepEqual to work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just got bitten by this in two ways. First, that errors now adds a prefix and then that the comparison did not work. I'll expose the compare function so that we can use that in tests but it would be nice if we could find a more generic solution.

uapolicy/policyAes128Sha256RsaOaep.go Outdated Show resolved Hide resolved
@@ -3,7 +3,7 @@ package uapolicy
import (
"crypto"
"crypto/hmac"
"errors"
"github.com/gopcua/opcua/errors"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort pkg name

uapolicy/policyAes256Sha256RsaPss.go Outdated Show resolved Hide resolved
uapolicy/policyBasic128Rsa15.go Outdated Show resolved Hide resolved
uapolicy/policyBasic256.go Outdated Show resolved Hide resolved
uapolicy/policyBasic256Sha256.go Outdated Show resolved Hide resolved
"sort"

"github.com/gopcua/opcua/errors"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop blank line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you using a different fmt tool? go fmt doesn't report any issues this or uapolicy/crypto_hmac.go

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm just a stickler for these things. I believe in consistency and that developers don't read code but pattern match it. So any deviation from the structure slows you down b/c you fall back to the slower "read code" mode.

@@ -124,7 +124,7 @@ func (s *SecureChannel) SendRequest(req ua.Request, authToken *ua.NodeID, h func
func (s *SecureChannel) SendRequestWithTimeout(req ua.Request, authToken *ua.NodeID, timeout time.Duration, h func(interface{}) error) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this belongs to a different patch

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea how this is contaminating my branch. I even redid this PR from scratch.

@magiconair magiconair merged commit 4326b25 into gopcua:master Oct 4, 2019
magiconair added a commit that referenced this pull request Oct 4, 2019
@kung-foo kung-foo deleted the feature/errors branch October 6, 2019 18:00
magiconair added a commit that referenced this pull request Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error strings should be prefixed
2 participants