@@ -331,14 +331,23 @@ APPLICATION_INFO::HandleShadowCopy(const ShimOptions& options, IHttpContext& pHt
331331 auto shadowCopyBaseDirectory = std::filesystem::directory_entry (shadowCopyPath);
332332 if (!shadowCopyBaseDirectory.exists ())
333333 {
334- LOG_INFOF (L" Attempting to Create Directory" );
335-
336334 auto ret = CreateDirectory (shadowCopyBaseDirectory.path ().wstring ().c_str (), nullptr );
337335 if (!ret)
338336 {
339- LOG_ERRORF (L" Failed to create shadow copy base directory %ls. Error: %d" ,
340- shadowCopyBaseDirectory.path ().c_str (),
341- GetLastError ());
337+ auto pathString = to_multi_byte_string (shadowCopyBaseDirectory.path (), CP_UTF8);
338+ auto errorCode = std::error_code (GetLastError (), std::system_category ());
339+ std::string errorMessage = format (" Failed to create shadow copy base directory %s. Error: %s" ,
340+ pathString.c_str (),
341+ errorCode.message ().c_str ());
342+
343+ // TODO: Better substatus code
344+ error.statusCode = 500i16;
345+ error.subStatusCode = 30i16;
346+ error.generalErrorType = format (" ASP.NET Core app failed to start - Failed to copy to shadow copy directory" );
347+ error.errorReason = format (" Ensure the application pool process model has write permissions for the shadow copy base directory %s" ,
348+ pathString.c_str ());
349+ error.detailedErrorContent = errorMessage;
350+ return std::wstring ();
342351 }
343352 }
344353
@@ -373,7 +382,7 @@ APPLICATION_INFO::HandleShadowCopy(const ShimOptions& options, IHttpContext& pHt
373382 // It could expand to a network drive, or an expanded link folder path
374383 // We already made it an absolute path relative to the physicalPath above
375384 try {
376- // CopyToDirectory throws exception on failure, therefore don't need to check return value
385+ // CopyToDirectory will succeed or throw exception, so return value can be ignored
377386 Environment::CopyToDirectory (physicalPath, shadowCopyPath, options.QueryCleanShadowCopyDirectory (), shadowCopyBaseDirectory.path (), copiedFileCount);
378387 }
379388 catch (const std::system_error& ex)
0 commit comments