[Enhance] Ehance error message thrown by Config (#1270)

pull/1290/head
Mashiro 2023-07-28 10:09:47 +08:00 committed by GitHub
parent 42fdbc2ddb
commit e56d6edf19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -910,7 +910,7 @@ class Config:
parsed_codes = ast.parse(f.read())
parsed_codes = RemoveAssignFromAST(BASE_KEY).visit(
parsed_codes)
codeobj = compile(parsed_codes, '', mode='exec')
codeobj = compile(parsed_codes, filename, mode='exec')
# Support load global variable in nested function of the
# config.
global_locals_var = {BASE_KEY: base_cfg_dict}
@ -1228,8 +1228,9 @@ class Config:
cfg_dict = mmengine.load(filename)
base_files = cfg_dict.get(BASE_KEY, [])
else:
raise TypeError('The config type should be py, json, yaml or '
f'yml, but got {file_format}')
raise ConfigParsingError(
'The config type should be py, json, yaml or '
f'yml, but got {file_format}')
base_files = base_files if isinstance(base_files,
list) else [base_files]
return base_files