jenkins-bot submitted this change.
[IMPR] use exc_info=True with pywikibot.exception() by default
Bug: T306762
Change-Id: I646834a6b4c07e510206bbc92f2d9c14e397efb8
---
M pywikibot/bot.py
M pywikibot/logging.py
M pywikibot/scripts/generate_family_file.py
M pywikibot/specialbots/_upload.py
M scripts/archivebot.py
M scripts/category.py
M scripts/category_redirect.py
M scripts/checkimages.py
M scripts/commonscat.py
M scripts/cosmetic_changes.py
M scripts/dataextend.py
M scripts/djvutext.py
M scripts/download_dump.py
M scripts/fixing_redirects.py
M scripts/interwiki.py
M scripts/maintenance/cache.py
M scripts/movepages.py
M scripts/pagefromfile.py
M scripts/parser_function_count.py
M scripts/redirect.py
M scripts/reflinks.py
M scripts/replace.py
M scripts/revertbot.py
M scripts/watchlist.py
M scripts/welcome.py
M tests/aspects.py
M tests/ui_tests.py
27 files changed, 80 insertions(+), 78 deletions(-)
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 5183905..5e7de0f 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -964,7 +964,7 @@
try:
pywikibot.Site()
except (UnknownFamilyError, UnknownSiteError):
- pywikibot.exception()
+ pywikibot.exception(exc_info=False)
sys.exit(1)
if username:
@@ -1516,7 +1516,7 @@
pywikibot.output('successfully.')
else:
pywikibot.output('by exception:\n')
- pywikibot.exception()
+ pywikibot.exception(exc_info=False)
def init_page(self, item: Any) -> 'pywikibot.page.BasePage':
"""Initialize a generator item before treating.
diff --git a/pywikibot/logging.py b/pywikibot/logging.py
index 5399d03..a955887 100644
--- a/pywikibot/logging.py
+++ b/pywikibot/logging.py
@@ -290,25 +290,26 @@
# Note: The logoutput frame must be updated if this decorator is removed
@deprecated_args(tb='exc_info') # since 7.2
-def exception(msg: Any = None, *args: Any, **kwargs: Any) -> None:
+def exception(msg: Any = None, *args: Any,
+ exc_info: bool = True, **kwargs: Any) -> None:
"""Output an error traceback to the user with level :const:`ERROR`.
Use directly after an 'except' statement::
...
except Exception:
- pywikibot.exception('exc_info'=True)
+ pywikibot.exception()
...
or alternatively::
...
except Exception as e:
- pywikibot.exception(e, 'exc_info'=True)
+ pywikibot.exception(e)
...
- Without `exc_info` parameter this function works like :func:`error`
- except that the `msg` parameter may be omitted.
+ With `exc_info=False` this function works like :func:`error` except
+ that the `msg` parameter may be omitted.
This function should only be called from an Exception handler.
``msg`` will be sent to stderr via :mod:`pywikibot.userinterfaces`.
The arguments are interpreted as for :func:`logoutput`.
@@ -316,6 +317,8 @@
.. versionchanged:: 7.2
only keyword arguments are allowed except for `msg`;
`exc_info` keyword is to be used instead of `tb`.
+ .. versionchanged:: 7.3
+ `exc_info` is True by default
.. seealso::
:python:`Logger.exception()
<library/logging.html#logging.Logger.exception>`
@@ -325,7 +328,7 @@
if msg is None:
exc_type, value, _tb = sys.exc_info()
msg = str(value)
- if not kwargs.get('exc_info', False):
+ if not exc_info:
msg += ' ({})'.format(exc_type.__name__)
assert msg is not None
- error(msg, *args, **kwargs)
+ error(msg, *args, exc_info=exc_info, **kwargs)
diff --git a/pywikibot/scripts/generate_family_file.py b/pywikibot/scripts/generate_family_file.py
index e109e7a..817409c 100755
--- a/pywikibot/scripts/generate_family_file.py
+++ b/pywikibot/scripts/generate_family_file.py
@@ -116,8 +116,8 @@
try:
w = self.Wiki(self.base_url, verify=verify)
except FatalServerError: # pragma: no cover
- print('ERROR: '
- + pywikibot.comms.http.SSL_CERT_VERIFY_FAILED_MSG)
+ pywikibot.error(
+ pywikibot.comms.http.SSL_CERT_VERIFY_FAILED_MSG)
pywikibot.exception()
if not pywikibot.bot.input_yn(
'Retry with disabled ssl certificate validation',
diff --git a/pywikibot/specialbots/_upload.py b/pywikibot/specialbots/_upload.py
index 66a81bb..d72bd15 100644
--- a/pywikibot/specialbots/_upload.py
+++ b/pywikibot/specialbots/_upload.py
@@ -401,8 +401,8 @@
and (not site.has_right('upload_by_url') or download):
try:
file_url = self.read_file_content(file_url)
- except FatalServerError:
- pywikibot.exception()
+ except FatalServerError as e:
+ pywikibot.error(e)
return None
try:
@@ -418,14 +418,14 @@
.format(site))
elif error.code == 'copyuploadbaddomain' and not download \
and '://' in file_url:
- pywikibot.exception()
+ pywikibot.error(error)
pywikibot.output('Downloading the file and retry...')
download = True
continue
else:
- pywikibot.error('Upload error: ', exc_info=True)
+ pywikibot.exception('Upload error: ')
except Exception:
- pywikibot.error('Upload error: ', exc_info=True)
+ pywikibot.exception('Upload error: ')
else:
if success:
# No warning, upload complete.
diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index 1ba136b..6d53efc 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -911,7 +911,7 @@
.format(pg, e))
except Exception:
pywikibot.exception('Error occurred while processing page {}'
- .format(pg), exc_info=True)
+ .format(pg))
if __name__ == '__main__':
diff --git a/scripts/category.py b/scripts/category.py
index 5a7e12b..7386033 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -1619,7 +1619,7 @@
try:
bot.run()
except Error:
- pywikibot.error('Fatal error:', exc_info=True)
+ pywikibot.exception('Fatal error:')
finally:
if cat_db:
cat_db.dump()
diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py
index 2b542ae..d0ce5b7 100755
--- a/scripts/category_redirect.py
+++ b/scripts/category_redirect.py
@@ -264,8 +264,8 @@
message = i18n.twtranslate(
self.site, 'category_redirect-log-added', params)
self.log_text.append(message)
- except Error:
- pywikibot.exception()
+ except Error as e:
+ pywikibot.error(e)
message = i18n.twtranslate(
self.site, 'category_redirect-log-add-failed', params)
self.log_text.append(message)
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 0c9430e..f3ea138 100755
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -602,8 +602,8 @@
pywikibot.output('Edit Conflict! Retrying...')
try:
self.put_mex_in_talk()
- except Exception:
- pywikibot.exception()
+ except Exception as e:
+ pywikibot.error(e)
pywikibot.output(
'Another error... skipping the user...')
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index d2b0915..ad8392f 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -381,8 +381,8 @@
pywikibot.log('Looking for template on ' + ipage.title())
try: # T291783
ipage_exists = ipage.exists()
- except InvalidTitleError:
- pywikibot.exception()
+ except InvalidTitleError as e:
+ pywikibot.error(e)
continue
if (not ipage_exists or ipage.isRedirectPage()
diff --git a/scripts/cosmetic_changes.py b/scripts/cosmetic_changes.py
index f432a61..96e6c4b 100755
--- a/scripts/cosmetic_changes.py
+++ b/scripts/cosmetic_changes.py
@@ -77,8 +77,8 @@
ignore=self.opt.ignore)
try:
old_text = self.current_page.text
- except InvalidPageError:
- pywikibot.exception()
+ except InvalidPageError as e:
+ pywikibot.error(e)
return
new_text = cc_toolkit.change(old_text)
diff --git a/scripts/dataextend.py b/scripts/dataextend.py
index 5f916df..1411475 100644
--- a/scripts/dataextend.py
+++ b/scripts/dataextend.py
@@ -15437,8 +15437,8 @@
repo = pywikibot.Site().data_repository()
try:
item = pywikibot.ItemPage(repo, item)
- except InvalidTitleError:
- pywikibot.exception()
+ except InvalidTitleError as e:
+ pywikibot.error(e)
else:
bot = DataExtendBot(site=repo, generator=[item], **options)
bot.run()
diff --git a/scripts/djvutext.py b/scripts/djvutext.py
index 509ddeb..8e3ca18 100755
--- a/scripts/djvutext.py
+++ b/scripts/djvutext.py
@@ -214,4 +214,4 @@
try:
main()
except Exception:
- pywikibot.error('Fatal error:', exc_info=True)
+ pywikibot.exception('Fatal error:')
diff --git a/scripts/download_dump.py b/scripts/download_dump.py
index 4a7b6cf..abe740c 100755
--- a/scripts/download_dump.py
+++ b/scripts/download_dump.py
@@ -164,13 +164,13 @@
replace(file_current_storepath, file_final_storepath)
break
- except OSError:
- pywikibot.exception()
+ except OSError as e:
+ pywikibot.error(e)
try:
remove(file_current_storepath)
- except OSError:
- pywikibot.exception()
+ except OSError as e:
+ pywikibot.error(e)
# If the atomic download fails, try without a temporary file
# If the non-atomic download also fails, exit the script
diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py
index bdb3700..b147f86 100755
--- a/scripts/fixing_redirects.py
+++ b/scripts/fixing_redirects.py
@@ -97,8 +97,8 @@
# Check whether the link found is to page.
try:
actual_link_page.title()
- except InvalidTitleError:
- pywikibot.exception()
+ except InvalidTitleError as e:
+ pywikibot.error(e)
continue
if actual_link_page != linked_page:
continue
@@ -172,8 +172,8 @@
InvalidTitleError,
InterwikiRedirectPageError):
pass
- except RuntimeError:
- pywikibot.exception()
+ except RuntimeError as e:
+ pywikibot.error(e)
else:
section = target.section()
if section and not does_text_contain_section(target.text,
@@ -193,8 +193,8 @@
"""Change all redirects from the current page to actual links."""
try:
newtext = self.current_page.text
- except InvalidPageError:
- pywikibot.exception()
+ except InvalidPageError as e:
+ pywikibot.error(e)
return
with ThreadPoolExecutor() as executor:
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index d6473b0..2b5d814 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -1723,8 +1723,8 @@
page.save(summary=mcomment,
asynchronous=self.conf.asynchronous,
nocreate=True)
- except NoCreateError:
- pywikibot.exception()
+ except NoCreateError as e:
+ pywikibot.error(e)
return False
except LockedPageError:
pywikibot.output('Page {} is locked. Skipping.'
@@ -2430,7 +2430,7 @@
except KeyboardInterrupt:
dump.write_dump(bot.dump_titles, append)
except Exception:
- pywikibot.exception(tb=bool(config.verbose_output))
+ pywikibot.exception(exc_info=bool(config.verbose_output))
dump.write_dump(bot.dump_titles, append)
else:
pywikibot.output('Script terminated sucessfully.')
diff --git a/scripts/maintenance/cache.py b/scripts/maintenance/cache.py
index cb24d54..48da334 100755
--- a/scripts/maintenance/cache.py
+++ b/scripts/maintenance/cache.py
@@ -265,10 +265,10 @@
try:
entry._load_cache()
- except ValueError as e:
+ except ValueError:
pywikibot.error('Failed loading {}'.format(
entry._cachefile_path()))
- pywikibot.exception(e, exc_info=True)
+ pywikibot.exception()
continue
if use_accesstime is None:
@@ -282,19 +282,19 @@
try:
entry.parse_key()
- except ParseError:
+ except ParseError as e:
pywikibot.error('Problems parsing {} with key {}'
.format(entry.filename, entry.key))
- pywikibot.exception()
+ pywikibot.error(e)
continue
try:
entry._rebuild()
- except Exception as e:
+ except Exception:
pywikibot.error('Problems loading {} with key {}, {!r}'
.format(entry.filename, entry.key,
entry._parsed_key))
- pywikibot.exception(e, exc_info=True)
+ pywikibot.exception()
continue
if func is None or func(entry):
@@ -317,8 +317,8 @@
try:
return eval('lambda entry: ' + command)
- except Exception:
- pywikibot.exception()
+ except Exception as e:
+ pywikibot.error(e)
pywikibot.error(
'Cannot compile {} command: {}'.format(name, command))
return None
diff --git a/scripts/movepages.py b/scripts/movepages.py
index 118dc9c..c59d653 100755
--- a/scripts/movepages.py
+++ b/scripts/movepages.py
@@ -86,8 +86,8 @@
movetalk=self.opt.movetalkpage,
movesubpages=self.opt.movesubpages,
noredirect=self.opt.noredirect)
- except PageRelatedError:
- pywikibot.exception()
+ except PageRelatedError as e:
+ pywikibot.error(e)
def skip_page(self, page):
"""Treat only non-redirect pages if 'skipredirects' is set."""
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index fd29a6b..a29606f 100755
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -209,8 +209,8 @@
encoding=config.textfile_encoding) as f:
text = f.read()
- except OSError:
- pywikibot.exception()
+ except OSError as e:
+ pywikibot.error(e)
return
position = 0
diff --git a/scripts/parser_function_count.py b/scripts/parser_function_count.py
index 83d4566..df996e1 100755
--- a/scripts/parser_function_count.py
+++ b/scripts/parser_function_count.py
@@ -168,8 +168,8 @@
with codecs.open(
self.opt.save, encoding='utf-8', mode='a') as f:
f.write(resultlist)
- except OSError:
- pywikibot.exception()
+ except OSError as e:
+ pywikibot.error(e)
if self.opt.upload:
page = pywikibot.Page(self.site, self.opt.upload)
diff --git a/scripts/redirect.py b/scripts/redirect.py
index e7eaa39..4488167 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -489,8 +489,8 @@
"""Get redirect target page and handle some exceptions."""
try:
return page.getRedirectTarget()
- except (CircularRedirectError, RuntimeError):
- pywikibot.exception()
+ except (CircularRedirectError, RuntimeError) as e:
+ pywikibot.error(e)
pywikibot.output('Skipping {}.'.format(page))
except InterwikiRedirectPageError:
pywikibot.output('{} is on another site, skipping.'.format(page))
@@ -502,8 +502,8 @@
done = not self.opt.delete
try:
targetPage = self.get_redirect_target(redir_page)
- except InvalidTitleError:
- pywikibot.exception()
+ except InvalidTitleError as e:
+ pywikibot.error(e)
targetPage = None
if not targetPage:
@@ -511,8 +511,8 @@
try:
targetPage.get()
- except InvalidTitleError:
- pywikibot.exception()
+ except InvalidTitleError as e:
+ pywikibot.error(e)
except NoPageError:
movedTarget = None
with suppress(NoMoveTargetError):
@@ -582,8 +582,8 @@
pywikibot.warning(
"Redirect target section {} doesn't exist."
.format(newRedir.title(as_link=True)))
- except UnsupportedPageError:
- pywikibot.exception()
+ except UnsupportedPageError as e:
+ pywikibot.error(e)
pywikibot.output('Skipping {}.'.format(newRedir))
break
except NoPageError:
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index d8e571c..23ae56b 100755
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -510,9 +510,9 @@
pywikibot.output('pdfinfo value error.')
except OSError:
pywikibot.output('pdfinfo OS error.')
- except Exception: # Ignore errors
+ except Exception as e: # Ignore errors
pywikibot.output('PDF processing error.')
- pywikibot.exception()
+ pywikibot.error(e)
else:
for aline in pdfinfo_out.splitlines():
if isinstance(aline, bytes):
diff --git a/scripts/replace.py b/scripts/replace.py
index fe93bad..6d807db 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -664,8 +664,8 @@
"""Work on each page retrieved from generator."""
try:
original_text = page.text
- except InvalidPageError:
- pywikibot.exception()
+ except InvalidPageError as e:
+ pywikibot.error(e)
return
applied = set()
new_text = original_text
diff --git a/scripts/revertbot.py b/scripts/revertbot.py
index 551f81f..ea4a5d5 100755
--- a/scripts/revertbot.py
+++ b/scripts/revertbot.py
@@ -143,7 +143,7 @@
return 'The edit(s) made in {} by {} was rollbacked'.format(
page.title(), self.user)
- pywikibot.exception()
+ pywikibot.exception(exc_info=False)
return False
def log(self, msg) -> None:
diff --git a/scripts/watchlist.py b/scripts/watchlist.py
index dd3ed60..1b94bd4 100755
--- a/scripts/watchlist.py
+++ b/scripts/watchlist.py
@@ -135,8 +135,8 @@
for page in watchlist:
try:
pywikibot.stdout(page.title())
- except InvalidTitleError:
- pywikibot.exception()
+ except InvalidTitleError as e:
+ pywikibot.error(e)
if __name__ == '__main__':
diff --git a/scripts/welcome.py b/scripts/welcome.py
index 223b327..5086e92 100755
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -709,8 +709,8 @@
or ue.action() == 'autocreate' and globalvar.welcome_auto:
try:
user = ue.page()
- except HiddenKeyError:
- pywikibot.exception()
+ except HiddenKeyError as e:
+ pywikibot.error(e)
else:
yield user
diff --git a/tests/aspects.py b/tests/aspects.py
index 89653a8..8bfbb66 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -468,8 +468,7 @@
r.status_code, HTTPStatus(r.status_code).phrase))
except Exception as e:
pywikibot.exception('{}: accessing {} caused exception:'
- .format(cls.__name__, hostname),
- exc_info=True)
+ .format(cls.__name__, hostname))
cls._checked_hostnames[hostname] = e
raise unittest.SkipTest(
diff --git a/tests/ui_tests.py b/tests/ui_tests.py
index 6df6054..3c81000 100755
--- a/tests/ui_tests.py
+++ b/tests/ui_tests.py
@@ -157,7 +157,7 @@
try:
raise TestExceptionError('Testing Exception')
except TestExceptionError:
- pywikibot.exception('exception')
+ pywikibot.error('exception', exc_info=False)
self.assertEqual(self.strout.getvalue(), '')
self.assertEqual(self.strerr.getvalue(),
'ERROR: exception\n')
@@ -166,7 +166,7 @@
try:
raise TestExceptionError('Testing Exception')
except TestExceptionError:
- pywikibot.exception()
+ pywikibot.exception(exc_info=False)
self.assertEqual(self.strout.getvalue(), '')
self.assertEqual(self.strerr.getvalue(),
'ERROR: Testing Exception (TestExceptionError)\n')
@@ -175,7 +175,7 @@
try:
raise TestExceptionError('Testing Exception')
except TestExceptionError:
- pywikibot.exception(exc_info=True)
+ pywikibot.exception()
self.assertEqual(self.strout.getvalue(), '')
stderrlines = self.strerr.getvalue().split('\n')
self.assertEqual(stderrlines[0],
To view, visit change 787065. To unsubscribe, or for help writing mail filters, visit settings.