When first time you started using WLST you might get many of these Python based WLST Errors. Here I had collected few of them which are very simple to handle them with care. Only thing you need to understand when what kind of errors raises, and what need to do to handle them. When there is error on your flow of WLST Script or prompt don't be panic, relax for a moment then after a while take a deep breath and focus on your error and map with one of the following and do the required workaround.
In Jython we have issubclass() to check superclass, subclass relation we can verify class relationship. You can find parent-child relationship with it. As per my understanding the Error hierarchy can be defined in WLST(Jython) as follows:
This WLST(Jython) Error tree I prepared and posted for your reference, so that you can make your script in perfect manner, here you can find what is going wrong why it is happen while working out your script.
Now let us see the sample indentation issue that raises the Syntax Error.
Another option for Syntax Error
This Error I have observed when I tried to migrate the WebLogic domain with createDomain() command.
This "Lexical error" got due to the copying from the webpage which has single quotes in different unicode value. When I retype the single quotes it was resolved.
Here in the above sample after issuing try block starting we must use a tab or 4 spaces before connect() command. When it found that is not
having proper indentation it raised the SyntaxError.
When the name used to do something like print or use in some other expression without assigning the value before it was defined then WLST will raises NameError. When first time scripting most of the time user encounters this unknowingly.
The following example might give you an idea how to resolve your issue.
You can handle this kind of error with our try-except block
The beauty of handling your Exception/Error more transparent and easy to understand with sys.exc_info() list.
This error can be raised by the WLST while using the dictionary objects or map objects accessed with non-matching key.
When I ran with all number values with %5d it was shouted as follows:
You might be on MBean tree where there is no such attribute defined and you tried to access it then WLST Shell raises AttributeError. Let us see an Example you can easily understand.
Let us see the example a list is defined with 5 elements
concatenation does not allows you, raises the TypeError.
Thanks for reading this post, Give your feedback in comments. cheers!!
Good References:
In Jython we have issubclass() to check superclass, subclass relation we can verify class relationship. You can find parent-child relationship with it. As per my understanding the Error hierarchy can be defined in WLST(Jython) as follows:
This WLST(Jython) Error tree I prepared and posted for your reference, so that you can make your script in perfect manner, here you can find what is going wrong why it is happen while working out your script.
SyntaxError
This you cannot be handled with the try-except block, because it will be thrown when your syntax is not in properly arranged, that is in the statement missing indentation or improper arguments. SyntaxError could be raised when the script lines are given for parsing, it will do token by token parsing wherever the improper syntax given WLST Shell points with cap char under the token.Now let us see the sample indentation issue that raises the Syntax Error.
wls:/offline>; try:
...connect('system','weblogic103','t3://adminhost:adminport')
Traceback (innermost last):
(no code object)
at line 0
File
"", line 2
connect('system','weblogic103','t3://adminhost:adminport')
^
SyntaxError: invalid syntax
Another option for Syntax Error
This Error I have observed when I tried to migrate the WebLogic domain with createDomain() command.
wls:/offline/wdomain>createDomain('/home/backup/olddomain.jar', '/home/otherusr/domains/newdomain',’system', 'weblogic103')
Traceback (innermost last):
(no code object) at line 0
File "", line 1
createDomain('/home/backup/olddomain.jar', '/home/otherusr/domains/newdomain',?system', 'weblogic103')
^
SyntaxError: Lexical error at line 1, column 99. Encountered: "\ufffd" (65533), after : ""
This "Lexical error" got due to the copying from the webpage which has single quotes in different unicode value. When I retype the single quotes it was resolved.
Here in the above sample after issuing try block starting we must use a tab or 4 spaces before connect() command. When it found that is not
having proper indentation it raised the SyntaxError.
NameError
When the name used to do something like print or use in some other expression without assigning the value before it was defined then WLST will raises NameError. When first time scripting most of the time user encounters this unknowingly.
The following example might give you an idea how to resolve your issue.
wls:/offline> var1=100 wls:/offline> var3=var1+var2 Traceback (innermost last): File "", line 1, in ?
You can handle this kind of error with our try-except block
wls:/offline> try: var3=var1+var2 ...except NameError, e: ... print "Please check there is: ", sys.exc_info()[0], sys.exc_info()[1] ... Please check there is: exceptions.NameError var2
The beauty of handling your Exception/Error more transparent and easy to understand with sys.exc_info() list.
KeyError
This error can be raised by the WLST while using the dictionary objects or map objects accessed with non-matching key.
wls:/offline> urls['b'] Traceback (innermost last): File "", line 1, in ? KeyError: b
ValueError
The ValueError is raised by the WLST shell when there is a inappropriate element is accessed in a list or a variable, that is such as the value specified for searching in the list with index() method. Removing the element which is not really exists in the list.wls:/offline> L.index('web2')
Traceback (innermost last):
File
"<console>", line 1, in ?
ValueError: list.index(x): x not in list
I was working on thread and JVM monitoring script, encountered with the ValueError in different way. After storing the ThreadPool values, JVM values into local variables
I was using C type of formating to display the data in a row of Table. Some of the attribute values are Long integers, some of them plain integers some of them are strings.
cd('/ServerRuntimes/'+ svr +'/ThreadPoolRuntime/ThreadPoolRuntime')
thtot=`get('ExecuteThreadTotalCount')`
thid= `get('ExecuteThreadIdleCount')`
hog= `get('HoggingThreadCount')`
sbth= `get('StandbyThreadCount')`
cr =`get('CompletedRequestCount')`
pr =`get('PendingUserRequestCount')`
ql =`get('QueueLength')`
th= `get('Throughput')`
cd('/ServerRuntimes/'+svr+'/JVMRuntime/'+svr)
freejvm = long(get('HeapFreeCurrent'))/(1024*1024)
totaljvm = long(get('HeapSizeCurrent'))/(1024*1024)
usedjvm = (totaljvm - freejvm)
When I ran with all number values with %5d it was shouted as follows:
ValueError: unsupported format character ' ' (0x20) at index 23Don't know what attribute requires which format ... Initially to resolve this display without any format for all attributes in the MBean.
print svr, thtot, thid, hog, sbth, cr, pr, ql, th, hs, totaljvm, freejvm, usedjvmBut still ValueError was exists, when I updated with formater it was stuck with CompletedRequestCount that was not integer, it is Long integer. changed the format for that attribute it resolved one issue. Now the issue with different index number came... I have an idea that, if I found all the attributes and their data types then it will be easy to fix the right format for each. I tried the following way
print type(thtot),type(thid), type(hog), type(sbth), type(cr), type(pr), type(ql), type(th),type(freejvm), type(totaljvm), type(usedjvm)formated accordingly the ValueError is resolved.
print '%14s %10s %5s %5s %5s %5s %8s %5s %5s %8s %5dMB %5dMB %5dMB' % (svr, hs, thtot, thid, hog, sbth, cr, pr, ql, th, totaljvm, freejvm, usedjvm)So now take care of Values of variables for your WLST code before use them for any operation!!
AttributeError
You might be on MBean tree where there is no such attribute defined and you tried to access it then WLST Shell raises AttributeError. Let us see an Example you can easily understand.
wls:/demodom/serverConfig> cmo.State() Traceback (innermost last): File "", line 1, in ? AttributeError: State
IndexError
The IndexError will be raised by the WLST shell, when thelist object is accessed with a out of range index value.Let us see the example a list is defined with 5 elements
wls:/offline> L['app1', 'app2', 'app3', 'app4', 'web1']when it is accessed with out of range index value say 7 then you get the IndexError.
wls:/offline> L[7] Traceback (innermost last): File "<console>", line 1, in ? IndexError: index out of range: 7
TypeError
The basic python object types int, str assignments or expressions or print statements withconcatenation does not allows you, raises the TypeError.
wls:/offline> print 'Number of servers:', 5 Number of servers: 5 wls:/offline>print 'Number of servers:'+ 5 Traceback (innermost last): File "<console>", line 1, in ? TypeError: cannot concatenate 'str' and 'int' objects
Thanks for reading this post, Give your feedback in comments. cheers!!
Good References:

0 comments:
Post a Comment