steamworks/
error.rs

1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3
4use crate::sys;
5use std::{convert::TryFrom, ffi::CStr};
6
7/// Covers errors that can be returned by the steamworks API
8///
9/// Documentation is based on official documentation which doesn't
10/// always explain when an error could be returned or its meaning.
11#[derive(Copy, Clone, Debug, Error, PartialEq, Eq)]
12#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
13pub enum SteamError {
14    /// Returned if the steamworks API fails to initialize.
15    #[error("failed to init the steamworks API")]
16    InitFailed,
17    /// Returned if the steamworks API fails to perform an action
18    #[error("a generic failure from the steamworks API")]
19    Generic,
20    /// Returned when steam fails performing a network request
21    #[error("there isn't a network connection to steam or it failed to connect")]
22    NoConnection,
23    /// Return when the password or ticked used is invalid
24    #[error("password or ticket is invalid")]
25    InvalidPassword,
26    /// Returned when the user is already logged in at another location
27    #[error("user logged in elsewhere")]
28    LoggedInElsewhere,
29    /// Returned when the protocol version is incorrect
30    #[error("the protocol version is incorrect")]
31    InvalidProtocolVersion,
32    /// Returned when a passed parameter is invalid
33    #[error("a parameter is invalid")]
34    InvalidParameter,
35    /// Returned when a file is not found
36    #[error("a file was not found")]
37    FileNotFound,
38    /// Returned when the called method was busy
39    ///
40    /// No action was performed
41    #[error("method busy")]
42    Busy,
43    /// Returned when the called object was in an
44    /// invalid state
45    #[error("object in invalid state")]
46    InvalidState,
47    /// Returned when the name is invalid
48    #[error("name is invalid")]
49    InvalidName,
50    /// Returned when the email is invalid
51    #[error("email is invalid")]
52    InvalidEmail,
53    /// Returned when the name is not unique
54    #[error("name is not unique")]
55    DuplicateName,
56    /// Returned when access is denied
57    #[error("access denied")]
58    AccessDenied,
59    /// Returned when the operation timed out
60    #[error("operation timed out")]
61    Timeout,
62    /// Returned when the user is VAC2 banned
63    #[error("VAC2 banned")]
64    Banned,
65    /// Returned when the account is not found
66    #[error("account not found")]
67    AccountNotFound,
68    /// Returned when the passed steam id is invalid
69    #[error("steamID is invalid")]
70    InvalidSteamID,
71    /// Returned when the requested service in unavailable
72    #[error("requested service is unavailable")]
73    ServiceUnavailable,
74    /// Returned when the user is not logged on
75    #[error("user not logged on")]
76    NotLoggedOn,
77    /// Returned when the request is pending (e.g. in progress/waiting)
78    #[error("request is pending")]
79    Pending,
80    /// Returned when encryption or decryption fails
81    #[error("encryption/decryption failed")]
82    EncryptionFailure,
83    /// Returned when you have insufficient privilege to perform
84    /// the action
85    #[error("insufficient privilege")]
86    InsufficientPrivilege,
87    /// Returned when you have hit the API limits
88    #[error("limit exceeded")]
89    LimitExceeded,
90    /// Returned when the user's access has been revoked (e.g. revoked
91    /// guess passes)
92    #[error("access revoked")]
93    Revoked,
94    /// Returned when the user's access has expired
95    #[error("access expired")]
96    Expired,
97    /// Returned when the licence/guest pass has already been redeemed
98    #[error("licence/guest pass already redeemed")]
99    AlreadyRedeemed,
100    /// Returned when the requested action is a duplicate and has
101    /// already occurred.
102    ///
103    /// The action will be ignored
104    #[error("request is a duplicate")]
105    DuplicateRequest,
106    /// Returned when all the games in the guest pass are already
107    /// owned by the user
108    #[error("all games requested already owned")]
109    AlreadyOwned,
110    /// Returned when the ip address is not found
111    #[error("ip address not found")]
112    IPNotFound,
113    /// Returned when the change failed to write to the data store
114    #[error("failed to write change")]
115    PersistFailed,
116    /// Returned when the operation failed to acquire the access lock
117    #[error("failed to acquire access lock")]
118    LockingFailed,
119    /// Undocumented
120    #[error("logon session replaced")]
121    LogonSessionReplaced,
122    /// Undocumented
123    #[error("connect failed")]
124    ConnectFailed,
125    /// Undocumented
126    #[error("handshake failed")]
127    HandshakeFailed,
128    /// Undocumented
129    #[error("IO failure")]
130    IOFailure,
131    /// Undocumented
132    #[error("remote disconnect")]
133    RemoteDisconnect,
134    /// Returned when the requested shopping cart wasn't found
135    #[error("failed to find the requested shopping cart")]
136    ShoppingCartNotFound,
137    /// Returned when the user blocks an action
138    #[error("action blocked")]
139    Blocked,
140    /// Returned when the target user is ignoring the sender
141    #[error("target is ignoring sender")]
142    Ignored,
143    /// Returned when nothing matching the request is found
144    #[error("no matches found")]
145    NoMatch,
146    /// Undocumented
147    #[error("account disabled")]
148    AccountDisabled,
149    /// Returned when the service isn't accepting content changes at
150    /// this moment
151    #[error("service is read only")]
152    ServiceReadOnly,
153    /// Returned when the account doesn't have value so the feature
154    /// isn't available
155    #[error("account not featured")]
156    AccountNotFeatured,
157    /// Allowed to take this action but only because the requester is
158    /// an admin
159    #[error("administrator ok")]
160    AdministratorOK,
161    /// Returned when there is a version mismatch in content transmitted
162    /// within the steam protocol
163    #[error("version mismatch with transmitted content")]
164    ContentVersion,
165    /// Returned when the current CM cannot service the user's request.
166    ///
167    /// The user should try another.
168    #[error("CM cannot service user")]
169    TryAnotherCM,
170    /// Returned when the user is already logged in elsewhere and the
171    /// cached credential login failed.
172    #[error("user already logged in, cached login failed")]
173    PasswordRequiredToKickSession,
174    /// Returned when the user is already logged in elsewhere, you
175    /// must wait before trying again
176    #[error("user already logged in, please wait")]
177    AlreadyLoggedInElsewhere,
178    /// Returned when a long running operation (e.g. download) is
179    /// suspended/paused.
180    #[error("operation suspended/paused")]
181    Suspended,
182    /// Returned when an operation is cancelled
183    #[error("operation cancelled")]
184    Cancelled,
185    /// Returned when an operation is cancelled due to data corruption
186    #[error("operation cancelled due to data corruption")]
187    DataCorruption,
188    /// Returned when an operation is cancelled due to running out of disk
189    /// space
190    #[error("operation cancelled due to the disk being full")]
191    DiskFull,
192    /// Returned when a remote call or an IPC call failed
193    #[error("remote/IPC call failed")]
194    RemoteCallFailed,
195    /// Returned when a password could not be verified as its unset
196    /// server side
197    #[error("cannot verify unset password")]
198    PasswordUnset,
199    /// Returned when the external account is not linked to a steam
200    /// account
201    #[error("external account not linked to steam")]
202    ExternalAccountUnlinked,
203    /// Returned when the PSN ticket is invalid
204    #[error("PSN ticket invalid")]
205    PSNTicketInvalid,
206    /// Returned when the external account is already linked to a steam
207    /// account
208    #[error("external account already linked")]
209    ExternalAccountAlreadyLinked,
210    /// Returned when sync cannot resume due to a file conflict
211    #[error("sync conflict between remote and local files")]
212    RemoteFileConflict,
213    /// Returned when the requested new password is not legal
214    #[error("new password is illegal")]
215    IllegalPassword,
216    /// Returned when the new value is the same as the previous value
217    #[error("new value is the same as old value")]
218    SameAsPreviousValue,
219    /// Returned when the account logon is denied to 2nd factor authentication
220    /// failure
221    #[error("2nd factor authentication failed")]
222    AccountLogonDenied,
223    /// Returned when the requested new password is the same as the
224    /// previous password
225    #[error("cannot use old password")]
226    CannotUseOldPassword,
227    /// Returned when logging in is denied due to an invalid auth code
228    #[error("invalid login auth code")]
229    InvalidLoginAuthCode,
230    /// Returned when logging in fails due to no email being set for 2nd
231    /// factor authentication
232    #[error("no email for 2nd factor authentication")]
233    AccountLogonDeniedNoMail,
234    /// Undocumented
235    #[error("hardware not capable of IPT")]
236    HardwareNotCapableOfIPT,
237    /// Undocumented
238    #[error("IPT init error")]
239    IPTInitError,
240    /// Returned when a operation fails due to parental control restrictions
241    /// for a user
242    #[error("restricted due to parental controls")]
243    ParentalControlRestricted,
244    /// Returned when a facebook query returns an error
245    #[error("facebook query failed")]
246    FacebookQueryError,
247    /// Returned when account login is denied due to an expired auth code
248    #[error("login denied due to exipred auth code")]
249    ExpiredLoginAuthCode,
250    /// Undocumented
251    #[error("IP login restriction failed")]
252    IPLoginRestrictionFailed,
253    /// Undocumented
254    #[error("account locked down")]
255    AccountLockedDown,
256    /// Undocumented
257    #[error("account logon denied verified email required")]
258    AccountLogonDeniedVerifiedEmailRequired,
259    /// Undocumented
260    #[error("no matching URL")]
261    NoMatchingURL,
262    /// Returned when something fails to parse/has a missing field
263    #[error("bad response")]
264    BadResponse,
265    /// Returned when a user cannot complete the action until they
266    /// re-enter their password
267    #[error("password re-entry required")]
268    RequirePasswordReEntry,
269    /// Returned when an entered value is outside the acceptable range
270    #[error("value is out of range")]
271    ValueOutOfRange,
272    /// Returned when an error happens that the steamworks API didn't
273    /// expect to happen
274    #[error("unexpected error")]
275    UnexpectedError,
276    /// Returned when the requested service is disabled
277    #[error("service disabled")]
278    Disabled,
279    /// Returned when the set of files submitted to the CEG server
280    /// are not valid
281    #[error("submitted files to CEG are invalid")]
282    InvalidCEGSubmission,
283    /// Returned when the device being used is not allowed to perform
284    /// this action
285    #[error("device is restricted from action")]
286    RestrictedDevice,
287    /// Returned when an action is prevented due to region restrictions
288    #[error("region restrictions prevented action")]
289    RegionLocked,
290    /// Returned when an action failed due to a temporary rate limit
291    #[error("temporary rate limit exceeded")]
292    RateLimitExceeded,
293    /// Returned when a account needs to use a two-factor code to login
294    #[error("two-factor authetication required for login")]
295    AccountLoginDeniedNeedTwoFactor,
296    /// Returned when the item attempting to be accessed has been deleted
297    #[error("item deleted")]
298    ItemDeleted,
299    /// Returned when the account login failed and you should throttle the
300    /// response to the possible attacker
301    #[error("account login denied, throttled")]
302    AccountLoginDeniedThrottle,
303    /// Returned when the two factor code provided mismatched the expected
304    /// one
305    #[error("two-factor code mismatched")]
306    TwoFactorCodeMismatch,
307    /// Returned when the two factor activation code mismatched the expected
308    /// one
309    #[error("two-factor activation code mismatched")]
310    TwoFactorActivationCodeMismatch,
311    /// Returned when the account has been associated with multiple partners
312    #[error("account associated to multiple partners")]
313    AccountAssociatedToMultiplePartners,
314    /// Returned when the data wasn't modified
315    #[error("data not modified")]
316    NotModified,
317    /// Returned when the account doesn't have a mobile device associated with
318    /// it
319    #[error("no mobile device associated with account")]
320    NoMobileDevice,
321    /// Returned when the current time is out of range or tolerance
322    #[error("time not synced correctly")]
323    TimeNotSynced,
324    /// Returned when the sms code failed to validate
325    #[error("sms code validation failed")]
326    SmsCodeFailed,
327    /// Returned when too many accounts are accessing the requested
328    /// resource
329    #[error("account limit exceeded for resource")]
330    AccountLimitExceeded,
331    /// Returned when there have been too many changes to the account
332    #[error("account activity limit exceeded")]
333    AccountActivityLimitExceeded,
334    /// Returned when there have been too many changes to the phone
335    #[error("phone activity limited exceeded")]
336    PhoneActivityLimitExceeded,
337    /// Returned when the refund can not be sent to the payment method
338    /// and the steam wallet must be used
339    #[error("must refund to wallet instead of payment method")]
340    RefundToWallet,
341    /// Returned when steam failed to send an email
342    #[error("email sending failed")]
343    EmailSendFailure,
344    /// Returned when an action cannot be performed until the payment
345    /// has settled
346    #[error("action cannot be performed until payment has settled")]
347    NotSettled,
348    /// Returned when the user needs to provide a valid captcha
349    #[error("valid captcha required")]
350    NeedCaptcha,
351    /// Returned when the game server login token owned by the token's owner
352    /// been banned
353    #[error("game server login token has been banned")]
354    GSLTDenied,
355    /// Returned when the game server owner has been denied for other reasons
356    /// (account lock, community ban, vac ban, missing phone)
357    #[error("game server owner denied")]
358    GSOwnerDenied,
359    /// Returned when the type of item attempted to be acted on is invalid
360    #[error("invalid item type")]
361    InvalidItemType,
362    /// Returned when the IP address has been banned for taking this action
363    #[error("IP banned from action")]
364    IPBanned,
365    /// Returned when the game server login token has expired
366    ///
367    /// It can be reset for use
368    #[error("game server login token expired")]
369    GSLTExpired,
370    /// Returned when the user does not have the wallet funds to complete
371    /// the action
372    #[error("insufficient wallet funds for action")]
373    InsufficientFunds,
374    /// Returned when there are too many of the requested action pending
375    /// already
376    #[error("too many actions pending")]
377    TooManyPending,
378    /// Returned when there is no site licenses found
379    #[error("no site licenses found")]
380    NoSiteLicensesFound,
381    /// Returned when WG could not send a response because it exceeded the
382    /// max network send size
383    #[error("WG network send size exceeded")]
384    WGNetworkSendExceeded,
385}
386
387impl From<sys::EResult> for SteamError {
388    fn from(r: sys::EResult) -> Self {
389        match r {
390            sys::EResult::k_EResultOK => panic!("EResult::k_EResultOK isn't an error"),
391            sys::EResult::k_EResultFail => SteamError::Generic,
392            sys::EResult::k_EResultNoConnection => SteamError::NoConnection,
393            sys::EResult::k_EResultInvalidPassword => SteamError::InvalidPassword,
394            sys::EResult::k_EResultLoggedInElsewhere => SteamError::LoggedInElsewhere,
395            sys::EResult::k_EResultInvalidProtocolVer => SteamError::InvalidProtocolVersion,
396            sys::EResult::k_EResultInvalidParam => SteamError::InvalidParameter,
397            sys::EResult::k_EResultFileNotFound => SteamError::FileNotFound,
398            sys::EResult::k_EResultBusy => SteamError::Busy,
399            sys::EResult::k_EResultInvalidState => SteamError::InvalidState,
400            sys::EResult::k_EResultInvalidName => SteamError::InvalidName,
401            sys::EResult::k_EResultInvalidEmail => SteamError::InvalidEmail,
402            sys::EResult::k_EResultDuplicateName => SteamError::DuplicateName,
403            sys::EResult::k_EResultAccessDenied => SteamError::AccessDenied,
404            sys::EResult::k_EResultTimeout => SteamError::Timeout,
405            sys::EResult::k_EResultBanned => SteamError::Banned,
406            sys::EResult::k_EResultAccountNotFound => SteamError::AccountNotFound,
407            sys::EResult::k_EResultInvalidSteamID => SteamError::InvalidSteamID,
408            sys::EResult::k_EResultServiceUnavailable => SteamError::ServiceUnavailable,
409            sys::EResult::k_EResultNotLoggedOn => SteamError::NotLoggedOn,
410            sys::EResult::k_EResultPending => SteamError::Pending,
411            sys::EResult::k_EResultEncryptionFailure => SteamError::EncryptionFailure,
412            sys::EResult::k_EResultInsufficientPrivilege => SteamError::InsufficientPrivilege,
413            sys::EResult::k_EResultLimitExceeded => SteamError::LimitExceeded,
414            sys::EResult::k_EResultRevoked => SteamError::Revoked,
415            sys::EResult::k_EResultExpired => SteamError::Expired,
416            sys::EResult::k_EResultAlreadyRedeemed => SteamError::AlreadyRedeemed,
417            sys::EResult::k_EResultDuplicateRequest => SteamError::DuplicateRequest,
418            sys::EResult::k_EResultAlreadyOwned => SteamError::AlreadyOwned,
419            sys::EResult::k_EResultIPNotFound => SteamError::IPNotFound,
420            sys::EResult::k_EResultPersistFailed => SteamError::PersistFailed,
421            sys::EResult::k_EResultLockingFailed => SteamError::LockingFailed,
422            sys::EResult::k_EResultLogonSessionReplaced => SteamError::LogonSessionReplaced,
423            sys::EResult::k_EResultConnectFailed => SteamError::ConnectFailed,
424            sys::EResult::k_EResultHandshakeFailed => SteamError::HandshakeFailed,
425            sys::EResult::k_EResultIOFailure => SteamError::IOFailure,
426            sys::EResult::k_EResultRemoteDisconnect => SteamError::RemoteDisconnect,
427            sys::EResult::k_EResultShoppingCartNotFound => SteamError::ShoppingCartNotFound,
428            sys::EResult::k_EResultBlocked => SteamError::Blocked,
429            sys::EResult::k_EResultIgnored => SteamError::Ignored,
430            sys::EResult::k_EResultNoMatch => SteamError::NoMatch,
431            sys::EResult::k_EResultAccountDisabled => SteamError::AccountDisabled,
432            sys::EResult::k_EResultServiceReadOnly => SteamError::ServiceReadOnly,
433            sys::EResult::k_EResultAccountNotFeatured => SteamError::AccountNotFeatured,
434            sys::EResult::k_EResultAdministratorOK => SteamError::AdministratorOK,
435            sys::EResult::k_EResultContentVersion => SteamError::ContentVersion,
436            sys::EResult::k_EResultTryAnotherCM => SteamError::TryAnotherCM,
437            sys::EResult::k_EResultPasswordRequiredToKickSession => {
438                SteamError::PasswordRequiredToKickSession
439            }
440            sys::EResult::k_EResultAlreadyLoggedInElsewhere => SteamError::AlreadyLoggedInElsewhere,
441            sys::EResult::k_EResultSuspended => SteamError::Suspended,
442            sys::EResult::k_EResultCancelled => SteamError::Cancelled,
443            sys::EResult::k_EResultDataCorruption => SteamError::DataCorruption,
444            sys::EResult::k_EResultDiskFull => SteamError::DiskFull,
445            sys::EResult::k_EResultRemoteCallFailed => SteamError::RemoteCallFailed,
446            sys::EResult::k_EResultPasswordUnset => SteamError::PasswordUnset,
447            sys::EResult::k_EResultExternalAccountUnlinked => SteamError::ExternalAccountUnlinked,
448            sys::EResult::k_EResultPSNTicketInvalid => SteamError::PSNTicketInvalid,
449            sys::EResult::k_EResultExternalAccountAlreadyLinked => {
450                SteamError::ExternalAccountAlreadyLinked
451            }
452            sys::EResult::k_EResultRemoteFileConflict => SteamError::RemoteFileConflict,
453            sys::EResult::k_EResultIllegalPassword => SteamError::IllegalPassword,
454            sys::EResult::k_EResultSameAsPreviousValue => SteamError::SameAsPreviousValue,
455            sys::EResult::k_EResultAccountLogonDenied => SteamError::AccountLogonDenied,
456            sys::EResult::k_EResultCannotUseOldPassword => SteamError::CannotUseOldPassword,
457            sys::EResult::k_EResultInvalidLoginAuthCode => SteamError::InvalidLoginAuthCode,
458            sys::EResult::k_EResultAccountLogonDeniedNoMail => SteamError::AccountLogonDeniedNoMail,
459            sys::EResult::k_EResultHardwareNotCapableOfIPT => SteamError::HardwareNotCapableOfIPT,
460            sys::EResult::k_EResultIPTInitError => SteamError::IPTInitError,
461            sys::EResult::k_EResultParentalControlRestricted => {
462                SteamError::ParentalControlRestricted
463            }
464            sys::EResult::k_EResultFacebookQueryError => SteamError::FacebookQueryError,
465            sys::EResult::k_EResultExpiredLoginAuthCode => SteamError::ExpiredLoginAuthCode,
466            sys::EResult::k_EResultIPLoginRestrictionFailed => SteamError::IPLoginRestrictionFailed,
467            sys::EResult::k_EResultAccountLockedDown => SteamError::AccountLockedDown,
468            sys::EResult::k_EResultAccountLogonDeniedVerifiedEmailRequired => {
469                SteamError::AccountLogonDeniedVerifiedEmailRequired
470            }
471            sys::EResult::k_EResultNoMatchingURL => SteamError::NoMatchingURL,
472            sys::EResult::k_EResultBadResponse => SteamError::BadResponse,
473            sys::EResult::k_EResultRequirePasswordReEntry => SteamError::RequirePasswordReEntry,
474            sys::EResult::k_EResultValueOutOfRange => SteamError::ValueOutOfRange,
475            sys::EResult::k_EResultUnexpectedError => SteamError::UnexpectedError,
476            sys::EResult::k_EResultDisabled => SteamError::Disabled,
477            sys::EResult::k_EResultInvalidCEGSubmission => SteamError::InvalidCEGSubmission,
478            sys::EResult::k_EResultRestrictedDevice => SteamError::RestrictedDevice,
479            sys::EResult::k_EResultRegionLocked => SteamError::RegionLocked,
480            sys::EResult::k_EResultRateLimitExceeded => SteamError::RateLimitExceeded,
481            sys::EResult::k_EResultAccountLoginDeniedNeedTwoFactor => {
482                SteamError::AccountLoginDeniedNeedTwoFactor
483            }
484            sys::EResult::k_EResultItemDeleted => SteamError::ItemDeleted,
485            sys::EResult::k_EResultAccountLoginDeniedThrottle => {
486                SteamError::AccountLoginDeniedThrottle
487            }
488            sys::EResult::k_EResultTwoFactorCodeMismatch => SteamError::TwoFactorCodeMismatch,
489            sys::EResult::k_EResultTwoFactorActivationCodeMismatch => {
490                SteamError::TwoFactorActivationCodeMismatch
491            }
492            sys::EResult::k_EResultAccountAssociatedToMultiplePartners => {
493                SteamError::AccountAssociatedToMultiplePartners
494            }
495            sys::EResult::k_EResultNotModified => SteamError::NotModified,
496            sys::EResult::k_EResultNoMobileDevice => SteamError::NoMobileDevice,
497            sys::EResult::k_EResultTimeNotSynced => SteamError::TimeNotSynced,
498            sys::EResult::k_EResultSmsCodeFailed => SteamError::SmsCodeFailed,
499            sys::EResult::k_EResultAccountLimitExceeded => SteamError::AccountLimitExceeded,
500            sys::EResult::k_EResultAccountActivityLimitExceeded => {
501                SteamError::AccountActivityLimitExceeded
502            }
503            sys::EResult::k_EResultPhoneActivityLimitExceeded => {
504                SteamError::PhoneActivityLimitExceeded
505            }
506            sys::EResult::k_EResultRefundToWallet => SteamError::RefundToWallet,
507            sys::EResult::k_EResultEmailSendFailure => SteamError::EmailSendFailure,
508            sys::EResult::k_EResultNotSettled => SteamError::NotSettled,
509            sys::EResult::k_EResultNeedCaptcha => SteamError::NeedCaptcha,
510            sys::EResult::k_EResultGSLTDenied => SteamError::GSLTDenied,
511            sys::EResult::k_EResultGSOwnerDenied => SteamError::GSOwnerDenied,
512            sys::EResult::k_EResultInvalidItemType => SteamError::InvalidItemType,
513            sys::EResult::k_EResultIPBanned => SteamError::IPBanned,
514            sys::EResult::k_EResultGSLTExpired => SteamError::GSLTExpired,
515            sys::EResult::k_EResultInsufficientFunds => SteamError::InsufficientFunds,
516            sys::EResult::k_EResultTooManyPending => SteamError::TooManyPending,
517            sys::EResult::k_EResultNoSiteLicensesFound => SteamError::NoSiteLicensesFound,
518            sys::EResult::k_EResultWGNetworkSendExceeded => SteamError::WGNetworkSendExceeded,
519            _ => unreachable!(),
520        }
521    }
522}
523
524impl TryFrom<i64> for SteamError {
525    type Error = InvalidErrorCode;
526
527    fn try_from(r: i64) -> Result<Self, Self::Error> {
528        let error = match r {
529            x if x == sys::EResult::k_EResultFail as i64 => SteamError::Generic,
530            x if x == sys::EResult::k_EResultNoConnection as i64 => SteamError::NoConnection,
531            x if x == sys::EResult::k_EResultInvalidPassword as i64 => SteamError::InvalidPassword,
532            x if x == sys::EResult::k_EResultLoggedInElsewhere as i64 => {
533                SteamError::LoggedInElsewhere
534            }
535            x if x == sys::EResult::k_EResultInvalidProtocolVer as i64 => {
536                SteamError::InvalidProtocolVersion
537            }
538            x if x == sys::EResult::k_EResultInvalidParam as i64 => SteamError::InvalidParameter,
539            x if x == sys::EResult::k_EResultFileNotFound as i64 => SteamError::FileNotFound,
540            x if x == sys::EResult::k_EResultBusy as i64 => SteamError::Busy,
541            x if x == sys::EResult::k_EResultInvalidState as i64 => SteamError::InvalidState,
542            x if x == sys::EResult::k_EResultInvalidName as i64 => SteamError::InvalidName,
543            x if x == sys::EResult::k_EResultInvalidEmail as i64 => SteamError::InvalidEmail,
544            x if x == sys::EResult::k_EResultDuplicateName as i64 => SteamError::DuplicateName,
545            x if x == sys::EResult::k_EResultAccessDenied as i64 => SteamError::AccessDenied,
546            x if x == sys::EResult::k_EResultTimeout as i64 => SteamError::Timeout,
547            x if x == sys::EResult::k_EResultBanned as i64 => SteamError::Banned,
548            x if x == sys::EResult::k_EResultAccountNotFound as i64 => SteamError::AccountNotFound,
549            x if x == sys::EResult::k_EResultInvalidSteamID as i64 => SteamError::InvalidSteamID,
550            x if x == sys::EResult::k_EResultServiceUnavailable as i64 => {
551                SteamError::ServiceUnavailable
552            }
553            x if x == sys::EResult::k_EResultNotLoggedOn as i64 => SteamError::NotLoggedOn,
554            x if x == sys::EResult::k_EResultPending as i64 => SteamError::Pending,
555            x if x == sys::EResult::k_EResultEncryptionFailure as i64 => {
556                SteamError::EncryptionFailure
557            }
558            x if x == sys::EResult::k_EResultInsufficientPrivilege as i64 => {
559                SteamError::InsufficientPrivilege
560            }
561            x if x == sys::EResult::k_EResultLimitExceeded as i64 => SteamError::LimitExceeded,
562            x if x == sys::EResult::k_EResultRevoked as i64 => SteamError::Revoked,
563            x if x == sys::EResult::k_EResultExpired as i64 => SteamError::Expired,
564            x if x == sys::EResult::k_EResultAlreadyRedeemed as i64 => SteamError::AlreadyRedeemed,
565            x if x == sys::EResult::k_EResultDuplicateRequest as i64 => {
566                SteamError::DuplicateRequest
567            }
568            x if x == sys::EResult::k_EResultAlreadyOwned as i64 => SteamError::AlreadyOwned,
569            x if x == sys::EResult::k_EResultIPNotFound as i64 => SteamError::IPNotFound,
570            x if x == sys::EResult::k_EResultPersistFailed as i64 => SteamError::PersistFailed,
571            x if x == sys::EResult::k_EResultLockingFailed as i64 => SteamError::LockingFailed,
572            x if x == sys::EResult::k_EResultLogonSessionReplaced as i64 => {
573                SteamError::LogonSessionReplaced
574            }
575            x if x == sys::EResult::k_EResultConnectFailed as i64 => SteamError::ConnectFailed,
576            x if x == sys::EResult::k_EResultHandshakeFailed as i64 => SteamError::HandshakeFailed,
577            x if x == sys::EResult::k_EResultIOFailure as i64 => SteamError::IOFailure,
578            x if x == sys::EResult::k_EResultRemoteDisconnect as i64 => {
579                SteamError::RemoteDisconnect
580            }
581            x if x == sys::EResult::k_EResultShoppingCartNotFound as i64 => {
582                SteamError::ShoppingCartNotFound
583            }
584            x if x == sys::EResult::k_EResultBlocked as i64 => SteamError::Blocked,
585            x if x == sys::EResult::k_EResultIgnored as i64 => SteamError::Ignored,
586            x if x == sys::EResult::k_EResultNoMatch as i64 => SteamError::NoMatch,
587            x if x == sys::EResult::k_EResultAccountDisabled as i64 => SteamError::AccountDisabled,
588            x if x == sys::EResult::k_EResultServiceReadOnly as i64 => SteamError::ServiceReadOnly,
589            x if x == sys::EResult::k_EResultAccountNotFeatured as i64 => {
590                SteamError::AccountNotFeatured
591            }
592            x if x == sys::EResult::k_EResultAdministratorOK as i64 => SteamError::AdministratorOK,
593            x if x == sys::EResult::k_EResultContentVersion as i64 => SteamError::ContentVersion,
594            x if x == sys::EResult::k_EResultTryAnotherCM as i64 => SteamError::TryAnotherCM,
595            x if x == sys::EResult::k_EResultPasswordRequiredToKickSession as i64 => {
596                SteamError::PasswordRequiredToKickSession
597            }
598            x if x == sys::EResult::k_EResultAlreadyLoggedInElsewhere as i64 => {
599                SteamError::AlreadyLoggedInElsewhere
600            }
601            x if x == sys::EResult::k_EResultSuspended as i64 => SteamError::Suspended,
602            x if x == sys::EResult::k_EResultCancelled as i64 => SteamError::Cancelled,
603            x if x == sys::EResult::k_EResultDataCorruption as i64 => SteamError::DataCorruption,
604            x if x == sys::EResult::k_EResultDiskFull as i64 => SteamError::DiskFull,
605            x if x == sys::EResult::k_EResultRemoteCallFailed as i64 => {
606                SteamError::RemoteCallFailed
607            }
608            x if x == sys::EResult::k_EResultPasswordUnset as i64 => SteamError::PasswordUnset,
609            x if x == sys::EResult::k_EResultExternalAccountUnlinked as i64 => {
610                SteamError::ExternalAccountUnlinked
611            }
612            x if x == sys::EResult::k_EResultPSNTicketInvalid as i64 => {
613                SteamError::PSNTicketInvalid
614            }
615            x if x == sys::EResult::k_EResultExternalAccountAlreadyLinked as i64 => {
616                SteamError::ExternalAccountAlreadyLinked
617            }
618            x if x == sys::EResult::k_EResultRemoteFileConflict as i64 => {
619                SteamError::RemoteFileConflict
620            }
621            x if x == sys::EResult::k_EResultIllegalPassword as i64 => SteamError::IllegalPassword,
622            x if x == sys::EResult::k_EResultSameAsPreviousValue as i64 => {
623                SteamError::SameAsPreviousValue
624            }
625            x if x == sys::EResult::k_EResultAccountLogonDenied as i64 => {
626                SteamError::AccountLogonDenied
627            }
628            x if x == sys::EResult::k_EResultCannotUseOldPassword as i64 => {
629                SteamError::CannotUseOldPassword
630            }
631            x if x == sys::EResult::k_EResultInvalidLoginAuthCode as i64 => {
632                SteamError::InvalidLoginAuthCode
633            }
634            x if x == sys::EResult::k_EResultAccountLogonDeniedNoMail as i64 => {
635                SteamError::AccountLogonDeniedNoMail
636            }
637            x if x == sys::EResult::k_EResultHardwareNotCapableOfIPT as i64 => {
638                SteamError::HardwareNotCapableOfIPT
639            }
640            x if x == sys::EResult::k_EResultIPTInitError as i64 => SteamError::IPTInitError,
641            x if x == sys::EResult::k_EResultParentalControlRestricted as i64 => {
642                SteamError::ParentalControlRestricted
643            }
644            x if x == sys::EResult::k_EResultFacebookQueryError as i64 => {
645                SteamError::FacebookQueryError
646            }
647            x if x == sys::EResult::k_EResultExpiredLoginAuthCode as i64 => {
648                SteamError::ExpiredLoginAuthCode
649            }
650            x if x == sys::EResult::k_EResultIPLoginRestrictionFailed as i64 => {
651                SteamError::IPLoginRestrictionFailed
652            }
653            x if x == sys::EResult::k_EResultAccountLockedDown as i64 => {
654                SteamError::AccountLockedDown
655            }
656            x if x == sys::EResult::k_EResultAccountLogonDeniedVerifiedEmailRequired as i64 => {
657                SteamError::AccountLogonDeniedVerifiedEmailRequired
658            }
659            x if x == sys::EResult::k_EResultNoMatchingURL as i64 => SteamError::NoMatchingURL,
660            x if x == sys::EResult::k_EResultBadResponse as i64 => SteamError::BadResponse,
661            x if x == sys::EResult::k_EResultRequirePasswordReEntry as i64 => {
662                SteamError::RequirePasswordReEntry
663            }
664            x if x == sys::EResult::k_EResultValueOutOfRange as i64 => SteamError::ValueOutOfRange,
665            x if x == sys::EResult::k_EResultUnexpectedError as i64 => SteamError::UnexpectedError,
666            x if x == sys::EResult::k_EResultDisabled as i64 => SteamError::Disabled,
667            x if x == sys::EResult::k_EResultInvalidCEGSubmission as i64 => {
668                SteamError::InvalidCEGSubmission
669            }
670            x if x == sys::EResult::k_EResultRestrictedDevice as i64 => {
671                SteamError::RestrictedDevice
672            }
673            x if x == sys::EResult::k_EResultRegionLocked as i64 => SteamError::RegionLocked,
674            x if x == sys::EResult::k_EResultRateLimitExceeded as i64 => {
675                SteamError::RateLimitExceeded
676            }
677            x if x == sys::EResult::k_EResultAccountLoginDeniedNeedTwoFactor as i64 => {
678                SteamError::AccountLoginDeniedNeedTwoFactor
679            }
680            x if x == sys::EResult::k_EResultItemDeleted as i64 => SteamError::ItemDeleted,
681            x if x == sys::EResult::k_EResultAccountLoginDeniedThrottle as i64 => {
682                SteamError::AccountLoginDeniedThrottle
683            }
684            x if x == sys::EResult::k_EResultTwoFactorCodeMismatch as i64 => {
685                SteamError::TwoFactorCodeMismatch
686            }
687            x if x == sys::EResult::k_EResultTwoFactorActivationCodeMismatch as i64 => {
688                SteamError::TwoFactorActivationCodeMismatch
689            }
690            x if x == sys::EResult::k_EResultAccountAssociatedToMultiplePartners as i64 => {
691                SteamError::AccountAssociatedToMultiplePartners
692            }
693            x if x == sys::EResult::k_EResultNotModified as i64 => SteamError::NotModified,
694            x if x == sys::EResult::k_EResultNoMobileDevice as i64 => SteamError::NoMobileDevice,
695            x if x == sys::EResult::k_EResultTimeNotSynced as i64 => SteamError::TimeNotSynced,
696            x if x == sys::EResult::k_EResultSmsCodeFailed as i64 => SteamError::SmsCodeFailed,
697            x if x == sys::EResult::k_EResultAccountLimitExceeded as i64 => {
698                SteamError::AccountLimitExceeded
699            }
700            x if x == sys::EResult::k_EResultAccountActivityLimitExceeded as i64 => {
701                SteamError::AccountActivityLimitExceeded
702            }
703            x if x == sys::EResult::k_EResultPhoneActivityLimitExceeded as i64 => {
704                SteamError::PhoneActivityLimitExceeded
705            }
706            x if x == sys::EResult::k_EResultRefundToWallet as i64 => SteamError::RefundToWallet,
707            x if x == sys::EResult::k_EResultEmailSendFailure as i64 => {
708                SteamError::EmailSendFailure
709            }
710            x if x == sys::EResult::k_EResultNotSettled as i64 => SteamError::NotSettled,
711            x if x == sys::EResult::k_EResultNeedCaptcha as i64 => SteamError::NeedCaptcha,
712            x if x == sys::EResult::k_EResultGSLTDenied as i64 => SteamError::GSLTDenied,
713            x if x == sys::EResult::k_EResultGSOwnerDenied as i64 => SteamError::GSOwnerDenied,
714            x if x == sys::EResult::k_EResultInvalidItemType as i64 => SteamError::InvalidItemType,
715            x if x == sys::EResult::k_EResultIPBanned as i64 => SteamError::IPBanned,
716            x if x == sys::EResult::k_EResultGSLTExpired as i64 => SteamError::GSLTExpired,
717            x if x == sys::EResult::k_EResultInsufficientFunds as i64 => {
718                SteamError::InsufficientFunds
719            }
720            x if x == sys::EResult::k_EResultTooManyPending as i64 => SteamError::TooManyPending,
721            x if x == sys::EResult::k_EResultNoSiteLicensesFound as i64 => {
722                SteamError::NoSiteLicensesFound
723            }
724            x if x == sys::EResult::k_EResultWGNetworkSendExceeded as i64 => {
725                SteamError::WGNetworkSendExceeded
726            }
727            _ => return Err(InvalidErrorCode),
728        };
729        Ok(error)
730    }
731}
732
733#[derive(Debug, Error)]
734#[error("error code could not be converted to rust enum")]
735pub struct InvalidErrorCode;
736
737#[derive(Clone, Debug, Error, PartialEq, Eq)]
738#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
739pub enum SteamAPIInitError {
740    #[error("Some other failure")]
741    FailedGeneric(String),
742
743    #[error("We cannot connect to Steam, steam probably isn't running")]
744    NoSteamClient(String),
745
746    #[error("Steam client appears to be out of date")]
747    VersionMismatch(String),
748}
749
750impl SteamAPIInitError {
751    pub fn from_result_and_message(
752        result: sys::ESteamAPIInitResult,
753        message: sys::SteamErrMsg,
754    ) -> Self {
755        let err_string = unsafe {
756            let cstr = CStr::from_ptr(message.as_ptr());
757            cstr.to_string_lossy().to_owned().into_owned()
758        };
759
760        match result {
761            sys::ESteamAPIInitResult::k_ESteamAPIInitResult_FailedGeneric => {
762                SteamAPIInitError::FailedGeneric(err_string)
763            }
764            sys::ESteamAPIInitResult::k_ESteamAPIInitResult_NoSteamClient => {
765                SteamAPIInitError::NoSteamClient(err_string)
766            }
767            sys::ESteamAPIInitResult::k_ESteamAPIInitResult_VersionMismatch => {
768                SteamAPIInitError::VersionMismatch(err_string)
769            }
770            _ => unreachable!(),
771        }
772    }
773}