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

unhandled-error could not detect unhandled errors of third party package methods #582

Open
ChenhuaYang opened this issue Sep 27, 2021 · 2 comments

Comments

@ChenhuaYang
Copy link

Describe the bug

Method TypeCheck() will return error "could not import xxx" if detect third party package. Such as:
could not import github.com/hyperledger/fabric/core/chaincode/shim (can't find import: github.com/hyperledger/fabric/core/chaincode/shim)

When the error emerged, revive could not get enough type information. So revive could not detect unhandled errors of third party package methods and nothing reported.

package main

import (

	"github.com/hyperledger/fabric/core/chaincode/shim"
	pb "github.com/hyperledger/fabric/protos/peer"
)

func (t *SimpleChaincode) insert(stub shim.ChaincodeStubInterface, args []string) pb.Response {

	if len(args) != 2 {
		return shim.Error("Incorrect number of arguments. Expecting 2")
	}
	key := args[0]
	val := args[1]

	// Unhandled error
	stub.PutState(key, []byte(val))
	return shim.Success(nil)
}
@chavacava
Copy link
Collaborator

Hi @ChenhuaYang, thanks for filling the issue.
As you describe, the rule needs type checking information to complete its analysis. If the type check fails then the rule is unable to continue.
To fix this bug it is necessary to improve the type analysis code. In fact the current analysis code leverages on the original GO build machinery that was then superseded by packages package to better cope with modules.

@ChenhuaYang
Copy link
Author

So we might need packages.Load to load packages? Or use go/analysis?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants