@@ -238,27 +238,25 @@ def _upload_to_oss_with_credentials(
238238 body = response_data ["body" ]
239239 data = body .get ("Data" )
240240 if data is None :
241- print (
242- "\n ❌ Configuration Error: The current RAM user "
243- "is not assigned to target workspace." ,
244- )
245- print (
241+ messages = [
242+ "\n ❌ Configuration Error: "
243+ "The current RAM user is not assigned to target workspace." ,
246244 "Bailian requires RAM users to be associated with "
247245 "at least one workspace to use temporary storage." ,
248- )
249- print ("\n 🔧 How to resolve:" )
250- print (
246+ "\n 🔧 How to resolve:" ,
251247 "1. Ask the primary account to log in to the "
252248 "Bailian Console: https://bailian.console.aliyun.com" ,
253- )
254- print ("2. Go to [Permission Management]" )
255- print ("3. Go to [Add User]" )
256- print ("4. Assign the user to a workspace" )
257- print (
258- "\n 💡 Note: If you are not the primary account holder, "
259- "please contact your administrator to complete this step." ,
260- )
261- print ("=" * 80 )
249+ "2. Go to [Permission Management]" ,
250+ "3. Go to [Add User]" ,
251+ "4. Assign the user to a workspace" ,
252+ "\n 💡 Note: If you are not the primary account holder,"
253+ " please contact your administrator to complete this step." ,
254+ "=" * 80 ,
255+ ]
256+
257+ for msg in messages :
258+ logger .error (msg )
259+
262260 raise ValueError (
263261 "RAM user is not assigned to any workspace in Bailian" ,
264262 )
@@ -336,42 +334,45 @@ def _get_presign_url_and_upload_to_oss(
336334 error_code = error .code
337335 if hasattr (error , "data" ) and isinstance (error .data , dict ):
338336 recommend_url = error .data .get ("Recommend" )
337+
339338 if error_code == "NoPermission" :
340- print ("\n ❌ Permission Denied (NoPermission)" )
341- print (
342- "The current account does not have permission to "
343- "apply for temporary storage (ApplyTempStorageLease)." ,
344- )
345- print ("\n 🔧 How to resolve:" )
346- print (
347- "1. Ask the primary account holder (or an administrator) "
348- "to grant your RAM user the following permission:" ,
349- )
350- print (" - Action: `AliyunBailianDataFullAccess`" )
351- print ("\n 2. Steps to grant permission:" )
352- print (
339+ messages = [
340+ "\n ❌ Permission Denied (NoPermission)" ,
341+ "The current account does not have permission to apply "
342+ "for temporary storage (ApplyTempStorageLease)." ,
343+ "\n 🔧 How to resolve:" ,
344+ "1. Ask the primary account holder (or an administrator)"
345+ " to grant your RAM user the following permission:" ,
346+ " - Action: `AliyunBailianDataFullAccess`" ,
347+ "\n 2. Steps to grant permission:" ,
353348 " - Go to Alibaba Cloud RAM Console: https://ram.console.aliyun.com/users" ,
354- )
355- print (" - Locate your RAM user" )
356- print (
357- " - Click 'Add Permissions' and attach a "
358- "policy that includes `AliyunBailianDataFullAccess`" ,
359- )
360- print ("\n 3. For further diagnostics:" )
349+ " - Locate your RAM user" ,
350+ " - Click 'Add Permissions' and attach a policy that includes "
351+ "`AliyunBailianDataFullAccess`" ,
352+ "\n 3. For further diagnostics:" ,
353+ ]
354+ official_doc_link = "https://help.aliyun.com/zh/ram/"
361355 if recommend_url :
362- print (
356+ messages . append (
363357 f" - Official troubleshooting link: { recommend_url } " ,
364358 )
365359 else :
366- print (
360+ messages . append (
367361 " - Visit the Alibaba Cloud API troubleshooting page" ,
368362 )
369- print (f" - Official document link: { recommend_url } " )
370- print (
371- "\n 💡 Note: If you are not an administrator, please contact your "
372- "cloud account administrator for assistance." ,
363+ messages .append (
364+ f" - Official document link: { official_doc_link or 'N/A' } " ,
373365 )
374- print ("=" * 80 )
366+ messages .append (
367+ "\n 💡 Note: If you are not an administrator, please "
368+ "contact your cloud account administrator for assistance." ,
369+ )
370+ messages .append ("=" * 80 )
371+
372+ # 一次性记录多行日志(每行单独一条日志,便于解析)
373+ for msg in messages :
374+ logger .error (msg )
375+
375376 logger .error ("Original error details: %s" , error )
376377 raise
377378
0 commit comments