mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-09 06:05:00 +00:00
Add some defensive coding to ChangeTracker
This commit is contained in:
parent
8e964bf6e2
commit
46b0bee184
1 changed files with 23 additions and 8 deletions
|
@ -30,10 +30,24 @@ class ChangeTracker:
|
||||||
- change_id: Unique identifier for the change
|
- change_id: Unique identifier for the change
|
||||||
"""
|
"""
|
||||||
if change_id is None:
|
if change_id is None:
|
||||||
change_id = self._generate_change_id()
|
generated_id = self._generate_change_id()
|
||||||
|
# Ensure the generated ID is treated as a string
|
||||||
|
current_change_id = str(generated_id)
|
||||||
|
else:
|
||||||
|
# If an ID is provided, ensure it's treated as a string key/value
|
||||||
|
current_change_id = str(change_id)
|
||||||
|
|
||||||
|
# Defensive check: Ensure the ID isn't literally the string 'False' or boolean False
|
||||||
|
# which might indicate an upstream issue or unexpected input.
|
||||||
|
if current_change_id == 'False' or current_change_id is False:
|
||||||
|
# Log a warning? For now, generate a new ID to prevent storing False.
|
||||||
|
print(f"Warning: change_id evaluated to False for {file_path}. Generating new ID.")
|
||||||
|
current_change_id = self._generate_change_id()
|
||||||
|
|
||||||
|
|
||||||
change = {
|
change = {
|
||||||
'id': change_id,
|
# Use the confirmed string ID here
|
||||||
|
'id': current_change_id,
|
||||||
'file_path': file_path,
|
'file_path': file_path,
|
||||||
'type': change_type,
|
'type': change_type,
|
||||||
'original': original_content,
|
'original': original_content,
|
||||||
|
@ -42,9 +56,10 @@ class ChangeTracker:
|
||||||
'timestamp': time.time()
|
'timestamp': time.time()
|
||||||
}
|
}
|
||||||
|
|
||||||
self.changes[change_id] = change
|
# Use the confirmed string ID for storage and return
|
||||||
self.files_changed[file_path].append(change_id)
|
self.changes[current_change_id] = change
|
||||||
return change_id
|
self.files_changed[file_path].append(current_change_id)
|
||||||
|
return current_change_id
|
||||||
|
|
||||||
def undo_change(self, change_id):
|
def undo_change(self, change_id):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue