From 4e1bda674d95b0fe3df028a9f429aa171ae63a68 Mon Sep 17 00:00:00 2001 From: Arjun Satarkar Date: Tue, 12 Mar 2024 20:59:40 -0400 Subject: markov: improve exceptions --- markov/errors.py | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'markov/errors.py') diff --git a/markov/errors.py b/markov/errors.py index 1af7de8..875d3b7 100644 --- a/markov/errors.py +++ b/markov/errors.py @@ -1,14 +1,46 @@ class MarkovGenerationError(Exception): - pass + def __init__(self, guild_id: int, member_id: int | None): + self.guild_id = guild_id + self.member_id = member_id + + def __repr__(self): + return f"MarkovGenerationError(guild_id={self.guild_id}, member_id={self.member_id})" class NoTotalCompletionCountError(MarkovGenerationError): - pass + def __init__(self, guild_id: int, member_id: int | None, token: str): + super().__init__(guild_id, member_id) + self.token = token + + def __repr__(self): + return ( + "NoTotalCompletionCountError(guild_id={}, member_id={}, token={})".format( + self.guild_id, self.member_id, repr(self.token) + ) + ) class NoNextTokenError(MarkovGenerationError): - pass + def __init__(self, guild_id: int, member_id: int | None, token: str, offset: int): + super().__init__(guild_id, member_id) + self.token = token + self.offset = offset + + def __repr__(self): + return ( + "NoNextTokenError(guild_id={}, member_id={}, token={}, offset={})".format( + self.guild_id, self.member_id, repr(self.token), self.offset + ) + ) class InvalidCompletionCountError(MarkovGenerationError): - pass + def __init__(self, guild_id: int, member_id: int | None, token: str, offset: int): + super().__init__(guild_id, member_id) + self.token = token + self.offset = offset + + def __repr__(self): + return "InvalidCompletionCountError(guild_id={}, member_id={}, token={}, offset={})".format( + self.guild_id, self.member_id, repr(self.token), self.offset + ) -- cgit v1.2.3-57-g22cb