From 6a60ab3ce72977bcc8a5eb26e919109fef054d3d Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 17 Mar 2021 20:50:05 +0900 Subject: [PATCH] error handling --- .../UniGLTF/IO/ImporterContextExtensions.cs | 9 +----- Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs | 29 ++++++++++++++----- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs index 4cc1e306d..900440fe3 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContextExtensions.cs @@ -18,14 +18,7 @@ namespace UniGLTF } if (task.IsFaulted) { - if (task.Exception is AggregateException ae && ae.InnerExceptions.Count == 1) - { - throw ae.InnerException; - } - else - { - throw task.Exception; - } + throw new AggregateException(task.Exception); } #if VRM_DEVELOP diff --git a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs index d68067a1a..acab2b4fb 100644 --- a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs +++ b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs @@ -35,7 +35,25 @@ namespace UniGLTF } } - static void Load(FileInfo gltf) + static void Message(string path, Exception exception) + { + while (exception.InnerException != null) + { + exception = exception.InnerException; + } + + if (exception is UniGLTFNotSupportedException ex) + { + // skip + Debug.LogWarning($"LoadError: {path}: {ex}"); + } + else + { + Debug.LogError($"LoadError: {path}: {exception}"); + } + } + + static void Load(FileInfo gltf, DirectoryInfo root) { var parser = new GltfParser(); try @@ -55,14 +73,9 @@ namespace UniGLTF importer.Load(); } } - catch (UniGLTFNotSupportedException) - { - // skip - } catch (Exception ex) { - Debug.LogError($"LoadError: {gltf}"); - Debug.LogException(ex); + Message(gltf.FullName.Substring(root.FullName.Length), ex); } } @@ -82,7 +95,7 @@ namespace UniGLTF foreach (var gltf in EnumerateGltfFiles(root)) { - Load(gltf); + Load(gltf, root); } } }