steam icon indicating copy to clipboard operation
steam copied to clipboard

Make EResult (or the full response) accessible in SteamAuthenticatorError.

Open luckydonald opened this issue 4 years ago • 3 comments

So current situation is that stuff like SteamAuthenticator(…).add() can cause SteamAuthenticatorError.

For example,

Traceback (most recent call last):
…
steam.guard.SteamAuthenticatorError: Failed to add authenticator. Error: <EResult.DuplicateRequest: 29>

Now that's a pretty easy to catch that error, telling the user to first have it log off the old instance, hence duplicate. Just, we can't really distinguish those errors unless we do some ugly string stuff on that returned string.

# "Failed to add authenticator. Error: <EResult.DuplicateRequest: 29>"
if str(e).startswith("Failed to add authenticator. Error: <EResult."):
  error_string = str(e)[45:-1]  # "DuplicateRequest: 29"
  error_label, error_num = error_string.split(": ")
  from steam.enums import EResult
  error_label = EResult[error_label]
  error_num = EResult(int(error_num))
  if error_label == error_num:
    error = error_label
  # end if
  if error == EResult.DuplicateRequest:
    exit('Already have set an authenticator in another app')
  # end if
# end if

This is obviously super prone to issues due to changes there, it would be way better to just include those fields in the exception.

luckydonald avatar Sep 15 '21 10:09 luckydonald

That's a good point.

https://github.com/ValvePython/steam/blob/061ca33842c9ec5aa7c0866d20cbeed0759d5ea5/steam/guard.py#L469-L470

SteamAuthenticatorError should really inherit from steam.exceptions.SteamError. And then any places where it sets the eresult should be passed as parameter. This looks like a straightforward change

rossengeorgiev avatar Sep 27 '21 19:09 rossengeorgiev

I can see if I have time to do a PR

luckydonald avatar Sep 28 '21 12:09 luckydonald

Made one.

luckydonald avatar Sep 28 '21 12:09 luckydonald