Skip to content

OSFileStreamStrategy Seek Error is Confusing and not helpful. #112112

Open
@ProbablePrime

Description

@ProbablePrime

Description

Hello, Apologies if I'm not doing anything correct here but let's get started!

I'm working on a complex system that processes files into more optimal formats for compression and storage, a bug in this code caused it to try to seek to a negative offset position within: OSFileStreamStrategy.Seek

When this occurs, FileStreamHelpers.ThrowInvalidArgument(_fileHandle); occurs.

Which throws a really unhelpful message: The parameter is incorrect. : <file path>.

Image

This caused me to debug around thinking that my file stream was wrong, or that my input file was a corrupt image etc. When in actuality the image is fine, some code elsewhere was just trying to seek negatively.

Reproduction Steps

Attempt to seek a `OSFileStreamStrategy with a negative resultant value.

Seek(-1, SeekOrigin.Begin); should achieve this.

Expected behavior

A better exception message, would be very helpful for developers to more quickly comprehend what's going on.

Actual behavior

Explained in description

Regression?

I am not sure, there is a comment in the area: " // keep throwing the same exception we did when seek was causing actual offset change
" that implies there was a decision point at some point in time.

Known Workarounds

No response

Configuration

.NET 9, Windows 10, x64

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.IOhelp wanted[up-for-grabs] Good issue for external contributors

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions