mirror of
https://github.com/storytold/deckcraft.git
synced 2026-10-29 04:56:58 -06:00
Slides: going to a slide that does not exist is an error
slide.go clamped an out-of-range index to the last slide and reported success, so a request for slide 99 of a short deck landed on the last slide without a word. It now returns an error and stays on the current slide. A slide id beyond u32 is reported as an unknown slide instead of being read as id 0.
This commit is contained in:
@@ -283,9 +283,16 @@ fn go_to(s: &mut Session, i: usize) -> Result<Value> {
|
||||
fn go(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let i = match (usize_param(p, "index"), p.get("id").and_then(Value::as_u64)) {
|
||||
(Some(i), _) => i,
|
||||
(None, Some(id)) => s.doc()?.doc.slide_index(SlideId(u32::try_from(id).unwrap_or(0))).ok_or_else(|| bad("slide.go", "no such slide"))?,
|
||||
(None, Some(id)) => s
|
||||
.doc()?
|
||||
.doc
|
||||
.slide_index(SlideId(u32::try_from(id).map_err(|_| bad("slide.go", "no such slide"))?))
|
||||
.ok_or_else(|| bad("slide.go", "no such slide"))?,
|
||||
_ => return Err(bad("slide.go", "missing `index`")),
|
||||
};
|
||||
if i >= s.doc()?.doc.slides.len() {
|
||||
return Err(bad("slide.go", format!("no slide {i}")));
|
||||
}
|
||||
go_to(s, i)
|
||||
}
|
||||
fn next(s: &mut Session, _p: &Value) -> Result<Value> {
|
||||
|
||||
Reference in New Issue
Block a user