summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorMartin Bielik <mx.bielik@gmail.com>2023-04-10 12:19:49 +0200
committerMartin Bielik <mx.bielik@gmail.com>2023-04-10 12:19:49 +0200
commit1d1a8887d49db5339aa3cb917f860452b7ffb7b2 (patch)
tree6b824adb2f880080702104cd48d86c39e3998786 /py
parent4a9a44ec891c81af93bcf5d5ddde2e1fb481317d (diff)
downloadvim-ai-1d1a8887d49db5339aa3cb917f860452b7ffb7b2.tar.gz
improved error handling
Diffstat (limited to 'py')
-rw-r--r--py/chat.py39
-rw-r--r--py/utils.py2
2 files changed, 23 insertions, 18 deletions
diff --git a/py/chat.py b/py/chat.py
index 2983701..0e3245f 100644
--- a/py/chat.py
+++ b/py/chat.py
@@ -30,24 +30,27 @@ def initialize_chat_window():
vim.command("redraw")
def parse_chat_header_options():
- options = {}
- lines = vim.eval('getline(1, "$")')
- contains_chat_options = '[chat-options]' in lines
- if contains_chat_options:
- # parse options that are defined in the chat header
- options_index = lines.index('[chat-options]')
- for line in lines[options_index + 1:]:
- if line.startswith('#'):
- # ignore comments
- continue
- if line == '':
- # stop at the end of the region
- break
- (key, value) = line.strip().split('=')
- if key == 'initial_prompt':
- value = value.split('\\n')
- options[key] = value
- return options
+ try:
+ options = {}
+ lines = vim.eval('getline(1, "$")')
+ contains_chat_options = '[chat-options]' in lines
+ if contains_chat_options:
+ # parse options that are defined in the chat header
+ options_index = lines.index('[chat-options]')
+ for line in lines[options_index + 1:]:
+ if line.startswith('#'):
+ # ignore comments
+ continue
+ if line == '':
+ # stop at the end of the region
+ break
+ (key, value) = line.strip().split('=')
+ if key == 'initial_prompt':
+ value = value.split('\\n')
+ options[key] = value
+ return options
+ except:
+ raise Exception("Invalid [chat-options]")
initialize_chat_window()
diff --git a/py/utils.py b/py/utils.py
index dee7d42..2291a26 100644
--- a/py/utils.py
+++ b/py/utils.py
@@ -9,6 +9,8 @@ def load_api_key():
api_key = file.read()
except Exception:
pass
+ if not api_key:
+ raise Exception("Missing OpenAI API key")
return api_key.strip()
def make_request_options(options):