-
Notifications
You must be signed in to change notification settings - Fork 18
Description
When using AppMap for Python on Windows, an OSError occurs during the file-renaming process. This is because the ISO 8601 formatted timestamp, which includes colons (:), is directly used in the AppMap filename. The colon character is forbidden in Windows filenames, causing the operation to fail.
Reproduction
The issue can be reproduced by running the appmap-python command on Windows. The specific paths and filenames will vary, but the error remains the same.
appmap-python --record process C:\path\to\your\project\.venv\Scripts\python.exe C:\path\to\your\project\main.py
The command fails with the following traceback:
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\\path\\to\\your\\project\\tmp\\appmap\\process\\tmp_some_string' -> 'C:\\path\\to\\your\\project\\tmp\\appmap\\process\\2024-01-20T10:30:00Z_12345.appmap.json'
Cause
The problem lies on line 120 of recording.py, where the appmap_name variable is constructed using an iso_time string. The standard ISO 8601 format includes a colon (:) to separate hours, minutes, and seconds (e.g., 10:30:00Z), which is not a valid character for filenames in the Windows file system.
The code snippet from recording.py is:
appmap_name = f"{iso_time}_{process_id}"Suggested Fix
To fix this, the ISO 8601 timestamp must be sanitized to remove or replace the colons before being used in the filename. A simple solution would be to use the .replace() method as a temporary workaround:
# Before
appmap_name = f"{iso_time}_{process_id}"
# After (Proposed Fix)
appmap_name = f"{iso_time.replace(':', '')}_{process_id}"