Page MenuHomePhabricator

pywikibot.exceptions.UnknownSite should show only error, no full traceback
Closed, ResolvedPublic

Description

I know that we have some task for this, but I'm not sure which one is.

Steps to reproduce:
Run python pwb.py login -family:wiktionary -lang:rs

Expected behaviour:
As lang isn't available, pywiki should show only error Language 'rs' does not exist in family wiktionary.

Actual behaviour:
Pywikibot shows all this:

Traceback (most recent call last):
  File "pwb.py", line 360, in <module>
    if not main():
  File "pwb.py", line 355, in main
    file_package)
  File "pwb.py", line 74, in run_python_file
    main_mod.__dict__)
  File "./scripts/login.py", line 185, in <module>
    main()
  File "./scripts/login.py", line 155, in main
    site = pywikibot.Site()
  File "/srv/paws/pwb/pywikibot/tools/__init__.py", line 1499, in wrapper
    return obj(*__args, **__kw)
  File "/srv/paws/pwb/pywikibot/__init__.py", line 1249, in Site
    _sites[key] = interface(code=code, fam=fam, user=user)
  File "/srv/paws/pwb/pywikibot/tools/__init__.py", line 1584, in wrapper
    return obj(*new_args, **new_kwargs)
  File "/srv/paws/pwb/pywikibot/site/__init__.py", line 1712, in __init__
    BaseSite.__init__(self, code, fam, user)
  File "/srv/paws/pwb/pywikibot/tools/__init__.py", line 1584, in wrapper
    return obj(*new_args, **new_kwargs)
  File "/srv/paws/pwb/pywikibot/site/__init__.py", line 768, in __init__
    % (self.__code, self.__family.name))
pywikibot.exceptions.UnknownSite: Language 'rs' does not exist in family wiktionary
CRITICAL: Exiting due to uncaught exception <class 'pywikibot.exceptions.UnknownSite'>

Reason for this is task is that I want to make warnings/errors more friendly.

Event Timeline

Xqt triaged this task as Low priority.Aug 6 2020, 4:36 AM

This can happen for so many scripts which use a Site object. We could have a new global option -notraceback to hide it or hide the traceback by default except -verbose option is set or have a config variable to hide the traceback. Or do never raise this exception but just show the warning and leave. The trick is made by sys.traceback setting to 0 which is 1000 by default. What do you think. Do you have another idea?

Ok one way could be to check whether the Site exits within handle_args.

Change 618702 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [IMPR] Leave teh script gracefully for wong -lang and -family option

https://gerrit.wikimedia.org/r/618702

New behaviour:

C:\pwb\GIT\core>pwb login -family:wiktionary -lang:rs
ERROR: UnknownSite: Language 'rs' does not exist in family wiktionary

C:\pwb\GIT\core>

This can happen for so many scripts which use a Site object. We could have a new global option -notraceback to hide it or hide the traceback by default except -verbose option is set or have a config variable to hide the traceback. Or do never raise this exception but just show the warning and leave. The trick is made by sys.traceback setting to 0 which is 1000 by default. What do you think. Do you have another idea?

We should just show warning/error, no full traceback per default. For debugging purposes, traceback is okay and user should have option to see it. But for this, I would like to more users says own opinion.

New behaviour:

C:\pwb\GIT\core>pwb login -family:wiktionary -lang:rs
ERROR: UnknownSite: Language 'rs' does not exist in family wiktionary

C:\pwb\GIT\core>

Much better! I've tested this patch, and I have this behaviour also.

Change 618702 merged by jenkins-bot:
[pywikibot/core@master] [IMPR] Leave the script gracefully for wrong -lang and -family option

https://gerrit.wikimedia.org/r/618702