Copilot commented on code in PR #12650:
URL: https://github.com/apache/cloudstack/pull/12650#discussion_r3971061704


##########
server/src/main/java/com/cloud/template/TemplateManagerImpl.java:
##########
@@ -1702,7 +1702,7 @@ public VirtualMachineTemplate 
createPrivateTemplate(CreateTemplateCmd command) t
             }
             DataStore store = 
_dataStoreMgr.getImageStoreWithFreeCapacity(zoneId);
             if (store == null) {
-                throw new CloudRuntimeException("cannot find an image store 
for zone " + zoneId);
+                throwExceptionForImageStoreObtentionFailure(zoneId, "create 
template");

Review Comment:
   The user-facing message is built from a free-form `operation` string, which 
makes the final error text easy to phrase inconsistently (e.g., missing 
articles: “Failed to upload volume.”). Prefer passing a fully-formed user 
message (or using an enum/constant set of operations mapped to well-phrased 
messages like “Failed to upload the volume.” / “Failed to create the 
template.”) so the thrown error remains consistently grammatical and easier to 
maintain.



##########
server/src/main/java/com/cloud/template/TemplateManagerImpl.java:
##########
@@ -2479,4 +2479,9 @@ public VirtualMachineTemplate 
linkUserDataToTemplate(LinkUserDataToTemplateCmd c
 
         return _tmpltDao.findById(template.getId());
     }
+
+    private void throwExceptionForImageStoreObtentionFailure(Long zoneId, 
String operation) {
+        logger.error("Cannot find an image store for zone [{}] while trying to 
{}.", zoneId, operation);
+        throw new CloudRuntimeException(String.format("Failed to %s. Please 
contact the cloud administrator.", operation));

Review Comment:
   The user-facing message is built from a free-form `operation` string, which 
makes the final error text easy to phrase inconsistently (e.g., missing 
articles: “Failed to upload volume.”). Prefer passing a fully-formed user 
message (or using an enum/constant set of operations mapped to well-phrased 
messages like “Failed to upload the volume.” / “Failed to create the 
template.”) so the thrown error remains consistently grammatical and easier to 
maintain.



##########
server/src/main/java/com/cloud/template/TemplateManagerImpl.java:
##########
@@ -2479,4 +2479,9 @@ public VirtualMachineTemplate 
linkUserDataToTemplate(LinkUserDataToTemplateCmd c
 
         return _tmpltDao.findById(template.getId());
     }
+
+    private void throwExceptionForImageStoreObtentionFailure(Long zoneId, 
String operation) {

Review Comment:
   The method name uses `Obtention`, which is uncommon/unclear in English API 
naming. Consider renaming to something more standard like 
`throwExceptionForImageStoreAcquisitionFailure` / `...RetrievalFailure` / 
`...LookupFailure` to improve readability and consistency.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to