Browse Source

Provide better exceptions and messages in case of errors.

pull/1030/head
Siegfried Pammer 7 years ago
parent
commit
89544864bf
  1. 2
      ICSharpCode.Decompiler/IL/ILReader.cs
  2. 2
      ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs
  3. 2
      ICSharpCode.Decompiler/Metadata/PEFile.cs
  4. 7
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlBinaryReader.cs
  5. 2
      ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs
  6. 2
      ILSpy/Analyzers/AnalyzeContextMenuEntry.cs
  7. 10
      ILSpy/Analyzers/AnalyzerSearchTreeNode.cs
  8. 6
      ILSpy/Images/Images.cs

2
ICSharpCode.Decompiler/IL/ILReader.cs

@ -1589,7 +1589,7 @@ namespace ICSharpCode.Decompiler.IL @@ -1589,7 +1589,7 @@ namespace ICSharpCode.Decompiler.IL
return new LdTypeToken(typeSystem.ResolveAsType(token));
if (token.Kind.IsMemberKind())
return new LdMemberToken(typeSystem.ResolveAsMember(token));
throw new NotImplementedException();
throw new BadImageFormatException("Invalid metadata token for ldtoken instruction.");
}
}
}

2
ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs

@ -100,7 +100,7 @@ namespace ICSharpCode.Decompiler.IL @@ -100,7 +100,7 @@ namespace ICSharpCode.Decompiler.IL
void CloneVariables()
{
throw new NotImplementedException();
throw new NotSupportedException("ILFunction.CloneVariables is currently not supported!");
}
public override void WriteTo(ITextOutput output, ILAstWritingOptions options)

2
ICSharpCode.Decompiler/Metadata/PEFile.cs

@ -43,6 +43,8 @@ namespace ICSharpCode.Decompiler.Metadata @@ -43,6 +43,8 @@ namespace ICSharpCode.Decompiler.Metadata
{
this.FileName = fileName ?? throw new ArgumentNullException(nameof(fileName));
this.Reader = reader ?? throw new ArgumentNullException(nameof(reader));
if (!reader.HasMetadata)
throw new ArgumentException("PE file does not contain any metadata!");
this.Metadata = reader.GetMetadataReader();
}

7
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/BamlBinaryReader.cs

@ -8,7 +8,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -8,7 +8,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
{
internal class BamlBinaryReader : BinaryReader
{
// Methods
public BamlBinaryReader(Stream stream)
: base(stream)
{
@ -16,7 +15,8 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -16,7 +15,8 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
public virtual double ReadCompressedDouble()
{
switch (this.ReadByte()) {
byte b = this.ReadByte();
switch (b) {
case 1:
return 0;
case 2:
@ -27,8 +27,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -27,8 +27,9 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
return ReadInt32() * 1E-06;
case 5:
return this.ReadDouble();
default:
throw new BadImageFormatException($"Unexpected byte sequence in ReadCompressedDouble: 0x{b:x}");
}
throw new NotSupportedException();
}
public int ReadCompressedInt32()

2
ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs

@ -467,7 +467,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection @@ -467,7 +467,7 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
int s = reader.ReadInt32();
int t = reader.ReadInt32();
if (((r != 0x600000) || (s != 0x600000)) || (t != 0x600000))
throw new NotSupportedException();
throw new BadImageFormatException("Magic value mismatch!");
initialized = true;
}

2
ILSpy/Analyzers/AnalyzeContextMenuEntry.cs

@ -85,7 +85,7 @@ namespace ICSharpCode.ILSpy.Analyzers @@ -85,7 +85,7 @@ namespace ICSharpCode.ILSpy.Analyzers
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedEventTreeNode(ed));
break;
default:
throw new NotSupportedException();
throw new ArgumentOutOfRangeException(nameof(entity), $"Entity {entity.GetType().FullName} is not supported.");
}
}
}

10
ILSpy/Analyzers/AnalyzerSearchTreeNode.cs

@ -68,9 +68,13 @@ namespace ICSharpCode.ILSpy.Analyzers @@ -68,9 +68,13 @@ namespace ICSharpCode.ILSpy.Analyzers
}
}
AnalyzerTreeNode EntityTreeNodeFactory(IEntity result)
AnalyzerTreeNode EntityTreeNodeFactory(IEntity entity)
{
switch (result) {
if (entity == null) {
throw new ArgumentNullException(nameof(entity));
}
switch (entity) {
case ITypeDefinition td:
return new AnalyzedTypeTreeNode(td) {
Language = this.Language
@ -92,7 +96,7 @@ namespace ICSharpCode.ILSpy.Analyzers @@ -92,7 +96,7 @@ namespace ICSharpCode.ILSpy.Analyzers
Language = this.Language
};
default:
throw new NotSupportedException();
throw new ArgumentOutOfRangeException(nameof(entity), $"Entity {entity.GetType().FullName} is not supported.");
}
}

6
ILSpy/Images/Images.cs

@ -168,7 +168,7 @@ namespace ICSharpCode.ILSpy @@ -168,7 +168,7 @@ namespace ICSharpCode.ILSpy
baseImage = Images.StaticClass;
break;
default:
throw new NotSupportedException();
throw new ArgumentOutOfRangeException(nameof(icon), $"TypeIcon.{icon} is not supported!");
}
return baseImage;
@ -238,7 +238,7 @@ namespace ICSharpCode.ILSpy @@ -238,7 +238,7 @@ namespace ICSharpCode.ILSpy
baseImage = Images.Event;
break;
default:
throw new NotSupportedException();
throw new ArgumentOutOfRangeException(nameof(icon), $"MemberIcon.{icon} is not supported!");
}
return baseImage;
@ -303,7 +303,7 @@ namespace ICSharpCode.ILSpy @@ -303,7 +303,7 @@ namespace ICSharpCode.ILSpy
overlayImage = Images.OverlayCompilerControlled;
break;
default:
throw new NotSupportedException();
throw new ArgumentOutOfRangeException(nameof(overlay), $"AccessOverlayIcon.{overlay} is not supported!");
}
return overlayImage;
}

Loading…
Cancel
Save