Skip to main content
 首页 » 编程设计

python之wsadmin 脚本中出现未处理异常后的误导性错误消息

2025年05月04日952php

我正在开发一个自动化框架,我遇到了 wsadmin 工具的奇怪行为。该问题在 WAS 6.1、7.0 和 8.0 中可重现(我没有尝试使用 8.5)。

我想知道这是否是 wsadmin 中的错误(很奇怪,还没有人注意到它,可能从 WAS 5 开始!)...

示例脚本可以在任何 WAS 环境中安全地执行而不会造成任何伤害。

try: 
    # this line throws WAS exception 
    AdminConfig.list('NonExistentType') 
except: 
    # exception is being handled 
    print 'Handled wsadmin exception' 
print 'Raising another exception' 
# eventually the script throws a non-WAS exception 
x = 1/0 

如果我理解正确,上面的脚本在除零时失败。但是 wsadmin 的输出有点困惑:

Handled wsadmin exception 
Raising another exception 
WASX7017E: Exception received while running file "ex.py"; exception information: com.ibm.websphere.management.exception.InvalidConfigDataTypeException 
com.ibm.websphere.management.exception.InvalidConfigDataTypeException: ADMG0007E: The configuration data type NonExistentType is not valid. 

真正有趣的是,Jacl 似乎也有同样的问题:

if [catch { puts [$AdminConfig list NonExistentType] } result] { 
    puts "Handled wsadmin exception" 
} 
puts "Raising another exception" 
set x [expr 1 / 0] 

wsadmin 也不打印有关终止脚本的实际异常的任何信息:

Handled wsadmin exception 
Raising another exception 
WASX7017E: Exception received while running file "ex.jacl"; exception information: com.ibm.websphere.management.exception.InvalidConfigDataTypeException 
com.ibm.websphere.management.exception.InvalidConfigDataTypeException: ADMG0007E: The configuration data type NonExistentType is not valid. 

稍微更改两个脚本(以避免抛出 WAS 异常)后,两个脚本的输出都是正确的。

try: 
    # this line does not throw any exception 
    AdminConfig.list('Cell') 
except: 
    # exception is being handled 
    print 'Handled wsadmin exception' 
print 'Raising another exception' 
# eventually the script throws a non-WAS exception 
x = 1/0 

如果脚本没有抛出/处理 WAS 异常,输出看起来像预期的那样:

Raising another exception 
WASX7017E: Exception received while running file "ex1.py"; exception information: com.ibm.bsf.BSFException: exception from Jython: 
Traceback (innermost last): 
  File "<string>", line 9, in ? 
ZeroDivisionError: integer division or modulo 

与 Jacl 相同:

if [catch { puts [$AdminConfig list Cell] } result] { 
    puts "Handled wsadmin exception" 
} 
puts "Raising another exception" 
set x [expr 1 / 0] 

wsadmin 输出以下内容,这也是意料之中的:

wdrCell(cells/wdrCell|cell.xml#Cell_1) 
Raising another exception 
WASX7017E: Exception received while running file "ex1.jacl"; exception information: com.ibm.bsf.BSFException: error while eval'ing Jacl expression: 
divide by zero 
    while executing 
"expr 1 / 0" 
    invoked from within 
"set x [expr 1 / 0]" 

我不得不承认一点:我问这个问题的原因是我实际上向 WebSphere 支持报告了这个问题。不过,我对他们的答复并不完全满意。 Wsadmin/Jython/Jacl/Python/Tcl 专家:您对此有何看法?

我做错了什么吗?

它是 wsadmin 中的错误吗?

这是预期的行为吗???

请您参考如下方法:

此问题将在即将推出的 WSAS 6.1、7.0、8.0 和 8.5 的修复包中得到解决。

IBM 支持有点担心破坏与以前实现的兼容性(好吧,这是有争议的,但某些脚本可能依赖于此错误),因此需要使用 com.ibm.ws 显式启用正确的行为。 scripting.exceptionPropagation=thrown JVM 属性。

我知道将此属性传递给 wsadmin 的 JVM 的两种方法:

  • javaOption 环境变量
  • javaoption 选项

环境变量方式:

export javaOption=-Dcom.ibm.ws.scripting.exceptionPropagation=thrown 
./wsadmin.sh -lang jython -f script.py 

命令行选项方式:

./wsadmin.sh -javaoption -Dcom.ibm.ws.scripting.exceptionPropagation=thrown-lang jython -f script.py 

此修复解决了 Jython 和 Jacl 的问题。

官方文档链接:http://www-01.ibm.com/support/docview.wss?uid=swg1PM80400