Skip to content

Commit a67299e

Browse files
committed
melib/nntp: set appropriate ErrorKind to errors
Signed-off-by: Manos Pitsidianakis <[email protected]>
1 parent 7ee8945 commit a67299e

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

melib/src/nntp/connection.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,10 @@ impl NntpStream {
117117
.await?;
118118
if !res.starts_with("101 ") {
119119
return Err(Error::new(format!(
120-
"Could not connect to {}: expected CAPABILITIES response but got:{}",
120+
"Could not connect to {}: expected CAPABILITIES response but got: {}",
121121
&server_conf.server_hostname, res
122-
)));
122+
))
123+
.set_kind(ErrorKind::ProtocolError));
123124
}
124125
let capabilities: Vec<&str> = res.lines().skip(1).collect();
125126

@@ -130,16 +131,17 @@ impl NntpStream {
130131
return Err(Error::new(format!(
131132
"Could not connect to {}: server is not NNTP VERSION 2 compliant",
132133
&server_conf.server_hostname
133-
)));
134+
))
135+
.set_kind(ErrorKind::ProtocolNotSupported));
134136
}
135137
if !capabilities
136138
.iter()
137139
.any(|cap| cap.eq_ignore_ascii_case("STARTTLS"))
138140
{
139141
return Err(Error::new(format!(
140-
"Could not connect to {}: server does not support STARTTLS",
142+
"Could not connect to {}: server does not support STARTTLS but it was required by user configuration",
141143
&server_conf.server_hostname
142-
)));
144+
)).set_kind(ErrorKind::NotSupported));
143145
}
144146
ret.stream.write_all(b"STARTTLS\r\n").await?;
145147
ret.stream.flush().await?;

melib/src/nntp/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl MailBackend for NntpType {
429429
_mailbox_hash: MailboxHash,
430430
_flags: Option<Flag>,
431431
) -> ResultFuture<()> {
432-
Err(Error::new("NNTP doesn't support saving."))
432+
Err(Error::new("NNTP doesn't support saving.").set_kind(ErrorKind::NotSupported))
433433
}
434434

435435
fn copy_messages(
@@ -439,7 +439,7 @@ impl MailBackend for NntpType {
439439
_destination_mailbox_hash: MailboxHash,
440440
_move_: bool,
441441
) -> ResultFuture<()> {
442-
Err(Error::new("NNTP doesn't support copying/moving."))
442+
Err(Error::new("NNTP doesn't support copying/moving.").set_kind(ErrorKind::NotSupported))
443443
}
444444

445445
fn set_flags(
@@ -504,7 +504,7 @@ impl MailBackend for NntpType {
504504
_env_hashes: EnvelopeHashBatch,
505505
_mailbox_hash: MailboxHash,
506506
) -> ResultFuture<()> {
507-
Err(Error::new("NNTP doesn't support deletion."))
507+
Err(Error::new("NNTP doesn't support deletion.").set_kind(ErrorKind::NotSupported))
508508
}
509509

510510
fn as_any(&self) -> &dyn std::any::Any {
@@ -525,7 +525,7 @@ impl MailBackend for NntpType {
525525
) -> ResultFuture<(MailboxHash, HashMap<MailboxHash, Mailbox>)> {
526526
Err(
527527
Error::new("Creating mailbox is not supported for nntp backend.")
528-
.set_kind(ErrorKind::NotImplemented),
528+
.set_kind(ErrorKind::NotSupported),
529529
)
530530
}
531531

@@ -593,7 +593,9 @@ impl MailBackend for NntpType {
593593
let mut conn = timeout(timeout_dur, connection.lock()).await?;
594594
let stream = conn.stream.as_ref()?;
595595
if !stream.supports_submission {
596-
return Err(Error::new("Server prohibits posting."));
596+
return Err(
597+
Error::new("Server prohibits posting.").set_kind(ErrorKind::NotSupported)
598+
);
597599
}
598600
// [ref:TODO] normalize CRLF in `bytes`
599601
let mut res = String::with_capacity(8 * 1024);

0 commit comments

Comments
 (0)