diff --git a/src/libraries/Common/src/Interop/Unix/Interop.IOErrors.cs b/src/libraries/Common/src/Interop/Unix/Interop.IOErrors.cs index 14aeddd5adcf4..6c348f9b16463 100644 --- a/src/libraries/Common/src/Interop/Unix/Interop.IOErrors.cs +++ b/src/libraries/Common/src/Interop/Unix/Interop.IOErrors.cs @@ -159,12 +159,14 @@ internal static Exception GetExceptionForIoErrno(ErrorInfo errorInfo, string? pa goto default; default: - return GetIOException(errorInfo); + return GetIOException(errorInfo, path); } } - internal static Exception GetIOException(Interop.ErrorInfo errorInfo) + internal static Exception GetIOException(Interop.ErrorInfo errorInfo, string? path = null) { - return new IOException(errorInfo.GetErrorMessage(), errorInfo.RawErrno); + string msg = errorInfo.GetErrorMessage(); + return new IOException( + string.IsNullOrEmpty(path) ? msg : $"{msg} : '{path}'", errorInfo.RawErrno); } }