Repository: microsoft/onnxruntime
File: onnxruntime/core/session/plugin_ep/ep_factory_webgpu.cc (C++)

Code before:
}

OrtStatus* WebGpuEpFactory::CreateIExecutionProvider(const OrtHardwareDevice* const* /*devices*/,
                                                     const OrtKeyValuePairs* const* /*ep_metadata_pairs*/,
                                                     size_t num_devices,
                                                     const OrtSessionOptions* session_options,
                                                     const OrtLogger* session_logger,
                                                     std::unique_ptr<IExecutionProvider>* ep) noexcept {
  *ep = nullptr;

  if (num_devices != 1) {
    return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT,
                                 "WebGPU EP factory currently only supports one device at a time.");
  }

  auto webgpu_ep_factory = WebGpuProviderFactoryCreator::Create(session_options->value.config_options);
  *ep = webgpu_ep_factory->CreateProvider();
  (*ep)->SetLogger(session_logger->ToInternal());

  return nullptr;
}

OrtStatus* WebGpuEpFactory::CreateDataTransfer(_Outptr_result_maybenull_ OrtDataTransferImpl** data_transfer) noexcept {
  // Call the WebGPU provider's C API to create the data transfer
  // This is implemented in the WebGPU provider backend which has access to WebGPU headers
  *data_transfer = OrtWebGpuCreateDataTransfer();
  return nullptr;
}

}  // namespace onnxruntime

#endif  // USE_WEBGPU


Review comment (bug):
if return value is `nullptr`, it should be an error. assigning `data_transfer` does not report the error (it's the default behavior)

API version mismatch is a fatal error so use ORT_ENFORCE on the return value 

Code after:
}

OrtStatus* WebGpuEpFactory::CreateIExecutionProvider(const OrtHardwareDevice* const* /*devices*/,
                                                     const OrtKeyValuePairs* const* /*ep_metadata_pairs*/,
                                                     size_t num_devices,
                                                     const OrtSessionOptions* session_options,
                                                     const OrtLogger* session_logger,
                                                     std::unique_ptr<IExecutionProvider>* ep) noexcept {
  *ep = nullptr;

  if (num_devices != 1) {
    return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT,
                                 "WebGPU EP factory currently only supports one device at a time.");
  }

  auto webgpu_ep_factory = WebGpuProviderFactoryCreator::Create(session_options->value.config_options);
  *ep = webgpu_ep_factory->CreateProvider();
  (*ep)->SetLogger(session_logger->ToInternal());

  return nullptr;
}

OrtStatus* WebGpuEpFactory::CreateDataTransfer(_Outptr_result_maybenull_ OrtDataTransferImpl** data_transfer) noexcept {
  // Call the WebGPU provider's C API to create the data transfer
  // This is implemented in the WebGPU provider backend which has access to WebGPU headers
  *data_transfer = OrtWebGpuCreateDataTransfer();

  // API version mismatch is a fatal error - return error status if creation failed
  if (*data_transfer == nullptr) {
    return OrtApis::CreateStatus(ORT_RUNTIME_EXCEPTION,
                                 "Failed to create WebGPU data transfer - API version mismatch.");
  }

  return nullptr;
}

}  // namespace onnxruntime

#endif  // USE_WEBGPU