From 18321ed15ce782ff5d1f24de9f2fb459d714d125 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Tue, 31 Jan 2023 15:12:39 +0100 Subject: Collapse most stream releated errors into IOError --- xmpp-vala/src/core/io_xmpp_stream.vala | 50 ++++++++++++---------------------- 1 file changed, 18 insertions(+), 32 deletions(-) (limited to 'xmpp-vala/src/core/io_xmpp_stream.vala') diff --git a/xmpp-vala/src/core/io_xmpp_stream.vala b/xmpp-vala/src/core/io_xmpp_stream.vala index 02653720..208e8053 100644 --- a/xmpp-vala/src/core/io_xmpp_stream.vala +++ b/xmpp-vala/src/core/io_xmpp_stream.vala @@ -1,7 +1,7 @@ using Gee; public interface Xmpp.WriteNodeFunc : Object { - public abstract async void write_stanza(XmppStream stream, StanzaNode node) throws IOStreamError; + public abstract async void write_stanza(XmppStream stream, StanzaNode node) throws IOError; } public abstract class Xmpp.IoXmppStream : XmppStream { @@ -15,10 +15,10 @@ public abstract class Xmpp.IoXmppStream : XmppStream { base(remote_name); } - public override async void disconnect() throws IOStreamError, XmlError, IOError { + public override async void disconnect() throws IOError { disconnected = true; if (writer == null || reader == null || stream == null) { - throw new IOStreamError.DISCONNECT("trying to disconnect, but no stream open"); + throw new IOError.CLOSED("trying to disconnect, but no stream open"); } log.str("OUT", "", this); yield writer.write(""); @@ -35,16 +35,12 @@ public abstract class Xmpp.IoXmppStream : XmppStream { require_setup(); } - public override async StanzaNode read() throws IOStreamError { + public override async StanzaNode read() throws IOError { StanzaReader? reader = this.reader; - if (reader == null) throw new IOStreamError.READ("trying to read, but no stream open"); - try { - StanzaNode node = yield ((!)reader).read_node(); - log.node("IN", node, this); - return node; - } catch (XmlError e) { - throw new IOStreamError.READ(e.message); - } + if (reader == null) throw new IOError.NOT_CONNECTED("trying to read, but no stream open"); + StanzaNode node = yield ((!)reader).read_node(); + log.node("IN", node, this); + return node; } [Version (deprecated = true, deprecated_since = "0.1", replacement = "write_async")] @@ -56,18 +52,14 @@ public abstract class Xmpp.IoXmppStream : XmppStream { }); } - public override async void write_async(StanzaNode node) throws IOStreamError { + public override async void write_async(StanzaNode node) throws IOError { if (write_obj != null) { yield write_obj.write_stanza(this, node); } else { StanzaWriter? writer = this.writer; - if (writer == null) throw new IOStreamError.WRITE("trying to write, but no stream open"); - try { - log.node("OUT", node, this); - yield ((!)writer).write_node(node); - } catch (XmlError e) { - throw new IOStreamError.WRITE(e.message); - } + if (writer == null) throw new IOError.NOT_CONNECTED("trying to write, but no stream open"); + log.node("OUT", node, this); + yield ((!)writer).write_node(node); } } @@ -75,7 +67,7 @@ public abstract class Xmpp.IoXmppStream : XmppStream { return stream; } - public override async void setup() throws IOStreamError { + public override async void setup() throws IOError { StanzaNode outs = new StanzaNode.build("stream", "http://etherx.jabber.org/streams") .put_attribute("to", remote_name.to_string()) .put_attribute("version", "1.0") @@ -89,17 +81,11 @@ public abstract class Xmpp.IoXmppStream : XmppStream { setup_needed = false; } - private async StanzaNode read_root() throws IOStreamError { + private async StanzaNode read_root() throws IOError { StanzaReader? reader = this.reader; - if (reader == null) throw new IOStreamError.READ("trying to read, but no stream open"); - try { - StanzaNode node = yield ((!)reader).read_root_node(); - log.node("IN ROOT", node, this); - return node; - } catch (XmlError.TLS e) { - throw new IOStreamError.TLS(e.message); - } catch (Error e) { - throw new IOStreamError.READ(e.message); - } + if (reader == null) throw new IOError.NOT_CONNECTED("trying to read, but no stream open"); + StanzaNode node = yield ((!)reader).read_root_node(); + log.node("IN ROOT", node, this); + return node; } } \ No newline at end of file -- cgit v1.2.3-54-g00ecf