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

Keep calm and don't panic: enable and apply forcetypeassert lint rules #522

Merged
merged 1 commit into from
Jun 29, 2022

Conversation

Dentrax
Copy link
Member

@Dentrax Dentrax commented Jun 22, 2022

Signed-off-by: Furkan furkan.turkal@trendyol.com

Summary

I was playing with Vault KMS and hit two different panic cases. And both of are actually casting error:

  1. keysData.(map[string]interface{})
  2. latestVersion.(json.Number)

I'm not so sure which cases caused this problem. So I thought It would be nice to have a forcetypeassert analyzer in the golangci-lint.

I also had to remove the following line because forcetypeassert still complains about: type assertion must be checked

return fmt.Errorf("data type assertion for field `valid` failed: %T %#v", valid.(bool), valid.(bool))

I could have passed a //nolinter: but I thought in both cases the following above throws panic, right? @blz-ea

Ticket Link

Fixes

Release Note

Enable forcetypeassert linter in golangic-lint

Signed-off-by: Furkan <furkan.turkal@trendyol.com>
@@ -309,7 +323,7 @@ func (h hashivaultClient) verify(sig, digest []byte, alg crypto.Hash, opts ...si

isValid, ok := valid.(bool)
if !ok {
return fmt.Errorf("data type assertion for field `valid` failed: %T %#v", valid.(bool), valid.(bool))
return fmt.Errorf("received non-bool value from 'valid' key")
Copy link
Member

Choose a reason for hiding this comment

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

should we use something like %T to still get the type or %s to attempt to stringify it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Reproduced the same case on playground, and it threw panic for the valid.(bool) casting: https://go.dev/play/p/-rCmjQsK0e8

But works well if we just use

fmt.Printf("%T %#v", valid, valid)

I can change all type assert errors to get their types %T and stringify %#v but I'm not sure if they are safe to print the entire content to stdout in vault client. 🤔

@dlorenc dlorenc merged commit b95fc0d into sigstore:main Jun 29, 2022
mtrmac pushed a commit to mtrmac/sigstore that referenced this pull request Mar 10, 2023
* sigstore#522 set Created date to time of execution

Signed-off-by: Tobias Trabelsi <lerentis@uploadfilter24.eu>

* sigstore#522 added check to only sign if previous date was zero and added date change to files as well

Signed-off-by: Tobias Trabelsi <tobias.trabelsi@dbschenker.com>

* added unit tests and removed log entry

Signed-off-by: Tobias Trabelsi <tobias.trabelsi@dbschenker.com>

* sigstore#522 review feedback

Signed-off-by: Tobias Trabelsi <tobias.trabelsi@dbschenker.com>

* sigstore#522 Apply suggestions from code review

Co-authored-by: Jason Hall <jason@chainguard.dev>
Signed-off-by: Tobias Trabelsi <tobias.trabelsi@dbschenker.com>

* sigstore#522 additional nil check

Signed-off-by: Tobias Trabelsi <tobias.trabelsi@dbschenker.com>

Co-authored-by: Tobias Trabelsi <tobias.trabelsi@dbschenker.com>
Co-authored-by: Jason Hall <jason@chainguard.dev>
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.

None yet

2 participants