Bagale Pulse

Practical technology guides and perspectives from Adamawa.

Bagale Admin Login

Authorized administrators only.

Forgot password?

Ask AI to Explain an Error Message Before Changing Code

When a program fails, a large replacement code block can hide the original problem. Begin by understanding the error and reproducing it with the smallest relevant example.

A practical way to start

Copy the exact error text, the relevant code and the action that triggered it. Remove tokens, passwords and private paths. State the language and environment details that you know.

Prompt to try

Explain this error in beginner language. Identify the line most likely involved and suggest the smallest change to test first. Do not rewrite unrelated code. If more context is needed, ask for it. Error: [message]. Relevant code: [code]. Expected behaviour: [description].

Worked example: adding a delivery fee in Python

Suppose a small shop records an order total as text. This example uses invented amounts, so no customer details need to be shared.

order_total = "2500"
delivery_fee = 500
print(order_total + delivery_fee)

Python raises TypeError: can only concatenate str (not "int") to str. The problem is the types: order_total is a string, while delivery_fee is an integer. The plus operator cannot combine them in this way.

A focused prompt

I am using Python 3. This code should add a delivery fee to an order total, but it raises the TypeError shown above. Explain which values have incompatible types and suggest the smallest correction. Keep the variable names and do not rewrite the program.

The smallest correction

order_total = "2500"
delivery_fee = 500
print(int(order_total) + delivery_fee)

The result is 3000. Converting the text to an integer makes this arithmetic addition. Converting the fee to text instead would produce 2500500, which is not the desired total.

Check more than the successful case

Try an order total of "0": the result should be 500. Try "1250": expect 1750. Now try "unknown": conversion raises a ValueError. That last test reveals a separate input-validation problem rather than a reason to change unrelated code.

order_total = "unknown"
delivery_fee = 500
try:
    total = int(order_total) + delivery_fee
except ValueError:
    print("Enter a whole-number order total.")
else:
    print(total)

This teaching example accepts whole numbers only. A real checkout also needs rules for negative values, currency precision and trusted price calculations. State these requirements before asking AI to extend it.

Keep a useful debugging record

Write down the original error, the single change made, and the input/output of each test. If the suggestion fails, share that evidence in the next prompt. Never paste API keys, customer records or passwords into an AI chat.

Check the result

Save your current work before applying a change. Run the same failing case again, then test a normal case. If the error changes, record the new message rather than stacking several unverified fixes.

Ask for a brief explanation of why the fix works. The aim is to build a troubleshooting habit you can repeat, not just collect snippets that happen to run once.