Repository navigation
Fix unhandled ArgumentOutOfRangeException when exporting FlameGraph with unrendered canvas - #2339
Conversation
Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
…t namespace usage Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
Brian Robbins (brianrob)
left a comment
There was a problem hiding this comment.
Copilot, please address these comments.
| // Validate that the canvas has a valid size before attempting to export | ||
| if (width <= 0 || height <= 0) | ||
| { | ||
| throw new InvalidOperationException( |
There was a problem hiding this comment.
| throw new InvalidOperationException( | |
| throw new ArgumentOutOfRangeException( |
| { | ||
| throw new InvalidOperationException( | ||
| $"Cannot export flame graph: the canvas has an invalid size (width={width}, height={height}). " + | ||
| "Please ensure the flame graph is visible and has been rendered before attempting to export."); |
There was a problem hiding this comment.
The text here is too long to appear in the status bar. Please use this text: "Please ensure the flame graph is visible and has been rendered before attempting to export."
There was a problem hiding this comment.
Done in 0699b4a - shortened the error message to just the essential guidance
| FlameGraph.Export(FlameGraphCanvas, saveDialog.FileName); | ||
| StatusBar.Log($"Saved flame graph to {saveDialog.FileName}"); | ||
| } | ||
| catch (InvalidOperationException ex) |
There was a problem hiding this comment.
| catch (InvalidOperationException ex) | |
| catch (ArgumentOutOfRangeException ex) |
| try | ||
| { | ||
| // Attempt to export should throw InvalidOperationException with a meaningful message | ||
| var exception = Assert.Throws<InvalidOperationException>(() => |
There was a problem hiding this comment.
| var exception = Assert.Throws<InvalidOperationException>(() => | |
| var exception = Assert.Throws<ArgumentOutOfRangeException>(() => |
…r message Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
Brian Robbins (brianrob)
left a comment
There was a problem hiding this comment.
Copilot, please address these comments.
| { | ||
| throw new ArgumentOutOfRangeException( | ||
| "flameGraphCanvas", | ||
| $"canvas has an invalid size (width={width}, height={height}). Please ensure the flame graph is visible and has been rendered before attempting to export."); |
There was a problem hiding this comment.
| $"canvas has an invalid size (width={width}, height={height}). Please ensure the flame graph is visible and has been rendered before attempting to export."); | |
| $"Canvas has an invalid size (width={width}, height={height}). Please ensure the flame graph is visible and has been rendered before attempting to export."); |
| }); | ||
|
|
||
| // Verify the exception message is helpful | ||
| Assert.Contains("canvas has an invalid size", exception.Message); |
There was a problem hiding this comment.
| Assert.Contains("canvas has an invalid size", exception.Message); | |
| Assert.Contains("Canvas has an invalid size", exception.Message); |
Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
Lee Culver (leculver)
left a comment
There was a problem hiding this comment.
One nitpick, but otherwise looks good to me.
Summary
Fixed unhandled
ArgumentOutOfRangeExceptionthat occurred when saving a FlameGraph with an unrendered or invalid-sized canvas. The fix includes:FlameGraph.Export()to ensure canvas width and height are greater than zero before creatingRenderTargetBitmapArgumentOutOfRangeExceptionwhich matches the original error fromRenderTargetBitmapStatusBar.LogError()nameof()operator for parameter namesAll review comments have been addressed. The changes are minimal, focused, and directly address the reported issue.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.