cmd_receive: internal error-handling cleanups

This commit is contained in:
Brian Warner 2016-04-25 18:24:18 -07:00
parent a181a3fb35
commit 2a6767ee6f

View File

@ -88,11 +88,11 @@ class TwistedReceiver:
else: else:
self.msg(u"I don't know what they're offering\n") self.msg(u"I don't know what they're offering\n")
self.msg(u"Offer details:", them_d) self.msg(u"Offer details:", them_d)
raise RespondError({"error": "unknown offer type"}) raise RespondError("unknown offer type")
except RespondError as r: except RespondError as r:
data = json.dumps(r.response).encode("utf-8") data = json.dumps({"error": r.response}).encode("utf-8")
yield w.send_data(data) yield w.send_data(data)
raise TransferError(r["error"]) raise TransferError(r.response)
returnValue(None) returnValue(None)
@inlineCallbacks @inlineCallbacks
@ -144,7 +144,7 @@ class TwistedReceiver:
zipmode = file_data["mode"] zipmode = file_data["mode"]
if zipmode != "zipfile/deflated": if zipmode != "zipfile/deflated":
self.msg(u"Error: unknown directory-transfer mode '%s'" % (zipmode,)) self.msg(u"Error: unknown directory-transfer mode '%s'" % (zipmode,))
raise RespondError({"error": "unknown mode"}) raise RespondError("unknown mode")
self.abs_destname = self.decide_destname("directory", self.abs_destname = self.decide_destname("directory",
file_data["dirname"]) file_data["dirname"])
self.xfersize = file_data["zipsize"] self.xfersize = file_data["zipsize"]
@ -168,7 +168,7 @@ class TwistedReceiver:
if os.path.exists(abs_destname): if os.path.exists(abs_destname):
self.msg(u"Error: refusing to overwrite existing %s %s" % self.msg(u"Error: refusing to overwrite existing %s %s" %
(mode, destname)) (mode, destname))
raise RespondError({"error": "%s already exists" % mode}) raise RespondError("%s already exists" % mode)
return abs_destname return abs_destname
def ask_permission(self): def ask_permission(self):
@ -179,7 +179,7 @@ class TwistedReceiver:
break break
print(u"transfer rejected", file=sys.stderr) print(u"transfer rejected", file=sys.stderr)
self.args.timing.finish_event(_start, answer="no") self.args.timing.finish_event(_start, answer="no")
raise RespondError({"error": "transfer rejected"}) raise RespondError("transfer rejected")
self.args.timing.finish_event(_start, answer="yes") self.args.timing.finish_event(_start, answer="yes")
@inlineCallbacks @inlineCallbacks