Log error for invalid beatmap/storyboard events instead of thro… (#5611)

Log error for invalid beatmap/storyboard events instead of throwing

Co-authored-by: Dan Balasescu <smoogipoo@smgi.me>
This commit is contained in:
Dean Herbert
2019-08-09 12:56:47 +09:00
committed by GitHub
6 changed files with 252 additions and 253 deletions

View File

@ -482,5 +482,17 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.AreEqual(hitObjects[0].Samples[0].Bank, hitObjects[0].Samples[1].Bank);
}
}
[Test]
public void TestInvalidEventStillPasses()
{
var decoder = new LegacyBeatmapDecoder { ApplyOffsets = false };
using (var badResStream = TestResources.OpenResource("invalid-events.osu"))
using (var badStream = new StreamReader(badResStream))
{
Assert.DoesNotThrow(() => decoder.Decode(badStream));
}
}
}
}

View File

@ -0,0 +1,14 @@
osu file format v14
[Events]
bad,event,this,should,fail
//Background and Video events
0,0,"machinetop_background.jpg",0,0
//Break Periods
2,122474,140135
//Storyboard Layer 0 (Background)
this,is,also,bad
//Storyboard Layer 1 (Fail)
//Storyboard Layer 2 (Pass)
//Storyboard Layer 3 (Foreground)
//Storyboard Sound Samples

View File

@ -5,7 +5,6 @@ using System;
using System.IO;
using System.Linq;
using osu.Framework.IO.File;
using osu.Framework.Logging;
using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Objects.Legacy;
using osu.Game.Beatmaps.ControlPoints;
@ -290,8 +289,9 @@ namespace osu.Game.Beatmaps.Formats
string[] split = line.Split(',');
EventType type;
if (!Enum.TryParse(split[0], out type))
throw new InvalidDataException($@"Unknown event type {split[0]}");
throw new InvalidDataException($@"Unknown event type: {split[0]}");
switch (type)
{
@ -318,8 +318,6 @@ namespace osu.Game.Beatmaps.Formats
}
private void handleTimingPoint(string line)
{
try
{
string[] split = line.Split(',');
@ -395,15 +393,6 @@ namespace osu.Game.Beatmaps.Formats
AutoGenerated = timingChange
});
}
catch (FormatException)
{
Logger.Log("A timing point could not be parsed correctly and will be ignored", LoggingTarget.Runtime, LogLevel.Important);
}
catch (OverflowException)
{
Logger.Log("A timing point could not be parsed correctly and will be ignored", LoggingTarget.Runtime, LogLevel.Important);
}
}
private void handleTimingControlPoint(TimingControlPoint newPoint)
{

View File

@ -49,7 +49,7 @@ namespace osu.Game.Beatmaps.Formats
}
catch (Exception e)
{
Logger.Error(e, $"Failed to process line \"{line}\" into {output}");
Logger.Log($"Failed to process line \"{line}\" into {output}: {e.Message}", LoggingTarget.Runtime, LogLevel.Important);
}
}
}

View File

@ -82,8 +82,9 @@ namespace osu.Game.Beatmaps.Formats
storyboardSprite = null;
EventType type;
if (!Enum.TryParse(split[0], out type))
throw new InvalidDataException($@"Unknown event type {split[0]}");
throw new InvalidDataException($@"Unknown event type: {split[0]}");
switch (type)
{

View File

@ -10,7 +10,6 @@ using osu.Game.Beatmaps.Formats;
using osu.Game.Audio;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Logging;
using osu.Framework.MathUtils;
namespace osu.Game.Rulesets.Objects.Legacy
@ -40,8 +39,6 @@ namespace osu.Game.Rulesets.Objects.Legacy
[CanBeNull]
public override HitObject Parse(string text)
{
try
{
string[] split = text.Split(',');
@ -219,10 +216,7 @@ namespace osu.Game.Rulesets.Objects.Legacy
}
if (result == null)
{
Logger.Log($"Unknown hit object type: {type}. Skipped.", level: LogLevel.Error);
return null;
}
throw new InvalidDataException($"Unknown hit object type: {split[3]}");
result.StartTime = startTime;
@ -233,17 +227,6 @@ namespace osu.Game.Rulesets.Objects.Legacy
return result;
}
catch (FormatException)
{
Logger.Log("A hitobject could not be parsed correctly and will be ignored", LoggingTarget.Runtime, LogLevel.Important);
}
catch (OverflowException)
{
Logger.Log("A hitobject could not be parsed correctly and will be ignored", LoggingTarget.Runtime, LogLevel.Important);
}
return null;
}
private void readCustomSampleBanks(string str, SampleBankInfo bankInfo)
{