Marco Ricci commited on 2024-12-31 22:18:29
Zeige 4 geänderte Dateien mit 54 Einfügungen und 15 Löschungen.
Apparently, we overlooked this in 59d73c8320650a6bcb77eed759c694949d350cdb.
... | ... |
@@ -939,6 +939,18 @@ class ErrMsgTemplate(enum.Enum): |
939 | 939 |
context='error message', |
940 | 940 |
flags='python-brace-format', |
941 | 941 |
) |
942 |
+ CANNOT_PARSE_AS_VAULT_CONFIG_OSERROR = _prepare_translatable( |
|
943 |
+ comments=r""" |
|
944 |
+ TRANSLATORS: "error" is supplied by the operating system |
|
945 |
+ (errno/strerror). |
|
946 |
+ """, |
|
947 |
+ msg=r""" |
|
948 |
+ Cannot parse {path!r} as a valid vault-native configuration |
|
949 |
+ file/directory: {error!s}: {filename!r}. |
|
950 |
+ """, |
|
951 |
+ context='error message', |
|
952 |
+ flags='python-brace-format', |
|
953 |
+ ) |
|
942 | 954 |
CANNOT_STORE_VAULT_SETTINGS = _prepare_translatable( |
943 | 955 |
comments=r""" |
944 | 956 |
TRANSLATORS: "error" is supplied by the operating system |
... | ... |
@@ -1329,32 +1329,56 @@ def derivepassphrase_export_vault( |
1329 | 1329 |
ValueError, |
1330 | 1330 |
RuntimeError, |
1331 | 1331 |
): |
1332 |
- logger.info('Cannot load as %s: %s', fmt, path) |
|
1332 |
+ logger.info( |
|
1333 |
+ _msg.TranslatedString( |
|
1334 |
+ _msg.InfoMsgTemplate.CANNOT_LOAD_AS_VAULT_CONFIG, |
|
1335 |
+ path=path, |
|
1336 |
+ fmt=fmt, |
|
1337 |
+ ), |
|
1338 |
+ ) |
|
1333 | 1339 |
continue |
1334 | 1340 |
except OSError as exc: |
1335 | 1341 |
logger.error( |
1336 |
- 'Cannot parse %r as a valid config: %s: %r', |
|
1337 |
- path, |
|
1338 |
- exc.strerror, |
|
1339 |
- exc.filename, |
|
1342 |
+ _msg.TranslatedString( |
|
1343 |
+ _msg.ErrMsgTemplate.CANNOT_PARSE_AS_VAULT_CONFIG_OSERROR, |
|
1344 |
+ path=path, |
|
1345 |
+ error=exc.strerror, |
|
1346 |
+ filename=exc.filename, |
|
1347 |
+ ).maybe_without_filename(), |
|
1340 | 1348 |
) |
1341 | 1349 |
ctx.exit(1) |
1342 | 1350 |
except ModuleNotFoundError: |
1343 |
- # TODO(the-13th-letter): Use backslash continuation. |
|
1344 |
- # https://github.com/nedbat/coveragepy/issues/1836 |
|
1345 | 1351 |
logger.error( |
1346 |
- 'Cannot load the required Python module "cryptography".' |
|
1352 |
+ _msg.TranslatedString( |
|
1353 |
+ _msg.ErrMsgTemplate.MISSING_MODULE, |
|
1354 |
+ module='cryptography', |
|
1355 |
+ ), |
|
1356 |
+ ) |
|
1357 |
+ logger.info( |
|
1358 |
+ _msg.TranslatedString( |
|
1359 |
+ _msg.InfoMsgTemplate.PIP_INSTALL_EXTRA, |
|
1360 |
+ extra_name='export', |
|
1361 |
+ ), |
|
1347 | 1362 |
) |
1348 |
- logger.info('pip users: see the "export" extra.') |
|
1349 | 1363 |
ctx.exit(1) |
1350 | 1364 |
else: |
1351 | 1365 |
if not _types.is_vault_config(config): |
1352 |
- logger.error('Invalid vault config: %r', config) |
|
1366 |
+ logger.error( |
|
1367 |
+ _msg.TranslatedString( |
|
1368 |
+ _msg.ErrMsgTemplate.INVALID_VAULT_CONFIG, |
|
1369 |
+ config=config, |
|
1370 |
+ ), |
|
1371 |
+ ) |
|
1353 | 1372 |
ctx.exit(1) |
1354 | 1373 |
click.echo(json.dumps(config, indent=2, sort_keys=True)) |
1355 | 1374 |
break |
1356 | 1375 |
else: |
1357 |
- logger.error('Cannot parse %r as a valid config.', path) |
|
1376 |
+ logger.error( |
|
1377 |
+ _msg.TranslatedString( |
|
1378 |
+ _msg.ErrMsgTemplate.CANNOT_PARSE_AS_VAULT_CONFIG, |
|
1379 |
+ path=path, |
|
1380 |
+ ).maybe_without_filename(), |
|
1381 |
+ ) |
|
1358 | 1382 |
ctx.exit(1) |
1359 | 1383 |
|
1360 | 1384 |
|
... | ... |
@@ -1311,7 +1311,7 @@ AAAAAAAAAKSBiwUAADFkUEsFBgAAAAAEAAQAwwAAAMIHAAAAAA== |
1311 | 1311 |
""" |
1312 | 1312 |
|
1313 | 1313 |
CANNOT_LOAD_CRYPTOGRAPHY = ( |
1314 |
- 'Cannot load the required Python module "cryptography".' |
|
1314 |
+ "Cannot load the required Python module 'cryptography'." |
|
1315 | 1315 |
) |
1316 | 1316 |
|
1317 | 1317 |
skip_if_cryptography_support = pytest.mark.skipif( |
... | ... |
@@ -134,7 +134,10 @@ class TestCLI: |
134 | 134 |
) |
135 | 135 |
result = tests.ReadableResult.parse(_result) |
136 | 136 |
assert result.error_exit( |
137 |
- error="Cannot parse 'does-not-exist.txt' as a valid config", |
|
137 |
+ error=( |
|
138 |
+ "Cannot parse 'does-not-exist.txt' " |
|
139 |
+ "as a valid vault-native config" |
|
140 |
+ ), |
|
138 | 141 |
record_tuples=caplog.record_tuples, |
139 | 142 |
), 'expected error exit and known error message' |
140 | 143 |
assert tests.CANNOT_LOAD_CRYPTOGRAPHY not in result.stderr |
... | ... |
@@ -157,7 +160,7 @@ class TestCLI: |
157 | 160 |
) |
158 | 161 |
result = tests.ReadableResult.parse(_result) |
159 | 162 |
assert result.error_exit( |
160 |
- error="Cannot parse '.vault' as a valid config", |
|
163 |
+ error="Cannot parse '.vault' as a valid vault-native config", |
|
161 | 164 |
record_tuples=caplog.record_tuples, |
162 | 165 |
), 'expected error exit and known error message' |
163 | 166 |
assert tests.CANNOT_LOAD_CRYPTOGRAPHY not in result.stderr |
... | ... |
@@ -180,7 +183,7 @@ class TestCLI: |
180 | 183 |
) |
181 | 184 |
result = tests.ReadableResult.parse(_result) |
182 | 185 |
assert result.error_exit( |
183 |
- error="Cannot parse '.vault' as a valid config", |
|
186 |
+ error="Cannot parse '.vault' as a valid vault-native config", |
|
184 | 187 |
record_tuples=caplog.record_tuples, |
185 | 188 |
), 'expected error exit and known error message' |
186 | 189 |
assert tests.CANNOT_LOAD_CRYPTOGRAPHY not in result.stderr |
187 | 190 |