Fix two diagnostic bugs in validate-modern.py (#40418)

* Fix two bugs in validate-modern.py 1. Line 394: f-string missing braces around info.size - was printing the literal text '(info.size)' instead of the actual file size value. Fix: Change (info.size) to ({info.size}). 2. Line 414: validate_config reassigned its 'path' parameter to the resolved tar member path, then printed the (now-None) path in the not-found error. Renamed the local to 'real_path' so the error message references the original input path the caller asked for. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address PR feedback: use original config path in diagnostic messages The unexpected_keys error and 'Found valid keys' log were still using the resolved tar member path instead of the caller-supplied config path, so symlinked configs (e.g. /etc/wsl.conf -> /etc/wsl.conf.real) would still report the symlink target rather than the user-facing config name. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Ben Hillis committed May 7, 2026 at 16:14 UTC 4e547dab1eda2d6d4be5a0a7fe70858d0a8f4975
1 file changed +5 -5
distributions/validate-modern.py
+5 -5
@@ -391,7 +391,7 @@ def read_tar(node, file, elf_magic: str):
391 warning(node, f'file: "{path}" has unexpected gid: {info.gid} (expected: {gid})')
392
393 if max_size is not None and info.size > max_size:
394 - error(node, f'file: "{path}" is too big (info.size), max: {max_size}')
394 + error(node, f'file: "{path}" is too big ({info.size}), max: {max_size}')
395
396 if magic is not None or parse_method is not None:
397 content = tar.extractfile(real_path)
@@ -409,12 +409,12 @@ def read_tar(node, file, elf_magic: str):
409 return True
410
411 def validate_config(path: str, valid_keys: list):
412 - _, path = get_tar_file(tar, path, follow_symlink=True)
413 - if path is None:
414 - error(node, f'File "{file}" not found in tar')
412 + _, real_path = get_tar_file(tar, path, follow_symlink=True)
413 + if real_path is None:
414 + error(node, f'File "{path}" not found in tar')
415 return None
416
417 - content = tar.extractfile(path)
417 + content = tar.extractfile(real_path)
418 config = configparser.ConfigParser()
419 config.read_string(content.read().decode())
420