Skip to content

Commit 3cb043d

Browse files
fix: add encoding='utf-8' to all file operations to prevent UnicodeEncodeError
1 parent d25122b commit 3cb043d

9 files changed

Lines changed: 14 additions & 9 deletions

File tree

.cursorrules

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Instead of `Optional` use `| None`
99
- Create a `__init__.py` file in each folder
1010
- Never pass literals, e.g., `error_msg`, directly to `Exceptions`, but instead assign them to variables and pass them to the exception, e.g., `raise FileNotFoundError(error_msg)` instead of `raise FileNotFoundError(f"Thread {thread_id} not found")`
11+
- Always specify `encoding="utf-8"` for all file read and write operations (e.g., `Path.read_text()`, `Path.write_text()`, `open()`, etc.) to ensure proper handling of Unicode characters across all platforms
1112

1213
## FastAPI
1314
- Instead of defining `response_model` within route annotation, use the model as the response type in the function signature
@@ -16,6 +17,10 @@
1617
# Testing
1718
- Use `pytest-mock` for mocking in tests wherever you need to mock something and pytest-mock can do the job.
1819

20+
# Git
21+
- Never use `git add .` - always explicitly add files that are related to the task using `git add <file1> <file2> ...`
22+
- Use conventional commits format for commit messages (e.g., `feat:`, `fix:`, `docs:`, `style:`, `refactor:`, `test:`, `chore:`)
23+
1924
# Documentation
2025

2126
## Docstrings

src/askui/chat/api/workflows/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def retrieve(
7070
) -> Workflow:
7171
try:
7272
workflow_path = self._get_workflow_path(workflow_id)
73-
workflow = Workflow.model_validate_json(workflow_path.read_text())
73+
workflow = Workflow.model_validate_json(workflow_path.read_text(encoding="utf-8"))
7474

7575
# Check workspace access
7676
if workspace_id is not None and workflow.workspace_id != workspace_id:

src/askui/models/askui/ai_element_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def from_json_file(cls, json_file_path: pathlib.Path) -> "AiElement":
6464
image=Image.open(image_path),
6565
image_path=image_path,
6666
json_path=json_file_path,
67-
metadata=json.loads(json_file_path.read_text()),
67+
metadata=json.loads(json_file_path.read_text(encoding="utf-8")),
6868
)
6969

7070

src/askui/reporting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ def generate(self) -> None:
736736
f"{random.randint(0, 1000):03}.html"
737737
)
738738
self.report_dir.mkdir(parents=True, exist_ok=True)
739-
report_path.write_text(html)
739+
report_path.write_text(html, encoding="utf-8")
740740

741741

742742
class AllureReporter(Reporter):

src/askui/telemetry/anonymous_id.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def _read_anonymous_id_from_file() -> str | None:
1515
"""Read anonymous ID from file if it exists."""
1616
try:
1717
if _ANONYMOUS_ID_FILE_PATH.exists():
18-
return _ANONYMOUS_ID_FILE_PATH.read_text().strip()
18+
return _ANONYMOUS_ID_FILE_PATH.read_text(encoding="utf-8").strip()
1919
except OSError as e:
2020
logger.warning("Failed to read anonymous ID from file", extra={"error": str(e)})
2121
return None
@@ -25,7 +25,7 @@ def _write_anonymous_id_to_file(anonymous_id: str) -> bool:
2525
"""Write anonymous ID to file, creating directories if needed."""
2626
try:
2727
_ANONYMOUS_ID_FILE_PATH.parent.mkdir(parents=True, exist_ok=True)
28-
_ANONYMOUS_ID_FILE_PATH.write_text(anonymous_id)
28+
_ANONYMOUS_ID_FILE_PATH.write_text(anonymous_id, encoding="utf-8")
2929
except OSError as e:
3030
logger.warning("Failed to write anonymous ID to file", extra={"error": str(e)})
3131
else:

src/askui/tools/askui/askui_controller_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def _find_remote_device_controller_by_component_registry_file(
164164
return None
165165

166166
component_registry = AskUiComponentRegistry.model_validate_json(
167-
self.component_registry_file.read_text()
167+
self.component_registry_file.read_text(encoding="utf-8")
168168
)
169169
return (
170170
component_registry.installed_packages.remote_device_controller_uuid.executables.askui_remote_device_controller # noqa: E501

src/askui/tools/testing/execution_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def list_(self, query: ExecutionListQuery) -> ListResponse[Execution]:
5959
def retrieve(self, execution_id: ExecutionId) -> Execution:
6060
try:
6161
execution_path = self._get_execution_path(execution_id)
62-
return Execution.model_validate_json(execution_path.read_text())
62+
return Execution.model_validate_json(execution_path.read_text(encoding="utf-8"))
6363
except FileNotFoundError as e:
6464
error_msg = f"Execution {execution_id} not found"
6565
raise NotFoundError(error_msg) from e

src/askui/tools/testing/feature_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def list_(
5757
def retrieve(self, feature_id: FeatureId) -> Feature:
5858
try:
5959
feature_path = self._get_feature_path(feature_id)
60-
return Feature.model_validate_json(feature_path.read_text())
60+
return Feature.model_validate_json(feature_path.read_text(encoding="utf-8"))
6161
except FileNotFoundError as e:
6262
error_msg = f"Feature {feature_id} not found"
6363
raise NotFoundError(error_msg) from e

src/askui/tools/testing/scenario_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def list_(self, query: ScenarioListQuery) -> ListResponse[Scenario]:
6262
def retrieve(self, scenario_id: ScenarioId) -> Scenario:
6363
try:
6464
scenario_path = self._get_scenario_path(scenario_id)
65-
return Scenario.model_validate_json(scenario_path.read_text())
65+
return Scenario.model_validate_json(scenario_path.read_text(encoding="utf-8"))
6666
except FileNotFoundError as e:
6767
error_msg = f"Scenario {scenario_id} not found"
6868
raise NotFoundError(error_msg) from e

0 commit comments

Comments
 (0)