Commit 8b419009 authored by Tom Niget's avatar Tom Niget

demo: handle errors in topology generation

parent fb92f016
...@@ -500,11 +500,14 @@ if args.port: ...@@ -500,11 +500,14 @@ if args.port:
if page < 2: if page < 2:
body = route_svg(page) body = route_svg(page)
else: else:
body = registry.Popen(('python3', '-c', r"""if 1: out, err = registry.Popen(('python3', '-c', r"""if 1:
import math, json import math, json
from re6st.registry import RegistryClient from re6st.registry import RegistryClient
g = json.loads(RegistryClient( topo = RegistryClient('http://localhost/').topology()
'http://localhost/').topology()) g = json.loads(topo)
if not g:
print('digraph { "empty topology" [shape="none"] }')
exit()
r = set(g.pop('', ())) r = set(g.pop('', ()))
a = set() a = set()
for v in g.values(): for v in g.values():
...@@ -523,13 +526,16 @@ if args.port: ...@@ -523,13 +526,16 @@ if args.port:
for v in v: for v in v:
print('"%s" -> "%s";' % (n, title(v))) print('"%s" -> "%s";' % (n, title(v)))
print('}') print('}')
"""), stdout=subprocess.PIPE, cwd="..").communicate()[0].decode("utf-8") """), stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd="..").communicate()
if body: if err:
body = subprocess.Popen(('neato', '-Tsvg'), self.send_error(500, explain='SVG generation failed: ' + err.decode(errors='replace'))
stdin=subprocess.PIPE, stdout=subprocess.PIPE, return
).communicate(body.encode("utf-8"))[0].decode("utf-8") graph_body = out.decode("utf-8")
if not body: try:
self.send_error(500) body = subprocess.run(('neato', '-Tsvg'), check=True, text=True,
input=graph_body).stdout
except subprocess.CalledProcessError as e:
self.send_error(500, explain='neato failed: ' + e.stderr)
return return
if ext == 'svg': if ext == 'svg':
mt = 'image/svg+xml' mt = 'image/svg+xml'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment