gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-merchant-demos] 04/14: generate proper error message on con


From: gnunet
Subject: [taler-taler-merchant-demos] 04/14: generate proper error message on configuration error (fixes #6512)
Date: Sun, 06 Sep 2020 11:20:21 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository taler-merchant-demos.

commit fd74c419ac1b308f314dd9d47c7dd98103aa0e80
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Aug 23 12:10:06 2020 +0200

    generate proper error message on configuration error (fixes #6512)
---
 bin/taler-merchant-demos                  |  4 ++--
 talermerchantdemos/blog/blog.py           | 13 +++++++++----
 talermerchantdemos/donations/donations.py | 13 +++++++++----
 talermerchantdemos/survey/survey.py       | 14 ++++++++++----
 4 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/bin/taler-merchant-demos b/bin/taler-merchant-demos
index 098416a..9cc7516 100755
--- a/bin/taler-merchant-demos
+++ b/bin/taler-merchant-demos
@@ -62,7 +62,7 @@ def handle_serve_uwsgi(config, whichShop):
     try:
         os.execlp(*params)
     except:
-        echo "Failed to start uwsgi. Please make sure to install uwsgi for 
Python3."
+        sys.stderr.write("Failed to start uwsgi. Please make sure to install 
uwsgi for Python3.")
         sys.exit(1)
 
 ##
@@ -82,7 +82,7 @@ def handle_serve_http(config, whichShop, port=None):
                   "--http", spec,
                   "--module", "talermerchantdemos.{}:app".format(whichShop))
     except:
-        echo "Failed to start uwsgi. Please make sure to install uwsgi for 
Python3."
+        sys.stderr.write("Failed to start uwsgi. Please make sure to install 
uwsgi for Python3.")
         sys.exit(1)
 
 @click.command("Global shop launcher")
diff --git a/talermerchantdemos/blog/blog.py b/talermerchantdemos/blog/blog.py
index cf14acb..2526c80 100644
--- a/talermerchantdemos/blog/blog.py
+++ b/talermerchantdemos/blog/blog.py
@@ -26,8 +26,9 @@ import base64
 import flask
 import lxml.etree
 import time
+import sys
 from urllib.parse import urljoin, urlencode, urlparse
-from taler.util.talerconfig import TalerConfig
+from taler.util.talerconfig import TalerConfig, ConfigurationError
 from ..blog.content import ARTICLES, get_article_file, get_image_file
 from talermerchantdemos.httpcommon import backend_get, backend_post
 
@@ -43,9 +44,13 @@ app.secret_key = 
base64.b64encode(os.urandom(64)).decode("utf-8")
 
 LOGGER = logging.getLogger(__name__)
 TC = TalerConfig.from_env()
-BACKEND_BASE_URL = TC["frontends"]["backend"].value_string(required=True)
-CURRENCY = TC["taler"]["currency"].value_string(required=True)
-APIKEY = TC["frontends"]["backend_apikey"].value_string(required=True)
+try:
+    BACKEND_BASE_URL = TC["frontends"]["backend"].value_string(required=True)
+    CURRENCY = TC["taler"]["currency"].value_string(required=True)
+    APIKEY = TC["frontends"]["backend_apikey"].value_string(required=True)
+except ConfigurationError as ce:
+    print(ce)
+    exit(1)
 ARTICLE_AMOUNT = CURRENCY + ":0.5"
 BACKEND_URL = urljoin(BACKEND_BASE_URL, "instances/blog/")
 
diff --git a/talermerchantdemos/donations/donations.py 
b/talermerchantdemos/donations/donations.py
index d02bfa3..614f730 100644
--- a/talermerchantdemos/donations/donations.py
+++ b/talermerchantdemos/donations/donations.py
@@ -25,9 +25,10 @@ import os
 import time
 import traceback
 import urllib
-from taler.util.talerconfig import TalerConfig
+from taler.util.talerconfig import TalerConfig, ConfigurationError
 from urllib.parse import urljoin
 from ..httpcommon import backend_post, backend_get
+import sys
 
 if not sys.version_info.major == 3 and sys.version_info.minor >= 6:
     print("Python 3.6 or higher is required.")
@@ -43,9 +44,13 @@ app.debug = True
 app.secret_key = base64.b64encode(os.urandom(64)).decode("utf-8")
 
 TC = TalerConfig.from_env()
-BACKEND_BASE_URL = TC["frontends"]["backend"].value_string(required=True)
-CURRENCY = TC["taler"]["currency"].value_string(required=True)
-APIKEY = TC["frontends"]["backend_apikey"].value_string(required=True)
+try:
+    BACKEND_BASE_URL = TC["frontends"]["backend"].value_string(required=True)
+    CURRENCY = TC["taler"]["currency"].value_string(required=True)
+    APIKEY = TC["frontends"]["backend_apikey"].value_string(required=True)
+except ConfigurationError as ce:
+    print(ce)
+    exit(1)
 
 app.config.from_object(__name__)
 
diff --git a/talermerchantdemos/survey/survey.py 
b/talermerchantdemos/survey/survey.py
index ef8e946..562b817 100644
--- a/talermerchantdemos/survey/survey.py
+++ b/talermerchantdemos/survey/survey.py
@@ -24,8 +24,9 @@ import logging
 from urllib.parse import urljoin
 import flask
 import traceback
-from taler.util.talerconfig import TalerConfig
+from taler.util.talerconfig import TalerConfig, ConfigurationError
 from ..httpcommon import backend_get, backend_post
+import sys
 
 if not sys.version_info.major == 3 and sys.version_info.minor >= 6:
     print("Python 3.6 or higher is required.")
@@ -37,9 +38,14 @@ app = flask.Flask(__name__, template_folder=BASE_DIR)
 app.debug = True
 app.secret_key = base64.b64encode(os.urandom(64)).decode('utf-8')
 TC = TalerConfig.from_env()
-BACKEND_URL = TC["frontends"]["backend"].value_string(required=True)
-CURRENCY = TC["taler"]["currency"].value_string(required=True)
-APIKEY = TC["frontends"]["backend_apikey"].value_string(required=True)
+try:
+    BACKEND_URL = TC["frontends"]["backend"].value_string(required=True)
+    CURRENCY = TC["taler"]["currency"].value_string(required=True)
+    APIKEY = TC["frontends"]["backend_apikey"].value_string(required=True)
+except ConfigurationError as ce:
+    print(ce)
+    exit(1)
+
 app.config.from_object(__name__)
 LOGGER = logging.getLogger(__name__)
 INSTANCED_URL = urljoin(BACKEND_URL, f"instances/survey/")

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]