提交 999cba8b 编写于 作者: J Jason Malinowski

Include the underlying exception when giving ERR_PeWritingFailure

上级 67f9831e
......@@ -7045,6 +7045,15 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to An error occurred while writing the output file: {0}.
/// </summary>
internal static string ERR_PeWritingFailure {
get {
return ResourceManager.GetString("ERR_PeWritingFailure", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Neither &apos;is&apos; nor &apos;as&apos; is valid on pointer types.
/// </summary>
......
......@@ -4676,6 +4676,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<value>Combined length of user strings used by the program exceeds allowed limit. Try to decrease use of string literals.</value>
</data>
<data name="ERR_PeWritingFailure" xml:space="preserve">
<value>An error occurred while writing the output file.</value>
<value>An error occurred while writing the output file: {0}</value>
</data>
</root>
......@@ -16,6 +16,9 @@ public partial class InternalsVisibleToAndStrongNameTests : CSharpTestBase
private class StrongNameProviderWithBadInputStream : StrongNameProvider
{
private StrongNameProvider _underlyingProvider;
public Exception ThrownException;
public StrongNameProviderWithBadInputStream(StrongNameProvider underlyingProvider)
{
_underlyingProvider = underlyingProvider;
......@@ -27,7 +30,8 @@ public StrongNameProviderWithBadInputStream(StrongNameProvider underlyingProvide
internal override Stream CreateInputStream()
{
throw new IOException("This is a test IOException");
ThrownException = new IOException("This is a test IOException");
throw ThrownException;
}
internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, CommonMessageProvider messageProvider) =>
......@@ -53,9 +57,9 @@ class C
var comp = CreateCompilationWithMscorlib(src,
options: options);
comp.VerifyEmitDiagnostics(
comp.Emit(new MemoryStream()).Diagnostics.Verify(
// error CS8104: An error occurred while writing the Portable Executable file.
Diagnostic(ErrorCode.ERR_PeWritingFailure).WithArguments("This is a test IOException").WithLocation(1, 1));
Diagnostic(ErrorCode.ERR_PeWritingFailure).WithArguments(testProvider.ThrownException.ToString()).WithLocation(1, 1));
}
}
}
......@@ -2701,13 +2701,13 @@ public void BrokenOutStream()
var result = compilation.Emit(output);
result.Diagnostics.Verify(
// error CS8104: An error occurred while writing the Portable Executable file.
Diagnostic(ErrorCode.ERR_PeWritingFailure).WithArguments("I/O error occurred.").WithLocation(1, 1));
Diagnostic(ErrorCode.ERR_PeWritingFailure).WithArguments(output.ThrownException.ToString()).WithLocation(1, 1));
output.BreakHow = 1;
output.BreakHow = BrokenStream.BreakHowType.ThrowOnSetPosition;
result = compilation.Emit(output);
result.Diagnostics.Verify(
// error CS8104: An error occurred while writing the Portable Executable file.
Diagnostic(ErrorCode.ERR_PeWritingFailure).WithArguments("Specified method is not supported.").WithLocation(1, 1));
Diagnostic(ErrorCode.ERR_PeWritingFailure).WithArguments(output.ThrownException.ToString()).WithLocation(1, 1));
// disposed stream is not writable
var outReal = new MemoryStream();
......@@ -2723,7 +2723,7 @@ public void BrokenPDBStream()
var output = new MemoryStream();
var pdb = new BrokenStream();
pdb.BreakHow = 2;
pdb.BreakHow = BrokenStream.BreakHowType.ThrowOnSetLength;
var result = compilation.Emit(output, pdb);
// error CS0041: Unexpected error writing debug information -- 'Exception from HRESULT: 0x806D0004'
......@@ -2969,12 +2969,12 @@ public static void Main()
}";
var compilation = CreateCompilationWithMscorlib(source);
var broken = new BrokenStream();
broken.BreakHow = 0;
broken.BreakHow = BrokenStream.BreakHowType.ThrowOnWrite;
var result = compilation.Emit(broken);
Assert.False(result.Success);
result.Diagnostics.Verify(
// error CS8104: An error occurred while writing the Portable Executable file.
Diagnostic(ErrorCode.ERR_PeWritingFailure).WithArguments("I/O error occurred.").WithLocation(1, 1));
Diagnostic(ErrorCode.ERR_PeWritingFailure).WithArguments(broken.ThrownException.ToString()).WithLocation(1, 1));
}
}
}
......@@ -1908,7 +1908,7 @@ private static EmitResult ToEmitResultAndFree(DiagnosticBag diagnostics, bool su
}
catch (Cci.PeWritingException e)
{
diagnostics.Add(MessageProvider.CreateDiagnostic(MessageProvider.ERR_PeWritingFailure, Location.None, e.Message));
diagnostics.Add(MessageProvider.CreateDiagnostic(MessageProvider.ERR_PeWritingFailure, Location.None, e.InnerException.ToString()));
return false;
}
catch (ResourceException e)
......
......@@ -9009,6 +9009,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
'''<summary>
''' Looks up a localized string similar to An error occurred while writing the output file: {0}.
'''</summary>
Friend ReadOnly Property ERR_PeWritingFailure() As String
Get
Return ResourceManager.GetString("ERR_PeWritingFailure", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Cannot embed interop types from assembly &apos;{0}&apos; because it is missing the &apos;{1}&apos; attribute..
'''</summary>
......
......@@ -5348,6 +5348,6 @@
<value>Combined length of user strings used by the program exceeds allowed limit. Try to decrease use of string or XML literals.</value>
</data>
<data name="ERR_PeWritingFailure" xml:space="preserve">
<value>An error occurred while writing the output file.</value>
<value>An error occurred while writing the output file: {0}</value>
</data>
</root>
......@@ -11,6 +11,8 @@ Partial Public Class InternalsVisibleToAndStrongNameTests
Private Class StrongNameProviderWithBadInputStream
Inherits StrongNameProvider
Private _underlyingProvider As StrongNameProvider
Public Property ThrownException As Exception
Public Sub New(underlyingProvider As StrongNameProvider)
_underlyingProvider = underlyingProvider
End Sub
......@@ -25,7 +27,8 @@ Partial Public Class InternalsVisibleToAndStrongNameTests
End Function
Friend Overrides Function CreateInputStream() As Stream
Throw New IOException("This is a test IOException")
ThrownException = New IOException("This is a test IOException")
Throw ThrownException
End Function
Friend Overrides Function CreateKeys(keyFilePath As String, keyContainerName As String, messageProvider As CommonMessageProvider) As StrongNameKeys
......@@ -53,8 +56,8 @@ End Class
</file>
</compilation>, options:=options)
comp.VerifyEmitDiagnostics(
Diagnostic(ERRID.ERR_PeWritingFailure).WithArguments("This is a test IOException").WithLocation(1, 1))
comp.Emit(New MemoryStream()).Diagnostics.Verify(
Diagnostic(ERRID.ERR_PeWritingFailure).WithArguments(testProvider.ThrownException.ToString()).WithLocation(1, 1))
End Sub
......
......@@ -2939,14 +2939,14 @@ End Module
Dim emitResult As EmitResult
Using output = New BrokenStream()
output.BreakHow = 0
output.BreakHow = BrokenStream.BreakHowType.ThrowOnWrite
emitResult = compilation.Emit(output, Nothing, Nothing, Nothing)
End Using
CompilationUtils.AssertTheseDiagnostics(emitResult.Diagnostics,
CompilationUtils.AssertTheseDiagnostics(emitResult.Diagnostics,
<expected>
BC37256: An error occurred while writing the output file.
BC37256: An error occurred while writing the output file: <%= output.ThrownException.ToString() %>
</expected>)
End Using
End Sub
End Class
End Namespace
......@@ -7,7 +7,15 @@ namespace Roslyn.Test.Utilities
{
internal class BrokenStream : Stream
{
public int BreakHow;
public enum BreakHowType
{
ThrowOnSetPosition,
ThrowOnWrite,
ThrowOnSetLength
}
public BreakHowType BreakHow;
public Exception ThrownException { get; private set; }
public override bool CanRead
{
......@@ -44,8 +52,11 @@ public override long Position
}
set
{
if (BreakHow == 1)
throw new NotSupportedException();
if (BreakHow == BreakHowType.ThrowOnSetPosition)
{
ThrownException = new NotSupportedException();
throw ThrownException;
}
}
}
......@@ -61,14 +72,20 @@ public override long Seek(long offset, SeekOrigin origin)
public override void SetLength(long value)
{
if (BreakHow == 2)
throw new IOException();
if (BreakHow == BreakHowType.ThrowOnSetLength)
{
ThrownException = new IOException();
throw ThrownException;
}
}
public override void Write(byte[] buffer, int offset, int count)
{
if (BreakHow == 0)
throw new IOException();
if (BreakHow == BreakHowType.ThrowOnWrite)
{
ThrownException = new IOException();
throw ThrownException;
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册