return proper error when the model path isn't found (#2391)

This commit is contained in:
Brian Martin 2019-11-13 14:57:32 -08:00 committed by GitHub
parent a3a6a97407
commit 895342bf74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -137,6 +137,7 @@ std::unique_ptr<onnx::ModelProto>
WinML::CreateModelProto(
const char* path) {
int file_descriptor;
_set_errno(0); // clear errno
_sopen_s(
&file_descriptor,
path,
@ -144,6 +145,14 @@ WinML::CreateModelProto(
_SH_DENYWR,
_S_IREAD | _S_IWRITE);
errno_t err = 0;
_get_errno(&err);
WINML_THROW_HR_IF_TRUE_MSG(
__HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
err == ENOENT,
"File not found: %s",
path);
WINML_THROW_HR_IF_TRUE_MSG(
E_FAIL,
0 > file_descriptor,