From b0171e5974fa4372ae1ea6b94e5e38ac0c1fa7b3 Mon Sep 17 00:00:00 2001 From: Stein Ivar Berghei Date: Wed, 1 Dec 2021 23:18:11 +0100 Subject: [PATCH] Make sure to clear python errors on every function run. --- guessit.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/guessit.go b/guessit.go index 62b34d0..07bd317 100644 --- a/guessit.go +++ b/guessit.go @@ -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 }