การรายงานข้อผิดพลาดโดยอัตโนมัติ
คุณสามารถส่งข้อผิดพลาดจากฟังก์ชันไปยัง การรายงานข้อผิดพลาด ดังที่แสดงด้านล่าง
Node.js
Python
หากต้องการรายงานข้อผิดพลาดอย่างละเอียดมากขึ้น คุณสามารถใช้ไคลเอ็นต์การรายงานข้อผิดพลาด ห้องสมุด
คุณดูข้อผิดพลาดที่รายงานได้ในการรายงานข้อผิดพลาดในคอนโซล Google Cloud นอกจากนี้คุณยังดูข้อผิดพลาดที่รายงานจาก ฟังก์ชันที่เจาะจงเมื่อคุณเลือกจากรายการฟังก์ชันในคอนโซล Google Cloud
ข้อยกเว้นที่ไม่ถูกตรวจจับซึ่งเกิดจากฟังก์ชันของคุณจะปรากฏใน "การรายงานข้อผิดพลาด" โปรดทราบว่าข้อยกเว้นบางประเภทที่ไม่มีการจับ (เช่น ข้อยกเว้นที่โยนขึ้นแบบไม่พร้อมกัน) จะทําให้การเริ่มต้นแบบเย็นเกิดขึ้นเมื่อมีการเรียกใช้ฟังก์ชันในอนาคต ซึ่งจะเพิ่มเวลาในการเรียกใช้ฟังก์ชัน
การรายงานข้อผิดพลาดด้วยตนเอง
กำลังส่งไปยัง Cloud Logging
ฟังก์ชัน error
จาก Cloud Functions
logger
SDK จะรายงานข้อผิดพลาดไปยังทั้ง Cloud Logging และการรายงานข้อผิดพลาด หากต้องการใส่บริบทเพิ่มเติมจากข้อผิดพลาดเป็น Structured Data ให้ส่งออบเจ็กต์ข้อผิดพลาดเป็นอาร์กิวเมนต์ที่ 2 ดังนี้
} catch (err) {
// Attach an error object as the second argument
functions.logger.error(
"Unable to read quote from Firestore, sending default instead",
err
);
}