vt-go icon indicating copy to clipboard operation
vt-go copied to clipboard

don't panic inside the library

Open ludusrusso opened this issue 2 years ago • 2 comments

I'm not a fun of using panic inside a client library, this could lead to unexpected crashes of code using the library.

https://github.com/VirusTotal/vt-go/blob/e010bf48aaee07eedebfa842258f1f6d1ec3bdd8/vt.go#L74-L79

What about creating a new method like this?

func NewURL(pathFmt string, a ...interface{}) (*url.URLm, error) {
	path := fmt.Sprintf(pathFmt, a...)
	url, err := url.Parse(path)
	if err != nil {
		return nil, fmt.Errorf(
			"error formatting URL \"%s\": %s",
			pathFmt, err)
	}
	return baseURL.ResolveReference(url), nil
}

ludusrusso avatar Apr 28 '22 13:04 ludusrusso

Also, all the Must* functions defined in https://github.com/VirusTotal/vt-go/blob/master/object.go are potentially dangerous, I suggest to deprecated them since they are not used in the main library!

ludusrusso avatar Apr 28 '22 13:04 ludusrusso

Hello @ludusrusso,

Thank you for your suggestion. Feel free to make a contribution to fix the problem :).

Regards, Marta

mgmacias95 avatar Apr 28 '22 13:04 mgmacias95