Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Add clear error when starting API and config file not found, closes #412

davidmezzettie2e903663956
diff --git a/src/python/txtai/app/base.py b/src/python/txtai/app/base.py
index 820644b1..7983a432 100644
--- a/src/python/txtai/app/base.py
+++ b/src/python/txtai/app/base.py
@@ -38,9 +38,14 @@ class Application:
with open(data, "r", encoding="utf-8") as f:
# Read configuration
return yaml.safe_load(f)
- else:
- # Read yaml from string
- return yaml.safe_load(data)
+
+ # Attempt to read yaml from input
+ data = yaml.safe_load(data)
+ if not isinstance(data, str):
+ return data
+
+ # File not found and input is not yaml, raise error
+ raise FileNotFoundError(f"Unable to load file '{data}'")
# Return unmodified
return data
diff --git a/test/python/testapp.py b/test/python/testapp.py
new file mode 100644
index 00000000..4f153dd1
--- /dev/null
+++ b/test/python/testapp.py
@@ -0,0 +1,21 @@
+"""
+Application module tests
+"""
+
+import unittest
+
+from txtai.app import Application
+
+
+class TestApp(unittest.TestCase):
+ """
+ Application tests.
+ """
+
+ def testConfig(self):
+ """
+ Tests a file not found config exception
+ """
+
+ with self.assertRaises(FileNotFoundError):
+ Application.read("No file here")