Skip to content

Commit 63e9758

Browse files
committed
fix: handle network errors gracefully in token count estimation
1 parent 6de8860 commit 63e9758

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/gitingest/output_formatter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
from __future__ import annotations
44

5+
import ssl
56
from typing import TYPE_CHECKING
67

8+
import requests.exceptions
79
import tiktoken
810

911
from gitingest.schemas import FileSystemNode, FileSystemNodeType
@@ -189,6 +191,9 @@ def _format_token_count(text: str) -> str | None:
189191
except (ValueError, UnicodeEncodeError) as exc:
190192
print(exc)
191193
return None
194+
except (requests.exceptions.RequestException, ssl.SSLError):
195+
# If network errors, silently skip token count estimation instead of erroring out
196+
return None
192197

193198
for threshold, suffix in _TOKEN_THRESHOLDS:
194199
if total_tokens >= threshold:

0 commit comments

Comments
 (0)