Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit b80defe

Browse files
authored
Merge pull request #35 from DarkCat09/darkcat09-patch1
Errors, bedrock whitelist bug
2 parents 7f77478 + c4c5c83 commit b80defe

File tree

5 files changed

+55
-70
lines changed

5 files changed

+55
-70
lines changed

python_aternos/__init__.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
from .aterrors import CredentialsError
2222
from .aterrors import TokenError
2323
from .aterrors import ServerError
24-
from .aterrors import ServerEulaError
25-
from .aterrors import ServerRunningError
26-
from .aterrors import ServerSoftwareError
27-
from .aterrors import ServerStorageError
24+
from .aterrors import ServerStartError
2825
from .aterrors import FileError
2926
from .aterrors import PermissionError
3027
from .atjsparse import exec, atob
@@ -41,8 +38,8 @@
4138
'PlayersList', 'AternosConfig', 'AternosWss',
4239
'FileManager', 'AternosFile', 'AternosError',
4340
'CloudflareError', 'CredentialsError', 'TokenError',
44-
'ServerError', 'ServerEulaError', 'ServerRunningError',
45-
'ServerSoftwareError', 'ServerStorageError', 'FileError',
41+
'ServerError', 'ServerStartError', 'FileError',
42+
'PermissionError',
4643
'exec', 'atob', 'to_ecma5_function',
4744

4845
'Edition', 'Status', 'Lists',

python_aternos/atconnect.py

+2
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,6 @@ def request_cloudflare(
249249
f'{method} completed with {req.status_code} status'
250250
)
251251

252+
req.raise_for_status()
253+
252254
return req

python_aternos/aterrors.py

+42-16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import Final
2+
3+
14
class AternosError(Exception):
25

36
"""Common error class"""
@@ -23,39 +26,62 @@ class TokenError(AternosError):
2326

2427
class ServerError(AternosError):
2528

26-
"""Common class for server errors"""
29+
"""Common class for server errors
30+
31+
:param reason: Code which contains error reason
32+
:type reason: str
33+
:param message: Error message, defaults to ''
34+
:type message: str, optional
35+
"""
2736

37+
def __init__(self, reason: str, message: str = '') -> None:
2838

29-
class ServerEulaError(ServerError):
39+
self.reason = reason
40+
super().__init__(message)
3041

31-
"""Raised when trying to start without
32-
confirming Mojang EULA"""
3342

43+
class ServerStartError(AternosError):
3444

35-
class ServerRunningError(ServerError):
45+
"""Raised when Aternos can not start Minecraft server
3646
37-
"""Raised when trying to start
38-
already running server"""
47+
:param reason: Code which contains error reason
48+
:type reason: str
49+
"""
3950

51+
MESSAGE: Final = 'Unable to start server, code: {}'
52+
reason_msg = {
4053

41-
class ServerSoftwareError(ServerError):
54+
'eula':
55+
'EULA was not accepted. '
56+
'Use start(accepteula=True)',
4257

43-
"""Raised when Aternos notifies about
44-
incorrect software version"""
58+
'already': 'Server is already running',
59+
'wrongversion': 'Incorrect software version installed',
4560

61+
'file':
62+
'File server is unavailbale, '
63+
'view https://status.aternos.gmbh',
4664

47-
class ServerStorageError(ServerError):
65+
'size': 'Available storage size limit (4 GB) was reached'
66+
}
4867

49-
"""Raised when Aternos notifies about
50-
violation of storage limits (4 GB for now)"""
68+
def __init__(self, reason: str) -> None:
69+
70+
super().__init__(
71+
reason,
72+
self.reason_msg.get(
73+
reason, self.MESSAGE.format(reason)
74+
)
75+
)
5176

5277

5378
class FileError(AternosError):
5479

5580
"""Raised when trying to execute a disallowed
5681
by Aternos file operation"""
5782

58-
83+
5984
class PermissionError(AternosError):
60-
"""Raised when trying to execute a non-allowed
61-
command on a server (Think friends permissions)"""
85+
86+
"""Raised when trying to execute a disallowed command,
87+
usually because of shared access rights"""

python_aternos/atplayers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, lst: Union[str, Lists], atserv: 'AternosServer') -> None:
3535

3636
self.atserv = atserv
3737
self.lst = Lists(lst)
38-
38+
3939
common_whl = (self.lst == Lists.whl)
4040
bedrock = (atserv.edition == Edition.bedrock)
4141
if common_whl and bedrock:

python_aternos/atserver.py

+7-47
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
from typing import Optional, List
55

66
from .atconnect import AternosConnect
7-
from .aterrors import ServerError
8-
from .aterrors import ServerEulaError
9-
from .aterrors import ServerRunningError
10-
from .aterrors import ServerSoftwareError
11-
from .aterrors import ServerStorageError
7+
from .aterrors import ServerStartError
128
from .atfm import FileManager
139
from .atconf import AternosConfig
1410
from .atplayers import PlayersList
@@ -99,16 +95,8 @@ def start(self, headstart: bool = False, accepteula: bool = True) -> None:
9995
:param accepteula: Automatically accept
10096
the Mojang EULA, defaults to `True`
10197
:type accepteula: bool, optional
102-
:raises ServerEulaError: When trying to start a server
103-
without accepting the Mojang EULA
104-
:raises ServerRunningError: When trying to start a server
105-
which is alreday running
106-
:raises ServerSoftwareError: When Aternos notifies about
107-
incorrect software version
108-
:raises ServerStorageError: When Aternos notifies about
109-
voilation of storage limits (4 GB for now)
110-
:raises ServerError: When API is unable to start a Minecraft server
111-
due to unavailability of Aternos' file servers or other problems
98+
:raises ServerStartError: When Aternos
99+
is unable to start the server
112100
"""
113101

114102
startreq = self.atserver_request(
@@ -120,42 +108,14 @@ def start(self, headstart: bool = False, accepteula: bool = True) -> None:
120108

121109
if startresult['success']:
122110
return
111+
123112
error = startresult['error']
124113

125114
if error == 'eula' and accepteula:
126115
self.eula()
127-
self.start(accepteula=False)
128-
129-
elif error == 'eula':
130-
raise ServerEulaError(
131-
'EULA was not accepted. Use start(accepteula=True)'
132-
)
133-
134-
elif error == 'already':
135-
raise ServerRunningError(
136-
'Server is already running'
137-
)
138-
139-
elif error == 'wrongversion':
140-
raise ServerSoftwareError(
141-
'Incorrect software version installed'
142-
)
143-
144-
elif error == 'file':
145-
raise ServerError(
146-
'File server is unavailbale, view https://status.aternos.gmbh'
147-
)
148-
149-
elif error == 'size':
150-
raise ServerStorageError(
151-
f'Available storage size is 4GB, '
152-
f'your server used: {startresult["size"]}'
153-
)
154-
155-
else:
156-
raise ServerError(
157-
f'Unable to start server, code: {error}'
158-
)
116+
return self.start(accepteula=False)
117+
118+
raise ServerStartError(error)
159119

160120
def confirm(self) -> None:
161121

0 commit comments

Comments
 (0)