Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chargeScripts may raise KeyError, "name", if external programs are unavailable #1034

Closed
e-kwsm opened this issue Jul 20, 2022 · 4 comments · Fixed by #1039
Closed

chargeScripts may raise KeyError, "name", if external programs are unavailable #1034

e-kwsm opened this issue Jul 20, 2022 · 4 comments · Fixed by #1039

Comments

@e-kwsm
Copy link
Contributor

e-kwsm commented Jul 20, 2022

Avogadro version: (please complete the following information from the About box):

  • Avogadrolibs: 1.96.0-175-g10a7a97f2e46
  • Qt: 5.15.5

Desktop version: (please complete the following information):

  • OS: EndeavourOS
  • Version: rolling
  • Compiler (if you built from source)

Describe the bug
If avogadro/qtplugins/scriptcharges/chargeScripts/{antechamber,xtb}.py take option --display-name, they access "name" of getMetaData():

elif args["display_name"]:
print(getMetaData()["name"])

elif args["display_name"]:
print(getMetaData()["name"])

However, the functions return empty dict if antechamber/xtb is unavailable, respectively:

def getMetaData():
# before we return metadata, make sure antechamber is in the path
if which("antechamber") is None:
return {} # Avogadro will ignore us now

def getMetaData():
# before we return metadata, make sure xtb is in the path
if which("xtb") is None:
return {} # Avogadro will ignore us now

Consequently getMetaData()["name"] may raise KeyError.
This does not terminate execution, though.

To Reproduce
Steps to reproduce the behavior:

  1. Prepare He.xyz:
1

He 0.0 0.0 0.0
  1. Open the file in a terminal: avogadro2 He.xyz
  2. See stderr:
...
Checking for  "charges"  scripts in "/usr/bin/../lib/avogadro2/scripts/charges"
ScriptLoader::queryProgramName: Unable to retrieve program name for "/usr/lib/avogadro2/scripts/charges/antechamber.py" ; "Error running script '/usr/bin/python /usr/lib/avogadro2/scripts/charges/antechamber.py --display-name --lang C': Abnormal exit status 1 (Unknown error.: Unknown error)\n\nOutput:\nTraceback (most recent call last):\n  File \"/usr/lib/avogadro2/scripts/charges/antechamber.py\", line 147, in <module>\n    print(getMetaData()[\"name\"])\nKeyError: 'name'\n"
ScriptLoader::queryProgramName: Unable to retrieve program name for "/usr/lib/avogadro2/scripts/charges/xtb.py" ; "Error running script '/usr/bin/python /usr/lib/avogadro2/scripts/charges/xtb.py --display-name --lang C': Abnormal exit status 1 (Unknown error.: Unknown error)\n\nOutput:\nTraceback (most recent call last):\n  File \"/usr/lib/avogadro2/scripts/charges/xtb.py\", line 96, in <module>\n    print(getMetaData()[\"name\"])\nKeyError: 'name'\n"
Open Babel formats ready:  145

Or, run

which antechamber || python avogadro/qtplugins/scriptcharges/chargeScripts/antechamber.py --display-name
which xtb         || python avogadro/qtplugins/scriptcharges/chargeScripts/xtb.py         --display-name

Expected behavior
No exception is raised.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here. Please consider uploading or linking test files.

@ghutchis
Copy link
Member

Okay, but that's by design. If you don't have the programs available, the scripts should fail and Avogadro won't show the methods as options.

What would you like to happen? You want the scripts to fail silently?

e-kwsm added a commit to e-kwsm/avogadrolibs that referenced this issue Jul 21, 2022
e-kwsm added a commit to e-kwsm/avogadrolibs that referenced this issue Jul 21, 2022
…available

fix OpenChemistry#1034

Signed-off-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
@e-kwsm
Copy link
Contributor Author

e-kwsm commented Jul 21, 2022

Thank you for your reply, but at the moment it is unclear why KeyError is raised; I created #1039.

@github-actions
Copy link
Contributor

Here are the build results
Avogadro2.AppImage
macOS.dmg
Ubuntu-2004.tar.gz
Win64.exe
Artifacts will only be retained for 90 days.

@github-actions
Copy link
Contributor

Here are the build results
Avogadro2.AppImage
macOS.dmg
Ubuntu-2004.tar.gz
Win64.exe
Artifacts will only be retained for 90 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants