Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit LogErrorFromException #2238

Open
jonpryor opened this issue Sep 27, 2018 · 1 comment
Open

Audit LogErrorFromException #2238

jonpryor opened this issue Sep 27, 2018 · 1 comment
Labels
Area: xamarin-android Build Issues building the xamarin-android repo *itself*.

Comments

@jonpryor
Copy link
Member

An occasional error that we'll see in the build logs is:

xamarin-android/build-tools/scripts/TestApks.targets(249,5): error : Root element is missing.

This message is borderline infuriating, because TestApks.targets(249,5) is a <RenameTestCases/> task execution. How is there a missing root element?!

Turns Out™ that this is MSBuild being helpful: <RenameTestCases/>'s Execute() method has a catch block which only calls Log.LogErrorFromException():

https://github.com/xamarin/xamarin-android/blob/30eea71177853a73ab07911d49be1c1707c300f0/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/RenameTestCases.cs#L43-L45

Log.LogErrorFromException() helpfully provides the filename and line information for where the task was invoked -- hence TestApks.targets(249,5) -- but the output isn't clear that there's an intervening task here. For months (years?) I've been laboring under the assumption that this Root element is missing message is being generated from MSBuild.

That is not the case. The error is reported from our task.

The Real™ problem is that the "UI" reporting of the error is inscrutable.

In short, Log.LogErrorFromException() should be considered a code smell: if it's the only thing present, then when it logs an error, the way that the error is reported -- which includes the MSBuild .targets callsite location, but no mention that this is being reported from the task that executed -- is extremely misleading and unhelpful.

We should audit our codebase for all uses of Log.LogErrorFromException() and ensure that when we do use it, we provide useful "error context" as well, so that when an error occurs, more than just Exception.Message ("Root element is missing") and the .targets call site is provided.

@jonpryor jonpryor assigned jonpryor and brendanzagaeski and unassigned jonpryor Sep 27, 2018
jonpryor added a commit to jonpryor/xamarin-android that referenced this issue Sep 27, 2018
Context: dotnet#2238
Context: 8905dfa
Context: 31a23ca

For *months*, I would occasionally see an error message which would
infuriate me, because it didn't make sense to my feeble mind:

	xamarin-android/build-tools/scripts/TestApks.targets(223,5): error : Root element is missing

The actual line number isn't relevant and changes over time, but what
*killed* me is that, *somehow*, there'd be (presumably) invalid XML
...in the middle of a `.targets` file?

Does that make any sense at all?

(No, that does not make sense, adding to the infuriation.)

Turns Out™ that I was *misreading* the message: The *task* at e.g.
`TestApks.targets` line 223 was reporting an exception with the
message text "Root element is missing."

However, *because* the task name wasn't mentioned in the error
message, this very significant fact escaped my attention.

This messaging structure is how `Log.LogErrorFromException()` works.
As such, we should modify how we're using it, to reduce confusion.

In the case of `<RenameTestCases/>`:

 1. Add an additional `LogError("Unable to process...")` message, so
    that `Root element is missing` won't be "alone" without context.

 2. Generate an output NUnit XML file which contains an error message.

Hopefully, by generating such an XML file, the Jenkins Test Results
page will show *an* error.  (Not necessarily a helpful one, but a
less-than-helpful error is better than none at all when *something*
has gone wrong...)
dellis1972 pushed a commit that referenced this issue Sep 28, 2018
…#2239)

Context: #2238
Context: 8905dfa
Context: 31a23ca

For *months*, I would occasionally see an error message which would
infuriate me, because it didn't make sense to my feeble mind:

	xamarin-android/build-tools/scripts/TestApks.targets(223,5): error : Root element is missing

The actual line number isn't relevant and changes over time, but what
*killed* me is that, *somehow*, there'd be (presumably) invalid XML
...in the middle of a `.targets` file?

Does that make any sense at all?

(No, that does not make sense, adding to the infuriation.)

Turns Out™ that I was *misreading* the message: The *task* at e.g.
`TestApks.targets` line 223 was reporting an exception with the
message text "Root element is missing."

However, *because* the task name wasn't mentioned in the error
message, this very significant fact escaped my attention.

This messaging structure is how `Log.LogErrorFromException()` works.
As such, we should modify how we're using it, to reduce confusion.

In the case of `<RenameTestCases/>`:

 1. Add an additional `LogError("Unable to process...")` message, so
    that `Root element is missing` won't be "alone" without context.

 2. Generate an output NUnit XML file which contains an error message.

Hopefully, by generating such an XML file, the Jenkins Test Results
page will show *an* error.  (Not necessarily a helpful one, but a
less-than-helpful error is better than none at all when *something*
has gone wrong...)
@jonathanpeppers jonathanpeppers added the Area: xamarin-android Build Issues building the xamarin-android repo *itself*. label Sep 28, 2018
@jonathanpeppers jonathanpeppers added this to the d16-0 milestone Sep 28, 2018
@jonathanpeppers jonathanpeppers modified the milestones: d16-0, d16-1 Jan 28, 2019
@pjcollins pjcollins modified the milestones: d16-1, Under Consideration Jun 20, 2019
@pjcollins
Copy link
Member

It looks like we've still got some occurrences of Log.LogErrorFromException that we may want to modify based on a quick search: https://github.com/xamarin/xamarin-android/search?q=Log.LogErrorFromException%28%29&unscoped_q=Log.LogErrorFromException%28%29

Updating milestones for further consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: xamarin-android Build Issues building the xamarin-android repo *itself*.
Projects
None yet
Development

No branches or pull requests

4 participants