mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-12 12:28:13 -04:00
Expose core error logger to plugins and report custom criteria errors (#78)
* Expose core error logger to plugins and report custom criteria errors Fixes #77 This adds an error logging method on the IObservatoryCore interface that writes the exception details to ObservatoryCore's central error log (found in `${Documents}/ObservatoryErrorLog.txt`). In addition, added a timestamp to each error log. Also updates the Explorer to report Custom Criteria file load errors and execution errors to the log. Also updates HeraldNotifier to report CacheIndex.json parse failures to the error log as well. * Expand debugging/error logging in Herald; cleanup empty mp3 files Herald crashes if attempting to play 0-byte mp3s so if detected, delete, re-request (empty files can occur in some azure failure cases (ie. out of quota). Trap and log errors in other places in HeraldQueue to avoid hard crashes due to weird and wonderful unexpected stuff.
This commit is contained in:
@ -19,15 +19,18 @@ namespace Observatory.Herald
|
||||
private string ApiEndpoint;
|
||||
private DirectoryInfo cacheLocation;
|
||||
private int cacheSize;
|
||||
|
||||
internal SpeechRequestManager(HeraldSettings settings, HttpClient httpClient, string cacheFolder)
|
||||
private Action<Exception, String> ErrorLogger;
|
||||
|
||||
internal SpeechRequestManager(
|
||||
HeraldSettings settings, HttpClient httpClient, string cacheFolder, Action<Exception, String> errorLogger)
|
||||
{
|
||||
ApiKey = ObservatoryAPI.ApiKey;
|
||||
ApiEndpoint = settings.ApiEndpoint;
|
||||
this.httpClient = httpClient;
|
||||
cacheSize = Math.Max(settings.CacheSize, 1);
|
||||
cacheLocation = new DirectoryInfo(cacheFolder);
|
||||
|
||||
ErrorLogger = errorLogger;
|
||||
|
||||
if (!Directory.Exists(cacheLocation.FullName))
|
||||
{
|
||||
Directory.CreateDirectory(cacheLocation.FullName);
|
||||
@ -49,7 +52,19 @@ namespace Observatory.Herald
|
||||
|
||||
var audioFilename = cacheLocation + ssmlHash + ".mp3";
|
||||
|
||||
if (!File.Exists(audioFilename))
|
||||
FileInfo audioFileInfo = null;
|
||||
if (File.Exists(audioFilename))
|
||||
{
|
||||
audioFileInfo = new FileInfo(audioFilename);
|
||||
if (audioFileInfo.Length == 0)
|
||||
{
|
||||
File.Delete(audioFilename);
|
||||
audioFileInfo = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (audioFileInfo == null)
|
||||
{
|
||||
using StringContent request = new(ssml)
|
||||
{
|
||||
@ -71,10 +86,10 @@ namespace Observatory.Herald
|
||||
{
|
||||
throw new PluginException("Herald", "Unable to retrieve audio data.", new Exception(response.StatusCode.ToString() + ": " + response.ReasonPhrase));
|
||||
}
|
||||
|
||||
audioFileInfo = new FileInfo(audioFilename);
|
||||
}
|
||||
|
||||
UpdateAndPruneCache(new FileInfo(audioFilename));
|
||||
UpdateAndPruneCache(audioFileInfo);
|
||||
|
||||
return audioFilename;
|
||||
}
|
||||
@ -231,6 +246,7 @@ namespace Observatory.Herald
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
cacheIndex = new();
|
||||
ErrorLogger(ex, "deserializing CacheIndex.json");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user