sillsdev / LfMerge

Send/Receive for languageforge.org
MIT License
2 stars 4 forks source link

Correctly handle comments on a LexEntry that doesn't have a lexeme #212

Open rmunn opened 2 years ago

rmunn commented 2 years ago

One project failed Send/Receive on the line var lexeme = GetLexEntry(comment.EntryRef).Lexeme.FirstNonEmptyString(); in ComvertMongoToLcmComments.cs, with a NullReferenceException. On investigation, the entry was missing a lexeme in Mongo, and so Lexeme.FirstNonEmptyString() was null.FirstNonEmptyString(). The only thing that the lexeme variable is used for in that code is fo human-readable text, so that line should be replaced with:

var lexeme = GetLexEntry(comment.EntryRef).Lexeme;
var lexemeText = (lexeme == null) ? "(no lexeme)" : FirstNonEmptyString();

Or, once we can use modern versions of C# (i.e. once we drop Mono 5):

var lexeme = GetLexEntry(comment.EntryRef)?.Lexeme?.FirstNonEmptyString() ?? "(no lexeme)";
jasonleenaylor commented 2 years ago

I'm pretty sure you can already use that with mono5. There are other new features that you can't.

megahirt commented 2 years ago

This seams like the fix is already thought out here.

Error repro steps:

@josephmyers this seems like a good candidate for testing out the "skip exceptions" feature that we recently developed.

megahirt commented 1 year ago

I wonder if the steps to trigger a "comment exception" could be:

c.f. https://github.com/sillsdev/web-languageforge/issues/1444