Skip to content

Bug: Application terminates because of casting error #741

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

Closed
capt4ce opened this issue Apr 9, 2020 · 0 comments · Fixed by #742 or #747
Closed

Bug: Application terminates because of casting error #741

capt4ce opened this issue Apr 9, 2020 · 0 comments · Fixed by #742 or #747
Assignees
Labels
BUG Something isn't working

Comments

@capt4ce
Copy link
Contributor

capt4ce commented Apr 9, 2020

Description

Returning status.Error() in P2P makes it un-castable to blocker that makes a few points in the code prone to error as P2P is essentially consumed by the same application in other node

Steps to reproduce

Try running this code isolated, it should return the same result:

package main

import (
	"fmt"

	"github.com/zoobc/zoobc-core/common/monitoring"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)

type (
	TypeBlocker string

	Blocker struct {
		Type    TypeBlocker
		Message string
	}
)

var (
	ServiceErr                TypeBlocker = "ServiceErr"
	DBErr                     TypeBlocker = "DBErr"
	DBRowNotFound             TypeBlocker = "DBRowNotFound"
	BlockErr                  TypeBlocker = "BlockErr"
	BlockNotFoundErr          TypeBlocker = "BlockNotFoundErr"
	RequestParameterErr       TypeBlocker = "RequestParameterErr"
	AppErr                    TypeBlocker = "AppErr"
	AuthErr                   TypeBlocker = "AuthErr"
	ValidationErr             TypeBlocker = "ValidationErr"
	DuplicateMempoolErr       TypeBlocker = "DuplicateMempoolErr"
	DuplicateTransactionErr   TypeBlocker = "DuplicateTransactionErr"
	ParserErr                 TypeBlocker = "ParserErr"
	ServerError               TypeBlocker = "ServerError"
	SmithingErr               TypeBlocker = "SmithingErr"
	ZeroParticipationScoreErr TypeBlocker = "ZeroParticipationScoreErr"
	ChainValidationErr        TypeBlocker = "ChainValidationErr"
	P2PNetworkConnectionErr   TypeBlocker = "P2PNetworkConnectionErr"
	SmithingPending           TypeBlocker = "SmithingPending"
	TimeoutExceeded           TypeBlocker = "TimeoutExceeded"
)

func NewBlocker(typeBlocker TypeBlocker, message string) error {
	monitoring.IncrementBlockerMetrics(string(typeBlocker))
	return Blocker{
		Type:    typeBlocker,
		Message: message,
	}
}

func (e Blocker) Error() string {
	return fmt.Sprintf("%v: %v", e.Type, e.Message)
}

func main() {
	err := status.Error(codes.Internal, "test")
	errCasted := err.(Blocker)
	fmt.Println(errCasted.Error())
}

Expected behavior

the casting should not produce error that would make the node terminate

@capt4ce capt4ce self-assigned this Apr 9, 2020
@capt4ce capt4ce added the BUG Something isn't working label Apr 9, 2020
@capt4ce capt4ce mentioned this issue Apr 9, 2020
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant