I get deprecation warnings as part of an exception and the returned traceback does not look correct
moepnse opened this issue · comments
Hello,
I get deprecation warnings as part of an exception. The returned traceback does not look correct.
/py/elephas/plugins/ui/0_base_component.py:120: DeprecationWarning: Setting observedAttributes as a method is deprecated. Set it as a class attribute.
webcomponent.define(component_name, web_component)
/py/elephas/plugins/ui/0_base_component.py:120: DeprecationWarning: Setting observedAttributes as a method is deprecated. Set it as a class attribute.
webcomponent.define(component_name, web_component)
Traceback (most recent call last):
File "http://localhost:8082/?brython-version=snapshot#__main__", line 18, in onopen
import elephas
File "VFS.elephas/__init__.py", line 68, in <module>
from . import ui
File "[VFS.elephas.ui/__init__.py](chrome://devtools/content/webconsole/VFS.elephas.ui/__init__.py)", line 6, in <module>
from . import splash
File "VFS.elephas.ui.uiplugins.py", line 44, in <module>
browser.aio.run(load_ui_plugins())
File "VFS.elephas.ui.uiplugins.py", line 43, in load_ui_plugins
UIPlugin.plugins_loaded()
File "/py/elephas/plugins/ui/0_base_component.py", line 185, in register
BaseComponent.register()
File "/py/elephas/plugins/ui/0_base_component.py", line 129, in register
Splash.hide_splash()
File "VFS.stermi.router.py", line 177, in event_handler
console.debug("No class handler found!")
File "/py/elephas/plugins/ui/app.py", line 144, in load_object
aio.run(_load_object(self, ev, router, params, query))
File "/py/elephas/plugins/ui/app.py", line 105, in _load_object
router.route(template, Default(attrs))
File "VFS.stermi.router.py", line 77, in route
history.append(page)
File "VFS.stermi.logic.py", line 35, in connectedCallback
self._initialized=True
File "<string>", line 5, in <module>
File "<string>", line 5, in <module>
File "VFS.stermi.logic.py", line 23, in register_logic_class
parent.register_logic_class(cls)
File "VFS.stermi.base_component.py", line 333, in register_logic_class
self._register_child_event_handlers(self)
File "VFS.ts3.experiment.py", line 29, in __init__
aio.run(self.init_cpu_n_mem_plot())
File "VFS.ts3.experiment.py", line 138, in init_live_stream_plot
channels:list=await remote_call_attr(self,'output_channels')
File "VFS.elephas.client.py", line 142, in remote_call_attr
session,ret_val=await window.session.call('app.call',[fqname_or_oid,call_name])
JavascriptError: TypeError: parts[1] is undefined
If you have any questions, please do not hesitate to contact me.
Thanks in advance!
Hard to tell about the DeprecationWarning. For the traceback, I have modified a function where parts[1]
is used, does it change anything ?
Yes, it has changed, but I think there is still work to be done.
/py/elephas/plugins/ui/0_base_component.py:120: DeprecationWarning: Setting observedAttributes as a method is deprecated. Set it as a class attribute.
webcomponent.define(component_name, web_component)
/py/elephas/plugins/ui/0_base_component.py:120: DeprecationWarning: Setting observedAttributes as a method is deprecated. Set it as a class attribute.
webcomponent.define(component_name, web_component)
Traceback (most recent call last):
File "?brython-version=snapshot", line 18, in onopen
import elephas
File "VFS.elephas/__init__.py", line 68, in <module>
from . import ui
File "VFS.elephas.ui/__init__.py", line 6, in <module>
from . import splash
File "VFS.elephas.ui.uiplugins.py", line 44, in <module>
browser.aio.run(load_ui_plugins())
File "VFS.elephas.ui.uiplugins.py", line 43, in load_ui_plugins
UIPlugin.plugins_loaded()
File "/py/elephas/plugins/ui/0_base_component.py", line 185, in register
BaseComponent.register()
File "/py/elephas/plugins/ui/0_base_component.py", line 129, in register
Splash.hide_splash()
File "VFS.stermi.router.py", line 177, in event_handler
console.debug("No class handler found!")
File "/py/elephas/plugins/ui/app.py", line 144, in load_object
aio.run(_load_object(self, ev, router, params, query))
File "/py/elephas/plugins/ui/app.py", line 105, in _load_object
router.route(template, Default(attrs))
File "VFS.stermi.router.py", line 77, in route
history.append(page)
File "VFS.stermi.logic.py", line 35, in connectedCallback
self._initialized=True
File "<string>", line 5, in <module>
File "VFS.stermi.logic.py", line 23, in register_logic_class
parent.register_logic_class(cls)
File "VFS.stermi.base_component.py", line 333, in register_logic_class
self._register_child_event_handlers(self)
File "VFS.ts3.experiment.py", line 29, in __init__
aio.run(self.init_cpu_n_mem_plot())
File "VFS.ts3.experiment.py", line 138, in init_live_stream_plot
channels:list=await remote_call_attr(self,'output_channels')
File "VFS.elephas.client.py", line 142, in remote_call_attr
session,ret_val=await window.session.call('app.call',[fqname_or_oid,call_name])
JavascriptError: undefined: undefined
undefined
I agree that the error message is not terribly helpful ;-)
It seems that the Javascript error raised in your program has no attribute "name" or "message". In the commit above I have added a trace that should appear in the console if you set the debug level to 2 or more. What does it say ?
Thanks for your efforts!
I have modified the issue demo from bug #2390 to cause the above error. The example is below the error message.
Now I am getting the following error:
Uncaught ReferenceError: err is not defined
exception https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:4193
show_error https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:4540
define/webcomp.prototype[key]</< https://raw.githack.com/brython-dev/brython/master/www/src/brython.js line 5727 > Function:171
define https://raw.githack.com/brython-dev/brython/master/www/src/brython.js line 5727 > Function:183
call1 https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:1610
call https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:1603
register637365426783006 https://raw.githack.com/brython-dev/brython/master/www/src/brython.js line 1117 > Function:224
f https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:2478
call https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:1603
anonymous https://raw.githack.com/brython-dev/brython/master/www/src/brython.js line 1117 > Function:754
loop https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:1117
run_script https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:963
loop https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:1133
onsuccess https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:1064
onsuccess https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:1055
idb_open https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:1040
loop https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:1133
run_scripts https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:945
brython https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:891
onload file:///C:/Users/lambojr/issues/brython_issue_20240313.html:1
onload https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:843
EventHandlerNonNull* https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:843
EventListener.handleEvent* https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:840
<anonymous> https://raw.githack.com/brython-dev/brython/master/www/src/brython.js:964
brython.js:4193:26
<!DOCTYPE html>
<html>
<head>
<!-- Required meta tags-->
<meta charset="utf-8">
<title>Issue Demo</title>
<!-- Brython -->
<script src="https://raw.githack.com/brython-dev/brython/master/www/src/brython.js"></script>
<!-- <script src="brython_.js"></script> -->
<script src="https://raw.githack.com/brython-dev/brython/master/www/src/brython_stdlib.js"></script>
<script>
function subscribe(uri, callback) {
throw new Error('Error 1');
}
function throw_js_error() {
throw new Error("Error 2");
}
</script>
<script type="text/python">
from browser import webcomponent, html, window, console, document
class BaseComponent:
_registry = []
_initialized = False
_logic_obj = None
_is_container: bool = False
_observed_attributes: list = []
def observedAttributes(self):
return self._observed_attributes
@staticmethod
def un_camel(word: str) -> str:
upper_chars: str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
last_char: str = word[0]
output: list = [last_char.lower()]
for c in word[1:]:
if c == "_":
output.append("-")
continue
if c in upper_chars:
if last_char not in upper_chars:
output.append('-')
output.append(c.lower())
else:
output.append(c)
last_char = c
return "".join(output)
@classmethod
def __init_subclass__(cls, **kwargs):
BaseComponent._registry.append(cls)
@classmethod
def remove_from_registry(cls, component):
print(cls._registry, component)
if component in cls._registry:
cls._registry.remove(component)
@classmethod
def register(cls):
registry = cls._registry
for web_component in registry:
web_component_name = cls.un_camel(web_component.__name__)
component_name = f"ui-{web_component_name}"
console.debug(f"registering web component {web_component} as {component_name}...")
webcomponent.define(component_name, web_component)
def register_logic_class(self, cls):
self._logic_class = cls
logic_obj = cls(self)
self._logic_obj = logic_obj
def render(target, data, layout):
window.Plotly.newPlot(
target,
data,
layout
)
class TimeSeries(BaseComponent):
def connectedCallback(self):
if not self._initialized:
# container div
self._container_div = div = document.createElement("div")
self.appendChild(div)
_locals = {}
config = self.querySelector("UI-TIME-SERIES-CONFIG")
if config:
bry_src = config.text
_globals = {}
exec(bry_src, _globals, _locals)
data = _locals.get("data", [])
layout = _locals.get("layout", [])
render(self._container_div, data, layout)
self._initialized = True
def restyle(self, restyle_data, trace_indexes=None):
console.debug(restyle_data)
window.Plotly.restyle(self._container_div, restyle_data, trace_indexes)
def relayout(self, update):
window.Plotly.relayout(self._container_div, update)
def resize(self,):
window.Plotly.Plots.resize(self._container_div)
def new_plot(self, data, layout):
render(self._container_div, data, layout)
def extend_traces(self, data, plot_indexes_to_modify):
window.Plotly.extendTraces(self._container_div, data, plot_indexes_to_modify)
def update(self, data):
window.Plotly.update(self._container_div, data)
class TimeSeriesConfig(BaseComponent):
pass
class Page(BaseComponent):
pass
class Logic(BaseComponent):
dependencies = ("Page", "PageContent")
def connectedCallback(self):
if not self._initialized:
def register_logic_class(cls):
nonlocal parent
if hasattr(parent, "register_logic_class"):
console.debug("registering logic class:", cls)
parent.register_logic_class(cls)
else:
console.error(f"{parent} has no logic class support")
parent = self.parentElement
bry_src = """
"""
bry_src += self.text
try:
exec(bry_src, {"parent": parent, "register_logic_class": register_logic_class})
except Exception as e:
console.error(e)
self._initialized = True
BaseComponent.register()
</script>
</head>
<body onload="brython({debug: 2})">
<ui-page>
<ui-time-series name="ts_cpu"></ui-time-series>
<ui-time-series name="ts_mem"></ui-time-series>
<ui-time-series name="ts_partitions"></ui-time-series>
<ui-logic style="display: none;">
import time
from datetime import datetime, timezone
import math
from browser import window, console, aio
class Demo:
def __init__(self, parent):
self._update_plot_subscription = None
self._update_system_health_subscription = None
self._parent = parent
# vvvv - system healt plots
self._ts_cpu = self._parent.querySelector("ui-time-series[name='ts_cpu']")
self._ts_mem = self._parent.querySelector("ui-time-series[name='ts_mem']")
self._ts_partitions = self._parent.querySelector("ui-time-series[name='ts_partitions']")
window.throw_js_error()
if self._ts_cpu and self._ts_mem:
aio.run(self.init_cpu_n_mem_plot())
# ^^^^
async def init_cpu_n_mem_plot(self, target_system=None):
console.debug("init_cpu_n_mem_plot")
target_system = ""
self._system_health_first_plot = True
console.debug(f'{target_system}.gemini')
if self._update_system_health_subscription is None:
self._update_system_health_subscription = window.subscribe(f'{target_system}.gemini', self.update_system_health_plots)
def update_system_health_plots(self, data, *args, **kwargs):
pass
register_logic_class(Demo)
</ui-logic>
</ui-page>
</body>
</html>
There was a typo in the previous commit...
After fixing it I get this error message
Traceback (most recent call last):
File "tests/issue_2387.html?hg", line 138, in <module>
BaseComponent.register()
File "tests/issue_2387.html?hg", line 50, in register
webcomponent.define(component_name, web_component)
File "tests/issue_2387.html?hg", line 132, in connectedCallback
exec(bry_src, {"parent": parent, "register_logic_class": register_logic_class})
File "<string>", line 36, in <module>
File "tests/issue_2387.html?hg", line 123, in register_logic_class
parent.register_logic_class(cls)
File "tests/issue_2387.html?hg", line 55, in register_logic_class
logic_obj = cls(self)
^^^^^^^^^
File "<string>", line 19, in __init__
JavascriptError: Error: Error 2
Is this the expected result ?
Yes, that makes troubleshooting much easier! Thank you!