From 029c5029685b365edddf093f865f003294669ff6 Mon Sep 17 00:00:00 2001 From: Matt Lyons Date: Fri, 13 Dec 2024 14:07:12 -0600 Subject: [PATCH] Improve versification handling and stop crashing on Debug.Assert (#1397) --- c-sharp/JsonUtils/VerseRefConverter.cs | 2 +- c-sharp/Program.cs | 14 +++++++------- c-sharp/Projects/ParatextProjectDataProvider.cs | 2 ++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/c-sharp/JsonUtils/VerseRefConverter.cs b/c-sharp/JsonUtils/VerseRefConverter.cs index 9c2d6a126d..98da1d1468 100644 --- a/c-sharp/JsonUtils/VerseRefConverter.cs +++ b/c-sharp/JsonUtils/VerseRefConverter.cs @@ -104,7 +104,7 @@ JsonSerializerOptions options bookName, chapterNum.Value.ToString(), verse ?? verseNum!.Value.ToString(), - new ScrVers(versification) + string.IsNullOrEmpty(versification) ? null : new ScrVers(versification) ); } diff --git a/c-sharp/Program.cs b/c-sharp/Program.cs index 76e77fb14b..55d2c784fa 100644 --- a/c-sharp/Program.cs +++ b/c-sharp/Program.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using Paranext.DataProvider.Checks; using Paranext.DataProvider.NetworkObjects; using Paranext.DataProvider.Projects; @@ -16,13 +17,12 @@ public static async Task Main() Console.WriteLine("Paranext data provider starting up"); Thread.CurrentThread.Name = "Main"; - // Turn on additional logging to help diagnose failures on macOS - if (OperatingSystem.IsMacOS()) - { - System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.ConsoleTraceListener()); - System.Diagnostics.Trace.AutoFlush = true; - System.Diagnostics.Trace.WriteLine("Trace logging enabled"); - } + var listener = new ConsoleTraceListener { TraceOutputOptions = TraceOptions.DateTime }; + // Clear the default listeners to stop Debug.Assert from crashing the app + Trace.Listeners.Clear(); + // Log all trace messages to the console + Trace.Listeners.Add(listener); + Trace.AutoFlush = true; using PapiClient papi = new(); try diff --git a/c-sharp/Projects/ParatextProjectDataProvider.cs b/c-sharp/Projects/ParatextProjectDataProvider.cs index f72364995c..e302b46a2b 100644 --- a/c-sharp/Projects/ParatextProjectDataProvider.cs +++ b/c-sharp/Projects/ParatextProjectDataProvider.cs @@ -606,6 +606,8 @@ Func getTextFromScrText try { var scrText = LocalParatextProjects.GetParatextProject(ProjectDetails.Metadata.Id); + if (verseRef.Versification == null) + verseRef.Versification = scrText.Settings.Versification; return getTextFromScrText(scrText, verseRef); } catch (Exception e) when (e is ArgumentException or ProjectNotFoundException)