Skip to content

Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.

fix: identify invalid UTF-8 run configurations (#275)

Rudy Mizrahi Celekli2765a891a600
diff --git a/ifixai/cli/config_file.py b/ifixai/cli/config_file.py
index f8a08b7..c4f3692 100644
--- a/ifixai/cli/config_file.py
+++ b/ifixai/cli/config_file.py
@@ -58,7 +58,7 @@ def load_config(start_dir: Path | None = None) -> RunConfig | None:
raw = yaml.safe_load(path.read_text(encoding="utf-8"))
if raw is None:
raw = {}
- except OSError as exc:
+ except (OSError, UnicodeError) as exc:
raise ValueError(f"Could not read {CONFIG_FILENAME}: {exc}") from exc
except yaml.YAMLError as exc:
raise ValueError(f"{CONFIG_FILENAME} is not valid YAML: {exc}") from exc
diff --git a/ifixai/tests/test_config_invalid_encoding.py b/ifixai/tests/test_config_invalid_encoding.py
new file mode 100644
index 0000000..69039be
--- /dev/null
+++ b/ifixai/tests/test_config_invalid_encoding.py
@@ -0,0 +1,20 @@
+import pytest
+
+from ifixai.cli.config_file import load_config
+
+
+def test_invalid_utf8_config_uses_the_public_load_error_contract(tmp_path):
+ (tmp_path / "ifixai.yaml").write_bytes(b"provider: \xff\n")
+ with pytest.raises(ValueError, match=r"Could not read ifixai\.yaml"):
+ load_config(tmp_path)
+
+
+def test_cli_identifies_the_invalidly_encoded_config(tmp_path):
+ from ifixai.tests.test_cli_config_read_errors import _run
+
+ (tmp_path / "ifixai.yaml").write_bytes(b"provider: \xff\n")
+ result = _run(tmp_path)
+ assert result.returncode == 1
+ assert "Config error: Could not read ifixai.yaml:" in result.stderr
+ assert "Traceback" not in result.stderr
+ assert "Dry run" not in result.stdout