handling more errors gracefully

This commit is contained in:
Rudis Muiznieks 2018-09-25 17:18:11 -05:00 committed by Rudis Muiznieks
parent 4ff4693fa3
commit b75a672ce2
2 changed files with 6 additions and 3 deletions

View File

@ -45,8 +45,11 @@
public Story ParseBlocks(IEnumerable<Block> blocks)
{
// get the story
var storyBlock = blocks.SingleOrDefault(b => b.Type == BlockType.Story);
if(storyBlock == null) throw new FicdownException("No story block found");
var storyBlocks = blocks.Where(b => b.Type == BlockType.Story);
if(storyBlocks.Count() == 0) throw new FicdownException("No story block found");
if(storyBlocks.Count() > 1) throw new FicdownException("More than one story block found");
var storyBlock = storyBlocks.Single();
Anchor storyAnchor;
try

View File

@ -44,7 +44,7 @@
get
{
var scene = _story.Scenes[_story.FirstScene].Where(s => s.Conditions == null);
if(scene == null)
if(scene.Count() == 0)
throw new FicdownException(_story.Name, string.Format("Story links to undefined scene: {0}", _story.FirstScene));
if(scene.Count() > 1)
throw new FicdownException(_story.Name, string.Format("Story links to scene that is defined more than once: {0}", _story.FirstScene));