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

Restore write-resource-to-text tests #4830

Merged
merged 8 commits into from
Oct 24, 2019

Conversation

rainersigwald
Copy link
Member

Closes #308 by re-enabling the tests.

Closes dotnet#308 by re-enabling the tests.
@rainersigwald
Copy link
Member Author

I thought this worked on my machine but I was testing desktop framework. Sigh. Pulling for now.

This was working for ResXResourceReader-based resources but not the new reader.
There are various failures possible in ReadResources, but the existing test applies only to full framework
@rainersigwald rainersigwald reopened this Oct 21, 2019
Uses the existing category from Xunit.NetCore.Extensions
These situations logged confusing English-only errors; now they fail and the error can get localized.
Copy link
Member

@Forgind Forgind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I had just a few questions.

@@ -2988,7 +2994,7 @@ private void ReadResources(String filename, bool shouldUseSourcePath, String out
#if FEATURE_ASSEMBLY_LOADFROM
ReadAssemblyResources(filename, outFileOrDir);
#else
_logger.LogError("Reading resources from Assembly not supported on .NET Core MSBuild");
throw new InputFormatNotSupportedException("Reading resources from Assembly not supported on .NET Core MSBuild");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it advantageous to throw instead of just logging an error? Are you trying to reduce duplicate output?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging an error here is nonfatal, so the experience with going through this codepath was:

  1. This error.
  2. Some other odd output when trying to move on.
  3. Another fatal error that didn't directly indicate the problem.

Since there were already exception-based error paths in ProcessFile I opted to add another rather than change everything to error returns.

{
if (assemblyName == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would they be null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what happens if an assembly name can't be extracted from a reference for some reason in PopulateAssemblyNames(). The other codepaths were robust to this situation but this newly-added one wasn't (until running a test revealed the error).

namespace Microsoft.Build.Tasks.ResourceHandling
{
[Serializable]
internal class InputFormatNotSupportedException : Exception
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you can't use FormatException or ArgumentException instead of making your own (empty) new type of exception?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a custom exception type makes detecting this error condition easy using a catch-specific-type block.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracing how it's currently caught, I believe a FormatException will still have the exact same effect.

Also, I don't see anywhere that you try to catch it; do you have plans for adding something like that in the future? If not, you're breaking something that could otherwise be caught by an ArgumentException, failing more cleanly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe a FormatException will still have the exact same effect.

Since it's a standard exception type, other code could insert a FormatException that would then be inadvertently caught and handled as this specific problem, rather than handled at another layer.

Also, I don't see anywhere that you try to catch it

https://github.com/microsoft/msbuild/pull/4830/files#diff-1d2aacce8c88cda3235c1659ea67e164R2606-R2611

If not, you're breaking something that could otherwise be caught by an ArgumentException, failing more cleanly.

This is harder to distinguish since other places could throw ArgumentException inside the big ProcessFile catch block.

@@ -979,6 +979,11 @@
<target state="translated">MSB3190: ClickOnce no admite el nivel de ejecución de solicitudes '{0}'.</target>
<note>{StrBegin="MSB3190: "}</note>
</trans-unit>
<trans-unit id="GenerateResource.CoreSupportsLimitedScenarios">
<source>MSB3824: In order to build with .NET Core, resource inputs must be in .txt or .resx format.</source>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this is supposed to be a localized version. When does that happen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. The loc team periodically (at least once per minor release) does a pass on strings and will submit a PR with updated localizations (#4679 was a recent one). Until that's done the English copy of the string is used.

Docs are here: https://github.com/microsoft/msbuild/blob/master/documentation/wiki/Localization.md

if (string.IsNullOrEmpty(resgenFile))
{
resgenFile = GetTempFileName(".resx");
File.Delete(resgenFile);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) Is this line necessary? According to the File.WriteAllText documentation, even if the file did exist it would be overwritten

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's preexisting but no, I don't think it is. I'll remove.

@rainersigwald
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rainersigwald rainersigwald merged commit 455f5be into dotnet:master Oct 24, 2019
@rainersigwald rainersigwald deleted the fix-308 branch October 24, 2019 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GenerateResource does not fail when converting binary .resx resources to .txt resources
3 participants