commands: use new error variants for a few more commands
This commit is contained in:
@@ -35,15 +35,24 @@ impl CommandRequest for MoveRequest {
|
||||
}
|
||||
|
||||
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
|
||||
let from_or_range = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let from_or_range = from_or_range
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, from_or_range.to_string()))?;
|
||||
let from_or_range = parts.next().ok_or(Self::missing_arguments_error(0))?;
|
||||
let from_or_range =
|
||||
from_or_range
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 0,
|
||||
expected_type: "OneOrRange".to_string(),
|
||||
raw_input: from_or_range.to_string(),
|
||||
})?;
|
||||
|
||||
let to = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let to = parts.next().ok_or(Self::missing_arguments_error(1))?;
|
||||
let to = to
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, to.to_string()))?;
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 1,
|
||||
expected_type: "AbsoluteRelativeSongPosition".to_string(),
|
||||
raw_input: to.to_string(),
|
||||
})?;
|
||||
|
||||
Self::throw_if_too_many_arguments(parts)?;
|
||||
|
||||
|
||||
@@ -35,15 +35,23 @@ impl CommandRequest for MoveIdRequest {
|
||||
}
|
||||
|
||||
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
|
||||
let id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let id = parts.next().ok_or(Self::missing_arguments_error(0))?;
|
||||
let id = id
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, id.to_string()))?;
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 0,
|
||||
expected_type: "SongId".to_string(),
|
||||
raw_input: id.to_string(),
|
||||
})?;
|
||||
|
||||
let to = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let to = parts.next().ok_or(Self::missing_arguments_error(1))?;
|
||||
let to = to
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, to.to_string()))?;
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 1,
|
||||
expected_type: "AbsoluteRelativeSongPosition".to_string(),
|
||||
raw_input: to.to_string(),
|
||||
})?;
|
||||
|
||||
Self::throw_if_too_many_arguments(parts)?;
|
||||
|
||||
|
||||
@@ -58,23 +58,44 @@ impl CommandRequest for PlaylistFindRequest {
|
||||
None => return Err(Self::missing_arguments_error(0)),
|
||||
};
|
||||
|
||||
let mut argument_index_counter = 0;
|
||||
let mut sort_or_window = parts.next();
|
||||
let mut sort = None;
|
||||
if let Some("sort") = sort_or_window {
|
||||
let s = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
argument_index_counter += 1;
|
||||
let s = parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::MissingKeywordValue {
|
||||
keyword: "sort",
|
||||
argument_index: argument_index_counter,
|
||||
})?;
|
||||
sort = Some(
|
||||
s.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, s.to_string()))?,
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: argument_index_counter,
|
||||
expected_type: "Sort".to_string(),
|
||||
raw_input: s.to_string(),
|
||||
})?,
|
||||
);
|
||||
sort_or_window = parts.next();
|
||||
}
|
||||
|
||||
let mut window = None;
|
||||
if let Some("window") = sort_or_window {
|
||||
let w = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
argument_index_counter += 1;
|
||||
let w = parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::MissingKeywordValue {
|
||||
keyword: "window",
|
||||
argument_index: argument_index_counter,
|
||||
})?;
|
||||
window = Some(
|
||||
w.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, w.to_string()))?,
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: argument_index_counter,
|
||||
expected_type: "WindowRange".to_string(),
|
||||
raw_input: w.to_string(),
|
||||
})?,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,23 +57,44 @@ impl CommandRequest for PlaylistSearchRequest {
|
||||
None => return Err(Self::missing_arguments_error(0)),
|
||||
};
|
||||
|
||||
let mut argument_index_counter = 0;
|
||||
let mut sort_or_window = parts.next();
|
||||
let mut sort = None;
|
||||
if let Some("sort") = sort_or_window {
|
||||
let s = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
argument_index_counter += 1;
|
||||
let s = parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::MissingKeywordValue {
|
||||
keyword: "sort",
|
||||
argument_index: argument_index_counter,
|
||||
})?;
|
||||
sort = Some(
|
||||
s.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, s.to_string()))?,
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: argument_index_counter,
|
||||
expected_type: "Sort".to_string(),
|
||||
raw_input: s.to_string(),
|
||||
})?,
|
||||
);
|
||||
sort_or_window = parts.next();
|
||||
}
|
||||
|
||||
let mut window = None;
|
||||
if let Some("window") = sort_or_window {
|
||||
let w = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
argument_index_counter += 1;
|
||||
let w = parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::MissingKeywordValue {
|
||||
keyword: "window",
|
||||
argument_index: argument_index_counter,
|
||||
})?;
|
||||
window = Some(
|
||||
w.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, w.to_string()))?,
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: argument_index_counter,
|
||||
expected_type: "WindowRange".to_string(),
|
||||
raw_input: w.to_string(),
|
||||
})?,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,16 +41,24 @@ impl CommandRequest for PlChangesRequest {
|
||||
}
|
||||
|
||||
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
|
||||
let version = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let version = parts.next().ok_or(Self::missing_arguments_error(0))?;
|
||||
let version = version
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, version.to_string()))?;
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 0,
|
||||
expected_type: "PlaylistVersion".to_string(),
|
||||
raw_input: version.to_string(),
|
||||
})?;
|
||||
|
||||
let window = parts
|
||||
.next()
|
||||
.map(|w| {
|
||||
w.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, w.to_string()))
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 1,
|
||||
expected_type: "WindowRange".to_string(),
|
||||
raw_input: w.to_string(),
|
||||
})
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
|
||||
@@ -41,16 +41,24 @@ impl CommandRequest for PlChangesPosIdRequest {
|
||||
}
|
||||
|
||||
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
|
||||
let version = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let version = parts.next().ok_or(Self::missing_arguments_error(0))?;
|
||||
let version = version
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, version.to_string()))?;
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 0,
|
||||
expected_type: "PlaylistVersion".to_string(),
|
||||
raw_input: version.to_string(),
|
||||
})?;
|
||||
|
||||
let window = parts
|
||||
.next()
|
||||
.map(|w| {
|
||||
w.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, w.to_string()))
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 1,
|
||||
expected_type: "WindowRange".to_string(),
|
||||
raw_input: w.to_string(),
|
||||
})
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
|
||||
@@ -35,15 +35,23 @@ impl CommandRequest for PrioRequest {
|
||||
}
|
||||
|
||||
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
|
||||
let prio = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let prio = parts.next().ok_or(Self::missing_arguments_error(0))?;
|
||||
let prio = prio
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, prio.to_string()))?;
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 0,
|
||||
expected_type: "Priority".to_string(),
|
||||
raw_input: prio.to_string(),
|
||||
})?;
|
||||
|
||||
let window = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let window = parts.next().ok_or(Self::missing_arguments_error(1))?;
|
||||
let window = window
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, window.to_string()))?;
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 1,
|
||||
expected_type: "WindowRange".to_string(),
|
||||
raw_input: window.to_string(),
|
||||
})?;
|
||||
|
||||
Self::throw_if_too_many_arguments(parts)?;
|
||||
|
||||
|
||||
@@ -42,12 +42,17 @@ impl CommandRequest for PrioIdRequest {
|
||||
}
|
||||
|
||||
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
|
||||
let prio = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let prio = parts.next().ok_or(Self::missing_arguments_error(0))?;
|
||||
let prio = prio
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, prio.to_string()))?;
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 0,
|
||||
expected_type: "Priority".to_string(),
|
||||
raw_input: prio.to_string(),
|
||||
})?;
|
||||
|
||||
let songids = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
// TODO: determine how to count arguments here...
|
||||
let songids = parts.next().ok_or(Self::missing_arguments_error(1))?;
|
||||
let songids = songids
|
||||
.split(',')
|
||||
.map(|s| {
|
||||
|
||||
@@ -38,15 +38,24 @@ impl CommandRequest for RangeIdRequest {
|
||||
}
|
||||
|
||||
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
|
||||
let songid = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let songid = parts.next().ok_or(Self::missing_arguments_error(0))?;
|
||||
let songid = songid
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, songid.to_string()))?;
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 0,
|
||||
expected_type: "SongId".to_string(),
|
||||
raw_input: songid.to_string(),
|
||||
})?;
|
||||
|
||||
let time_interval = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let time_interval = time_interval
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, time_interval.to_string()))?;
|
||||
let time_interval = parts.next().ok_or(Self::missing_arguments_error(1))?;
|
||||
let time_interval =
|
||||
time_interval
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 1,
|
||||
expected_type: "TimeInterval".to_string(),
|
||||
raw_input: time_interval.to_string(),
|
||||
})?;
|
||||
|
||||
Self::throw_if_too_many_arguments(parts)?;
|
||||
|
||||
|
||||
@@ -35,15 +35,23 @@ impl CommandRequest for SwapRequest {
|
||||
}
|
||||
|
||||
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
|
||||
let songpos1 = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let songpos1 = parts.next().ok_or(Self::missing_arguments_error(0))?;
|
||||
let songpos1 = songpos1
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, songpos1.to_string()))?;
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 0,
|
||||
expected_type: "SongPosition".to_string(),
|
||||
raw_input: songpos1.to_string(),
|
||||
})?;
|
||||
|
||||
let songpos2 = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let songpos2 = parts.next().ok_or(Self::missing_arguments_error(1))?;
|
||||
let songpos2 = songpos2
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, songpos2.to_string()))?;
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 1,
|
||||
expected_type: "SongPosition".to_string(),
|
||||
raw_input: songpos2.to_string(),
|
||||
})?;
|
||||
|
||||
Self::throw_if_too_many_arguments(parts)?;
|
||||
|
||||
|
||||
@@ -35,15 +35,23 @@ impl CommandRequest for SwapIdRequest {
|
||||
}
|
||||
|
||||
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
|
||||
let songid1 = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let songid1 = parts.next().ok_or(Self::missing_arguments_error(0))?;
|
||||
let songid1 = songid1
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, songid1.to_string()))?;
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 0,
|
||||
expected_type: "SongId".to_string(),
|
||||
raw_input: songid1.to_string(),
|
||||
})?;
|
||||
|
||||
let songid2 = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let songid2 = parts.next().ok_or(Self::missing_arguments_error(1))?;
|
||||
let songid2 = songid2
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, songid2.to_string()))?;
|
||||
.map_err(|_| RequestParserError::SubtypeParserError {
|
||||
argument_index: 1,
|
||||
expected_type: "SongId".to_string(),
|
||||
raw_input: songid2.to_string(),
|
||||
})?;
|
||||
|
||||
Self::throw_if_too_many_arguments(parts)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user