diff --git a/merico/comments/main.py b/merico/comments/main.py index 53694ea..46227fb 100644 --- a/merico/comments/main.py +++ b/merico/comments/main.py @@ -259,6 +259,8 @@ def main(): code_text = selected_text.get("text", "") response = add_comments(selected_text=code_text, file_path=file_path) + if not response: + sys.exit(1) new_code = extract_markdown_block(response) if not new_code: diff --git a/merico/commit/commit.py b/merico/commit/commit.py index bbe2255..9a31c9f 100644 --- a/merico/commit/commit.py +++ b/merico/commit/commit.py @@ -401,6 +401,8 @@ def main(): if branch_name: user_input += "\ncurrent repo branch name is:" + branch_name commit_message = generate_commit_message_base_diff(user_input, diff) + if not commit_message: + sys.exit(1) # TODO # remove Closes #IssueNumber in commit message diff --git a/merico/docstring/main.py b/merico/docstring/main.py index cb1811c..7171414 100644 --- a/merico/docstring/main.py +++ b/merico/docstring/main.py @@ -291,6 +291,8 @@ def main(): response = add_docstring( selected_text=selected_text.get("text", ""), file_path=selected_text.get("abspath", "") ) + if not response: + sys.exit(1) # Get indent level indent = get_indent_level(selected_text.get("text", "")) diff --git a/merico/explain/explain.py b/merico/explain/explain.py index 25660e2..9d9dfa7 100644 --- a/merico/explain/explain.py +++ b/merico/explain/explain.py @@ -83,8 +83,8 @@ def explain(selected_text, visible_text): def main(): - explain(selected_text=get_selected_code(), visible_text=get_visible_code()) - sys.exit(0) + result = explain(selected_text=get_selected_code(), visible_text=get_visible_code()) + sys.exit(0 if result else 1) if __name__ == "__main__": diff --git a/merico/fix/main.py b/merico/fix/main.py index b799151..16ad7e5 100644 --- a/merico/fix/main.py +++ b/merico/fix/main.py @@ -141,6 +141,8 @@ def main(): # rewrite response = fix_bugs(selected_text=selected_text, visible_text=visible_text) + if not response: + sys.exit(1) # apply new code to editor new_code = extract_markdown_block(response) diff --git a/merico/refactor/names/main.py b/merico/refactor/names/main.py index f283265..bd7dadd 100644 --- a/merico/refactor/names/main.py +++ b/merico/refactor/names/main.py @@ -229,6 +229,8 @@ def main(): # rewrite response = reanme_variable(selected_text=selected_code, file_path=selected_file) + if not response: + sys.exit(1) # apply new code to editor new_code = extract_markdown_block(response) diff --git a/merico/refactor/rewrite.py b/merico/refactor/rewrite.py index b659e9b..d83f7ea 100644 --- a/merico/refactor/rewrite.py +++ b/merico/refactor/rewrite.py @@ -120,6 +120,8 @@ def main(): # rewrite response = ai_rewrite(question=question, selected_text=selected_text) + if not response: + sys.exit(1) # apply new code to editor new_code = extract_markdown_block(response) diff --git a/merico/unit_tests/propose_test.py b/merico/unit_tests/propose_test.py index 1005642..8b65a9d 100644 --- a/merico/unit_tests/propose_test.py +++ b/merico/unit_tests/propose_test.py @@ -122,6 +122,8 @@ def propose_test( ) or {} ) + if not json_res: + raise ValueError("No valid json response") else: # Use the openai api parameters diff --git a/merico/unit_tests/write_tests.py b/merico/unit_tests/write_tests.py index 058f606..4cdff4f 100644 --- a/merico/unit_tests/write_tests.py +++ b/merico/unit_tests/write_tests.py @@ -138,10 +138,12 @@ def write_and_print_tests( if USE_USER_MODEL: # Use the wrapped api - _ = chat_completion_stream_out( + response = chat_completion_stream_out( messages=[{"role": "user", "content": user_msg}], llm_config={"model": MODEL, "temperature": 0.1}, ) + if not response.get("content", None): + raise response["error"] else: # Use the openai api parameters