From 0c2ee4ee6c1e1bb44b8fe75b61377ff571ac76b8 Mon Sep 17 00:00:00 2001 From: Believethehype Date: Sat, 30 Dec 2023 20:36:38 +0100 Subject: [PATCH] better error handling from venvs --- .idea/dataSources.xml | 12 ++++++++++++ nostr_dvm/bot.py | 2 +- nostr_dvm/dvm.py | 10 +++++----- nostr_dvm/interfaces/dvmtaskinterface.py | 1 - nostr_dvm/tasks/imagegeneration_openai_dalle.py | 6 +++--- setup.py | 2 +- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index e4a1d00b..d8ecaba7 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -56,5 +56,17 @@ + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/db/Bot.db + $ProjectFileDir$ + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.43.0/org/xerial/sqlite-jdbc/3.43.0.0/sqlite-jdbc-3.43.0.0.jar + + + \ No newline at end of file diff --git a/nostr_dvm/bot.py b/nostr_dvm/bot.py index 3895acf5..055d597b 100644 --- a/nostr_dvm/bot.py +++ b/nostr_dvm/bot.py @@ -239,7 +239,7 @@ def handle_nip90_feedback(nostr_event): client=self.client, config=self.dvm_config) time.sleep(2.0) reply_event = EventBuilder.new_encrypted_direct_msg(self.keys, - PublicKey.from_hex(user.npub), + PublicKey.from_hex(entry['npub']), content, None).to_event(self.keys) print(status + ": " + content) diff --git a/nostr_dvm/dvm.py b/nostr_dvm/dvm.py index d23339f6..ab5f7f33 100644 --- a/nostr_dvm/dvm.py +++ b/nostr_dvm/dvm.py @@ -469,6 +469,7 @@ def do_work(job_event, amount): task = get_task(job_event, client=self.client, dvm_config=self.dvm_config) for dvm in self.dvm_config.SUPPORTED_DVMS: + result = "" try: if task == dvm.TASK: @@ -488,13 +489,13 @@ def do_work(job_event, amount): with open(os.path.abspath('output.txt')) as f: resultall = f.readlines() - result = "" for line in resultall: if line != '\n': result += line os.remove(os.path.abspath('output.txt')) - if result.startswith("Error:"): - raise Exception + assert not result.startswith("Error:") + print(result) + else: # Some components might have issues with running code in otuside venv. # We install locally in these cases for now result = dvm.process(request_form) @@ -505,9 +506,8 @@ def do_work(job_event, amount): send_job_status_reaction(job_event, "error", content=str(e), dvm_config=self.dvm_config) except Exception as e: - print(e) # we could send the exception here to the user, but maybe that's not a good idea after all. - send_job_status_reaction(job_event, "error", content="An error occurred", + send_job_status_reaction(job_event, "error", content=result, dvm_config=self.dvm_config) # Zapping back the user on error if amount > 0 and self.dvm_config.LNBITS_ADMIN_KEY != "": diff --git a/nostr_dvm/interfaces/dvmtaskinterface.py b/nostr_dvm/interfaces/dvmtaskinterface.py index de4729d9..c3b2e070 100644 --- a/nostr_dvm/interfaces/dvmtaskinterface.py +++ b/nostr_dvm/interfaces/dvmtaskinterface.py @@ -146,5 +146,4 @@ def process_venv(identifier): DVMTaskInterface.write_output(result, args.output) except Exception as e: DVMTaskInterface.write_output("Error: " + str(e), args.output) - raise Exception diff --git a/nostr_dvm/tasks/imagegeneration_openai_dalle.py b/nostr_dvm/tasks/imagegeneration_openai_dalle.py index 69f119ad..e08c5b8c 100644 --- a/nostr_dvm/tasks/imagegeneration_openai_dalle.py +++ b/nostr_dvm/tasks/imagegeneration_openai_dalle.py @@ -116,9 +116,9 @@ def process(self, request_form): return result except Exception as e: - print("Error in Module") - raise Exception(e) - + if str(e).startswith("Error code: 400"): + raise Exception('Your request was rejected as a result of OpenAIĀ“s safety system. Your prompt may ' + 'contain text that is not allowed by their safety system.') # We build an example here that we can call by either calling this file directly from the main directory, # or by adding it to our playground. You can call the example and adjust it to your needs or redefine it in the diff --git a/setup.py b/setup.py index cc4a9b78..2a5d3ac4 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -VERSION = '0.1.4' +VERSION = '0.1.5' DESCRIPTION = 'A framework to build and run Nostr NIP90 Data Vending Machines' LONG_DESCRIPTION = ('A framework to build and run Nostr NIP90 Data Vending Machines. ' 'This is an early stage release. Interfaces might change/brick')