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

Recommend error handling #94

Closed
Bwahharharrr opened this issue Jan 1, 2022 · 5 comments
Closed

Recommend error handling #94

Bwahharharrr opened this issue Jan 1, 2022 · 5 comments

Comments

@Bwahharharrr
Copy link

Current error handling

    def _emit_run(self, f, args, kwargs):
        try:
            coro = f(*args, **kwargs)
        except Exception as exc:
            self.emit("error", exc)

recommend to include the function name/args/kwargs etc to help with debugging

    def _emit_run(self, f, args, kwargs):
        try:
            coro = f(*args, **kwargs)
        except Exception as exc:
            self.emit("error", exc, f, args, kwargs)

or some such thing

@leirons
Copy link
Contributor

leirons commented Jan 3, 2022

Think it's a good idea

@jfhbrook
Copy link
Owner

jfhbrook commented Jan 3, 2022

what about:

Args = TypeVar(name="Args")
Kwargs = TypeVar(name="Kwargs")


@dataclass
class CoroError(PyeeError, Generic[Args, Kwargs]):
    exc: Exception
    handler: CoroHandler
    args: Args
    kwargs: Kwargs

    
def _emit_run(self, f: CoroHandler, args: Iterable[Args], kwargs: Dict[str, Kwargs]):
    try:
        coro = f(*args, **kwargs)
    except Exception as exc:
        self.emit("error",CoroError(exc=exc,handler=f,args=args, kwargs=kwargs)

@leirons
Copy link
Contributor

leirons commented Jan 3, 2022

what about:

@dataclass
class AsyncIOPyeeError(PyeeError):
    exc: Exception
    handler: CoroHandler
    args: Tuple[Any,...]
    kwargs: Dict[str, Any]

    
def _emit_run(self, f: CoroHandler, args: Iterable[Args], kwargs: Dict[str, Kwargs]):
    try:
        coro = f(*args, **kwargs)
    except Exception as exc:
        self.emit("error", AsyncIOPyeeError(exc=exc,handler=f,args=args, kwargs=kwargs)

Looks good, but i dont know why you need to use Protocol, didnt see it in other projects and dont know how it's works, but i will check it

@jfhbrook
Copy link
Owner

jfhbrook commented Jan 3, 2022

Protocol might be a red herring, you can probably substitute Generic[Args, Kwargs] instead. If you're not familiar with type annotations you can safely ignore them.

@jfhbrook
Copy link
Owner

I took these notes and captured a plan for potential feature work in #102. In the meantime, I don't have any great answers aside from capturing Exceptions at the top of your handler "manually".

Thanks!

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

No branches or pull requests

3 participants