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