Prompt templates help diagnose complex code errors.

Prompt templates for diagnosing complex code errors emerged as an effective support tool, leveraging the power of AI to analyze, infer, and hypothesize about the cause of the error.

In software development, simple errors are usually easy to detect and fix, but complex code errors – involving multi-layered logic, module interactions, or edge cases – pose a significant challenge even for experienced programmers. Reading and tracing the code flow to find the root cause can be very time-consuming, especially when the system has grown to a large scale.

 

Therefore, prompt templates for diagnosing complex code errors were created as an effective support tool, leveraging the power of AI to analyze, infer, and hypothesize about the cause of errors. Instead of asking general questions, structured prompts guide the AI ​​to focus on critical aspects such as data flow, dependencies, system state, and potential bug locations.

 

This article will help you build 'focused' prompts, thereby not only shortening debugging time but also improving your in-depth understanding of the system. This is a crucial step in transforming AI into a true 'technical assistant' in complex software projects.

Prompt templates help diagnose complex code errors.

Hãy giúp tôi gỡ lỗi vấn đề này: Thông báo lỗi: [DÁN LỖI] Ngữ cảnh code: [DÁN CODE LIÊN QUAN] Ngôn ngữ/Framework: [ví dụ: JavaScript/Node.js] Điều tôi mong đợi: [HÀNH VI MONG ĐỢI] Điều xảy ra: [HÀNH VI THỰC TẾ] Những gì tôi đã thử: [LIỆT KÊ CÁC THỬ NGHIỆM] Cung cấp: 1. Phân tích nguyên nhân gốc rễ 2. Giải pháp từng bước 3. Tại sao nó xảy ra 4. Cách ngăn chặn nó

Best suited for: GPT-5, Claude 4 Sonnet

How to use sample prompts

  • The error message should be: Some items are out of stock
  • The code context is:
// services/orderService.js class OrderService { constructor(paymentService, inventoryService, notificationService) { this.paymentService = paymentService; this.inventoryService = inventoryService; this.notificationService = notificationService; } async processOrder(order) { try { // 1. Validate order if (!order.userId || !order.items || order.items.length === 0) { throw new Error("Invalid order data"); } // 2. Check inventory (BUG tiềm ẩn: không await Promise.all) const inventoryChecks = order.items.map(item => { return this.inventoryService.checkStock(item.productId, item.quantity); }); const allInStock = inventoryChecks.every(result => result === true); if (!allInStock) { throw new Error("Some items are out of stock"); } // 3. Calculate total (BUG: không xử lý số âm hoặc undefined price) let total = 0; for (const item of order.items) { total += item.price * item.quantity; } // 4. Apply discount (BUG: discount có thể > 100%) if (order.discount) { total = total - (total * order.discount); } // 5. Process payment (BUG: không handle timeout / retry) const paymentResult = await this.paymentService.charge( order.userId, total ); if (!paymentResult.success) { throw new Error("Payment failed"); } // 6. Deduct inventory (BUG: race condition nếu concurrent) order.items.forEach(item => { this.inventoryService.reduceStock(item.productId, item.quantity); }); // 7. Send notification (BUG: không await → có thể fail silently) this.notificationService.sendEmail(order.userId, "Order successful"); return { status: "success", total }; } catch (error) { console.error("Order processing failed:", error.message); return { status: "failed", error: error.message }; } } } module.exports = OrderService;

 

  • Language/Framework: JavaScript
  • The expected behavior is: Display an error code to indicate at which step the error occurred and to easily categorize the error.
  • What happened:
    • Returning only error.message → lacks context (doesn't know at which step the error occurred)
    • No error code → difficult to handle on the frontend.
    • No fault classification (business vs system)
    • console.error is not sufficient for production (a logger like Winston should be used instead).
  • What I tried: Refactored the entire error handling system to meet production standards (Node.js).

The sample prompt results were obtained using GPT-5.

Hãy giúp tôi gỡ lỗi vấn đề này: Thông báo lỗi: Some items are out of stock Ngữ cảnh code: // services/orderService.js class OrderService { constructor(paymentService, inventoryService, notificationService) { this.paymentService = paymentService; this.inventoryService = inventoryService; this.notificationService = notificationService; } async processOrder(order) { try { // 1. Validate order if (!order.userId || !order.items || order.items.length === 0) { throw new Error("Invalid order data"); } // 2. Check inventory (BUG tiềm ẩn: không await Promise.all) const inventoryChecks = order.items.map(item => { return this.inventoryService.checkStock(item.productId, item.quantity); }); const allInStock = inventoryChecks.every(result => result === true); if (!allInStock) { throw new Error("Some items are out of stock"); } // 3. Calculate total (BUG: không xử lý số âm hoặc undefined price) let total = 0; for (const item of order.items) { total += item.price * item.quantity; } // 4. Apply discount (BUG: discount có thể > 100%) if (order.discount) { total = total - (total * order.discount); } // 5. Process payment (BUG: không handle timeout / retry) const paymentResult = await this.paymentService.charge( order.userId, total ); if (!paymentResult.success) { throw new Error("Payment failed"); } // 6. Deduct inventory (BUG: race condition nếu concurrent) order.items.forEach(item => { this.inventoryService.reduceStock(item.productId, item.quantity); }); // 7. Send notification (BUG: không await → có thể fail silently) this.notificationService.sendEmail(order.userId, "Order successful"); return { status: "success", total }; } catch (error) { console.error("Order processing failed:", error.message); return { status: "failed", error: error.message }; } } } module.exports = OrderService; Ngôn ngữ/Framework: JavaScript Điều tôi mong đợi: Hiển thị mã lỗi để biết lỗi xảy ra ở bước nào và dễ phân loại lỗi Điều xảy ra: ❌ Chỉ trả về error.message → thiếu context (không biết lỗi xảy ra ở bước nào) ❌ Không có mã lỗi (error code) → khó xử lý phía frontend ❌ Không phân loại lỗi (business vs system) ❌ console.error không đủ cho production (nên dùng logger như Winston) Những gì tôi đã thử: Refactor toàn bộ hệ thống error handling theo chuẩn production (Node.js) Cung cấp: 1. Phân tích nguyên nhân gốc rễ 2. Giải pháp từng bước 3. Tại sao nó xảy ra 4. Cách ngăn chặn nó

Images 1 of Prompt templates help diagnose complex code errors.

Images 2 of Prompt templates help diagnose complex code errors.

Images 3 of Prompt templates help diagnose complex code errors.

Images 4 of Prompt templates help diagnose complex code errors.

Images 5 of Prompt templates help diagnose complex code errors.

Images 6 of Prompt templates help diagnose complex code errors.

Images 7 of Prompt templates help diagnose complex code errors.

Images 8 of Prompt templates help diagnose complex code errors.

Images 9 of Prompt templates help diagnose complex code errors.

Images 10 of Prompt templates help diagnose complex code errors.

Images 11 of Prompt templates help diagnose complex code errors.

Images 12 of Prompt templates help diagnose complex code errors.

Images 13 of Prompt templates help diagnose complex code errors.

Images 14 of Prompt templates help diagnose complex code errors.

Images 15 of Prompt templates help diagnose complex code errors.

Images 16 of Prompt templates help diagnose complex code errors.

Close
Category

System

Windows XP

Windows Server 2012

Windows 8

Windows 7

Windows 10

Wifi tips

Virus Removal - Spyware

Speed ​​up the computer

Server

Security solution

Mail Server

LAN - WAN

Ghost - Install Win

Fix computer error

Configure Router Switch

Computer wallpaper

Computer security

Mac OS X

Mac OS System software

Mac OS Security

Mac OS Office application

Mac OS Email Management

Mac OS Data - File

Mac hardware

Hardware

USB - Flash Drive

Speaker headset

Printer

PC hardware

Network equipment

Laptop hardware

Computer components

Advice Computer

Game

PC game

Online game

Mobile Game

Pokemon GO

information

Technology story

Technology comments

Quiz technology

New technology

British talent technology

Attack the network

Artificial intelligence

Technology

Smart watches

Raspberry Pi

Linux

Camera

Basic knowledge

Banking services

SEO tips

Science

Strange story

Space Science

Scientific invention

Science Story

Science photo

Science and technology

Medicine

Health Care

Fun science

Environment

Discover science

Discover nature

Archeology

Life

Travel Experience

Tips

Raise up child

Make up

Life skills

Home Care

Entertainment

DIY Handmade

Cuisine

Christmas

Application

Web Email

Website - Blog

Web browser

Support Download - Upload

Software conversion

Social Network

Simulator software

Online payment

Office information

Music Software

Map and Positioning

Installation - Uninstall

Graphic design

Free - Discount

Email reader

Edit video

Edit photo

Compress and Decompress

Chat, Text, Call

Archive - Share

Electric

Water heater

Washing machine

Television

Machine tool

Fridge

Fans

Air conditioning

Program

Unix and Linux

SQL Server

SQL

Python

Programming C

PHP

NodeJS

MongoDB

jQuery

JavaScript

HTTP

HTML

Git

Database

Data structure and algorithm

CSS and CSS3

C ++

C #

AngularJS

Mobile

Wallpapers and Ringtones

Tricks application

Take and process photos

Storage - Sync

Security and Virus Removal

Personalized

Online Social Network

Map

Manage and edit Video

Data

Chat - Call - Text

Browser and Add-on

Basic setup