From 037c0a53d01d1daf490c321cef72a2331e9df25c Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 22 Aug 2017 14:27:29 -0400 Subject: [PATCH 1/7] Print an error message when doctr fails Some commands are run in the finally block, which makes it hard to see where the actual error is. This hopefully makes it easier to find in the log. --- doctr/__main__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doctr/__main__.py b/doctr/__main__.py index e720b96e..5481e92a 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -28,6 +28,7 @@ import subprocess import yaml import json +import shlex from pathlib import Path @@ -290,6 +291,11 @@ def deploy(args, parser): print("Don't have permission to push. Not trying.") else: print("The docs have not changed. Not updating") + except: + DOCTR_COMMAND = ' '.join(map(shlex.quote, sys.argv)) + print("ERROR: The doctr command %r failed." % DOCTR_COMMAND, + file=sys.stderr) + raise finally: run(['git', 'checkout', current_commit]) # Ignore error, won't do anything if there was nothing to stash From 1d995dba7205829116a02123f54233c1a9b71561 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 22 Aug 2017 14:28:54 -0400 Subject: [PATCH 2/7] Add an exit early test, to make test out the error message code --- doctr/__main__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doctr/__main__.py b/doctr/__main__.py index 5481e92a..0ee65c25 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -273,6 +273,8 @@ def deploy(args, parser): run(['git', 'stash', '--all']) checkout_deploy_branch(deploy_branch, canpush=canpush) + sys.exit("Test exiting early") + if args.sync: log_file = os.path.join(deploy_dir, '.doctr-files') From f79d0ae3c353293ed29493fccd8aa9bc38b113f2 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 22 Aug 2017 14:36:34 -0400 Subject: [PATCH 3/7] Print the error message in red --- doctr/__main__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index 0ee65c25..5ceef36e 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -41,6 +41,9 @@ get_travis_branch, copy_to_tmp, checkout_deploy_branch) from . import __version__ +def red(text): + return "\033[31m%s\033[0m" % text + def make_parser_with_config_adder(parser, config): """factory function for a smarter parser: @@ -295,7 +298,7 @@ def deploy(args, parser): print("The docs have not changed. Not updating") except: DOCTR_COMMAND = ' '.join(map(shlex.quote, sys.argv)) - print("ERROR: The doctr command %r failed." % DOCTR_COMMAND, + print(red("ERROR: The doctr command %r failed." % DOCTR_COMMAND), file=sys.stderr) raise finally: From 46497949cdee27bd6ea7ed8b22f528978b21e4a0 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 22 Aug 2017 14:40:29 -0400 Subject: [PATCH 4/7] Print the exception message in red This should make it easier to see what happened (even if it's not in the context of the error). Most exceptions will be sys.exit() from a failed command. --- doctr/__main__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index 5ceef36e..425d223f 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -296,10 +296,11 @@ def deploy(args, parser): print("Don't have permission to push. Not trying.") else: print("The docs have not changed. Not updating") - except: + except BaseException as e: DOCTR_COMMAND = ' '.join(map(shlex.quote, sys.argv)) print(red("ERROR: The doctr command %r failed." % DOCTR_COMMAND), file=sys.stderr) + print(red(e), file=sys.stderr) raise finally: run(['git', 'checkout', current_commit]) From 5a5ae458cada11187e36eea25a4aeb5342df2a1a Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 22 Aug 2017 14:45:38 -0400 Subject: [PATCH 5/7] Put the error message on the same line --- doctr/__main__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index 425d223f..045786f7 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -298,9 +298,8 @@ def deploy(args, parser): print("The docs have not changed. Not updating") except BaseException as e: DOCTR_COMMAND = ' '.join(map(shlex.quote, sys.argv)) - print(red("ERROR: The doctr command %r failed." % DOCTR_COMMAND), + print(red("ERROR: The doctr command %r failed: %s" % (DOCTR_COMMAND, e), file=sys.stderr) - print(red(e), file=sys.stderr) raise finally: run(['git', 'checkout', current_commit]) From 4824ad31a090361025dfa555fca29bce372b8e13 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 22 Aug 2017 14:50:14 -0400 Subject: [PATCH 6/7] Fix syntax --- doctr/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index 045786f7..16627067 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -298,7 +298,7 @@ def deploy(args, parser): print("The docs have not changed. Not updating") except BaseException as e: DOCTR_COMMAND = ' '.join(map(shlex.quote, sys.argv)) - print(red("ERROR: The doctr command %r failed: %s" % (DOCTR_COMMAND, e), + print(red("ERROR: The doctr command %r failed: %s" % (DOCTR_COMMAND, e)), file=sys.stderr) raise finally: From 443aa3e9661a0c22353e41af48c57a87ca953fc0 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Tue, 22 Aug 2017 14:57:41 -0400 Subject: [PATCH 7/7] Revert "Add an exit early test, to make test out the error message code" This reverts commit 1d995dba7205829116a02123f54233c1a9b71561. --- doctr/__main__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/doctr/__main__.py b/doctr/__main__.py index 16627067..84217129 100644 --- a/doctr/__main__.py +++ b/doctr/__main__.py @@ -276,8 +276,6 @@ def deploy(args, parser): run(['git', 'stash', '--all']) checkout_deploy_branch(deploy_branch, canpush=canpush) - sys.exit("Test exiting early") - if args.sync: log_file = os.path.join(deploy_dir, '.doctr-files')