2525from wcwidth import wcswidth
2626from pyfiglet import figlet_format
2727
28- from nb_cli import cache
28+ from nb_cli import _ , cache
2929from nb_cli .config .model import NoneBotConfig
3030from nb_cli .consts import WINDOWS , REQUIRES_PYTHON
3131from nb_cli .config import GLOBAL_CONFIG , Driver , Plugin , Adapter , NoneBotConfig
3232from nb_cli .exceptions import (
3333 ModuleLoadFailed ,
34- PythonVersionError ,
3534 PipNotInstalledError ,
35+ PythonInterpreterError ,
3636 NoneBotNotInstalledError ,
3737)
3838
@@ -68,6 +68,8 @@ async def get_default_python() -> str:
6868 stdout = asyncio .subprocess .PIPE ,
6969 )
7070 stdout , _ = await proc .communicate ()
71+ if proc .returncode != 0 :
72+ raise PythonInterpreterError (_ ("Cannot find a valid Python interpreter." ))
7173 return json .loads (stdout .strip ())
7274
7375
@@ -107,8 +109,10 @@ async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
107109 if (version ["major" ], version ["minor" ]) >= REQUIRES_PYTHON :
108110 return await func (* args , ** kwargs )
109111
110- raise PythonVersionError (
111- f"Python { version ['major' ]} .{ version ['minor' ]} is not supported."
112+ raise PythonInterpreterError (
113+ _ ("Python {major}.{minor} is not supported." ).format (
114+ marjo = version ["major" ], minor = version ["minor" ]
115+ )
112116 )
113117
114118 return wrapper
@@ -148,7 +152,7 @@ async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
148152 if await get_nonebot_version (cast (Union [str , None ], kwargs .get ("python_path" ))):
149153 return await func (* args , ** kwargs )
150154
151- raise NoneBotNotInstalledError ("NoneBot is not installed." )
155+ raise NoneBotNotInstalledError (_ ( "NoneBot is not installed." ) )
152156
153157 return wrapper
154158
@@ -187,7 +191,7 @@ async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
187191 if await get_pip_version (cast (Union [str , None ], kwargs .get ("python_path" ))):
188192 return await func (* args , ** kwargs )
189193
190- raise PipNotInstalledError ("pip is not installed." )
194+ raise PipNotInstalledError (_ ( "pip is not installed." ) )
191195
192196 return wrapper
193197
@@ -224,7 +228,9 @@ async def load_module_data(
224228 elif module_type == "driver" :
225229 module_class = Driver
226230 else :
227- raise ValueError (f"Invalid module type: { module_type } " )
231+ raise ValueError (
232+ _ ("Invalid module type: {module_type}" ).format (module_type = module_type )
233+ )
228234 module_name : str = getattr (module_class .__config__ , "module_name" )
229235
230236 exceptions : List [Exception ] = []
@@ -244,7 +250,10 @@ async def load_module_data(
244250 except Exception as e :
245251 exceptions .append (e )
246252
247- raise ModuleLoadFailed (f"Failed to get { module_name } list." , exceptions )
253+ raise ModuleLoadFailed (
254+ _ ("Failed to get {module_type} list." ).format (module_type = module_type ),
255+ exceptions ,
256+ )
248257
249258
250259def format_package_results (
0 commit comments