Make sure to clear python errors on every function run.

pull/1/head v0.0.5
Stein Ivar Berghei 2021-12-01 23:18:11 +01:00
parent 95e5ef613f
commit b0171e5974
1 changed files with 4 additions and 1 deletions

View File

@ -50,6 +50,8 @@ func init() {
}
func New() (*Guessit, error) {
python3.PyErr_Clear()
module := python3.PyImport_ImportModule("guessit") //ret val: new ref
if !(module != nil && python3.PyErr_Occurred() == nil) {
return nil, fmt.Errorf("failed to import module 'guessit'")
@ -72,6 +74,8 @@ func New() (*Guessit, error) {
}
func (g Guessit) Guessit(s string, options ...string) (out Match, err error) {
python3.PyErr_Clear()
if len(s) == 0 {
err = fmt.Errorf("input string is empty")
return
@ -85,7 +89,6 @@ func (g Guessit) Guessit(s string, options ...string) (out Match, err error) {
testdataPy := g.fn.CallFunctionObjArgs(item, opts) //retval: New reference
if !(testdataPy != nil && python3.PyErr_Occurred() == nil) {
python3.PyErr_Print()
return
}