From 6fd7804d6c02d9d25e4465a0c40585063c93996b Mon Sep 17 00:00:00 2001 From: Gervasio Marchand Date: Thu, 9 Feb 2023 09:26:25 -0300 Subject: [PATCH] fix NRE when OrderedItems is null (and log it, I'm curious) (#38) --- src/Program.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index 4d6c5cd..66e526a 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -121,13 +121,19 @@ await Parallel.ForEachAsync(sitesTags, new ParallelOptions{MaxDegreeOfParallelis return; } - int count = 0; - foreach (var statusLink in data.OrderedItems.Where(i=>!imported.Contains(i))) + if (data.OrderedItems == null) + { + Console.WriteLine($"Got null on OrderedItems when pulling #{tag} posts from {site}"); + return; + } + + var count = 0; + foreach (var statusLink in data.OrderedItems.Where(i => !imported.Contains(i))) { statusesToLoadBag.Add(statusLink); count++; } - + Console.WriteLine($"Retrieved {count} new statuses from {site} with hashtag #{tag}"); }); @@ -164,7 +170,7 @@ File.WriteAllLines(importedPath, importedList); public class TagResponse { - public string[] OrderedItems { get; } + public string[]? OrderedItems { get; } public TagResponse(string[] orderedItems) {