-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add failure text to the end of the metadata document if decompilation fails #24188
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,15 @@ public async Task<MetadataAsSourceFile> GetGeneratedFileAsync(Project project, I | |
} | ||
catch (Exception e) when (FatalError.ReportWithoutCrashUnlessCanceled(e)) | ||
{ | ||
// Insert the exception message at the top of the fallback Metadata As Source document to | ||
// help with diagnosing failures. When the generated source is added to the document, this | ||
// comment will end up at the bottom. | ||
var failureText = e.ToString(); | ||
var failureTextAsComment = "// " + failureText.Replace("\n", "\n// ") + Environment.NewLine; | ||
|
||
var sourceText = await temporaryDocument.GetTextAsync(cancellationToken).ConfigureAwait(false); | ||
temporaryDocument = temporaryDocument.WithText(sourceText.Replace(new TextSpan(0, 0), failureTextAsComment)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file is empty up to this point, right? So the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might or might not be empty at this point. The comment already says it's placed at the top (which can be seen) and ends up at the bottom (covered by tests). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When is it not already empty? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Insert this at the top" implies there's something after our insertion point, but the test doesn't show anything after. Either we can add an assert here that the existing file is empty, or we're missing a test case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not aware of a case where it's not empty here. However, the code added by this pull request adheres to the stated behavior whether or not the document is empty at this point. |
||
|
||
useDecompiler = false; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry one more thing that would be nice: add some text along the lines of "the decompilation failed, and here was the failure". Otherwise people might wonder why there's a random exception at the end of the file.