Issue Description
The currencyservice is encountering recurring conversion errors that result in zero-amount calculations, causing the service to fall back to the original currency. This is happening consistently in the production environment.
Error Analysis
From the pod logs, I can see repeated instances of:
"Currency conversion resulted in zero amount, switching back to original currency"
Root Cause
After examining the source code in src/currencyservice/server.js and the currency data in src/currencyservice/data/currency_conversion.json, I've identified the issue:
The GBP (British Pound) exchange rate is set to an empty string in the currency_conversion.json file:
{
"EUR": "1.0",
"USD": "1.1305",
"JPY": "126.40",
...
"GBP": "", // <- This is the problem
...
}
Technical Details
In the convert function in server.js, the conversion logic performs:
- Convert from source currency to EUR:
from.units / data[from.currency_code]
- Convert from EUR to target currency:
euros.units * data[request.to_code]
When the GBP rate is an empty string, JavaScript coerces it to 0, causing:
- Division by 0 when converting FROM GBP (results in Infinity)
- Multiplication by 0 when converting TO GBP (results in 0)
This leads to zero amounts after the Math.floor() operations, triggering the error handling logic.
Recommended Fix
Replace the empty GBP exchange rate with the correct value. Based on typical EUR-GBP rates, it should be approximately "0.85" to "0.90".
Proposed change in src/currencyservice/data/currency_conversion.json:
{
"EUR": "1.0",
"USD": "1.1305",
"JPY": "126.40",
"BGN": "1.9558",
"CZK": "25.592",
"DKK": "7.4609",
"GBP": "0.8750", // Updated with proper exchange rate
"HUF": "315.51",
// ... rest of the currencies
}
Additional Recommendations
- Add input validation in the
convert function to check for invalid exchange rates (empty strings, null, zero values)
- Implement better error handling to log the specific currencies involved in failed conversions
- Consider adding unit tests to catch such data integrity issues
- Set up monitoring alerts for zero-amount conversions to catch similar issues quickly
Impact
This issue affects any currency conversion involving GBP, causing:
- Failed transactions when users try to view prices in British Pounds
- Fallback to original currencies, leading to poor user experience
- Increased error logging and unnecessary Slack notifications
Issue Description
The currencyservice is encountering recurring conversion errors that result in zero-amount calculations, causing the service to fall back to the original currency. This is happening consistently in the production environment.
Error Analysis
From the pod logs, I can see repeated instances of:
Root Cause
After examining the source code in
src/currencyservice/server.jsand the currency data insrc/currencyservice/data/currency_conversion.json, I've identified the issue:The GBP (British Pound) exchange rate is set to an empty string in the currency_conversion.json file:
{ "EUR": "1.0", "USD": "1.1305", "JPY": "126.40", ... "GBP": "", // <- This is the problem ... }Technical Details
In the
convertfunction inserver.js, the conversion logic performs:from.units / data[from.currency_code]euros.units * data[request.to_code]When the GBP rate is an empty string, JavaScript coerces it to
0, causing:This leads to zero amounts after the
Math.floor()operations, triggering the error handling logic.Recommended Fix
Replace the empty GBP exchange rate with the correct value. Based on typical EUR-GBP rates, it should be approximately
"0.85"to"0.90".Proposed change in
src/currencyservice/data/currency_conversion.json:{ "EUR": "1.0", "USD": "1.1305", "JPY": "126.40", "BGN": "1.9558", "CZK": "25.592", "DKK": "7.4609", "GBP": "0.8750", // Updated with proper exchange rate "HUF": "315.51", // ... rest of the currencies }Additional Recommendations
convertfunction to check for invalid exchange rates (empty strings, null, zero values)Impact
This issue affects any currency conversion involving GBP, causing: