Revamp error logging somewhat
This commit is contained in:
parent
7dff8f0dca
commit
af22814bc3
|
@ -1,9 +1,8 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import itertools
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
|
||||||
import re
|
import re
|
||||||
from netlib import http_uastrings
|
from netlib import http_uastrings
|
||||||
from . import pathoc, pathod, version, utils, language
|
from . import pathoc, pathod, version, utils, language
|
||||||
|
|
|
@ -14,6 +14,7 @@ def write(fp, lines):
|
||||||
)
|
)
|
||||||
for i in lines:
|
for i in lines:
|
||||||
fp.write(i)
|
fp.write(i)
|
||||||
|
fp.write("\n")
|
||||||
fp.flush()
|
fp.flush()
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,22 +45,13 @@ class Log:
|
||||||
if rlog:
|
if rlog:
|
||||||
self("Bytes read:")
|
self("Bytes read:")
|
||||||
self.dump(rlog, self.hex)
|
self.dump(rlog, self.hex)
|
||||||
if exc_type == netlib.tcp.NetLibTimeout:
|
if self.lines:
|
||||||
self("Timeout")
|
write(
|
||||||
elif exc_type in (
|
self.fp,
|
||||||
netlib.tcp.NetLibDisconnect,
|
[
|
||||||
netlib.http.HttpErrorConnClosed
|
"\n".join(self.lines),
|
||||||
):
|
]
|
||||||
self("Disconnected")
|
)
|
||||||
elif exc_type == netlib.http.HttpError:
|
|
||||||
self("HTTP Error: %s" % exc_value.message)
|
|
||||||
write(
|
|
||||||
self.fp,
|
|
||||||
[
|
|
||||||
"\n".join(self.lines),
|
|
||||||
"\n"
|
|
||||||
]
|
|
||||||
)
|
|
||||||
if exc_value:
|
if exc_value:
|
||||||
raise exc_value
|
raise exc_value
|
||||||
|
|
||||||
|
|
|
@ -346,10 +346,14 @@ class Pathoc(tcp.TCPClient):
|
||||||
)
|
)
|
||||||
resp.append(self.sslinfo)
|
resp.append(self.sslinfo)
|
||||||
resp = Response(*resp)
|
resp = Response(*resp)
|
||||||
|
except http.HttpError, v:
|
||||||
|
log("Invalid server response: %s" % v)
|
||||||
|
raise
|
||||||
except tcp.NetLibTimeout:
|
except tcp.NetLibTimeout:
|
||||||
if self.ignoretimeout:
|
if self.ignoretimeout:
|
||||||
log("Timeout (ignored)")
|
log("Timeout (ignored)")
|
||||||
return None
|
return None
|
||||||
|
log("Timeout")
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
if resp:
|
if resp:
|
||||||
|
|
|
@ -304,9 +304,10 @@ class PathodHandler(tcp.BaseHandler):
|
||||||
)])
|
)])
|
||||||
|
|
||||||
if anchor_gen:
|
if anchor_gen:
|
||||||
lg("crafting spec: %s" % anchor_gen)
|
spec = anchor_gen.next()
|
||||||
|
lg("crafting spec: %s" % spec)
|
||||||
nexthandler, retlog["response"] = self.http_serve_crafted(
|
nexthandler, retlog["response"] = self.http_serve_crafted(
|
||||||
anchor_gen.next()
|
spec
|
||||||
)
|
)
|
||||||
if nexthandler and websocket_key:
|
if nexthandler and websocket_key:
|
||||||
return self.handle_websocket, retlog
|
return self.handle_websocket, retlog
|
||||||
|
|
|
@ -16,7 +16,7 @@ def test_disconnect():
|
||||||
rw = DummyIO()
|
rw = DummyIO()
|
||||||
try:
|
try:
|
||||||
with log.Log(outf, False, rw, rw) as lg:
|
with log.Log(outf, False, rw, rw) as lg:
|
||||||
raise netlib.tcp.NetLibDisconnect()
|
lg("Test")
|
||||||
except netlib.tcp.NetLibDisconnect:
|
except netlib.tcp.NetLibDisconnect:
|
||||||
pass
|
pass
|
||||||
assert "Disconnected" in outf.getvalue()
|
assert "Test" in outf.getvalue()
|
||||||
|
|
|
@ -145,7 +145,7 @@ class TestDaemon(_TestDaemon):
|
||||||
assert "202" in self.tval(["get:'/p/202:b@1'"], ignorecodes=[200, 201])
|
assert "202" in self.tval(["get:'/p/202:b@1'"], ignorecodes=[200, 201])
|
||||||
|
|
||||||
def test_timeout(self):
|
def test_timeout(self):
|
||||||
assert "Timeout" in self.tval(["get:'/p/200:p0,10'"], timeout=0.01)
|
assert "Timeout" in self.tval(["get:'/p/200:p0,100'"], timeout=0.01)
|
||||||
assert "HTTP" in self.tval(
|
assert "HTTP" in self.tval(
|
||||||
["get:'/p/200:p5,100'"],
|
["get:'/p/200:p5,100'"],
|
||||||
showresp=True,
|
showresp=True,
|
||||||
|
|
Loading…
Reference in New Issue