Issue Description
The currencyservice is experiencing critical conversion errors that result in zero amounts when converting from/to certain currencies. The logs show multiple instances of:
Currency conversion resulted in zero amount, switching back to original currency
Root Cause Analysis
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 root cause:
The GBP (British Pound) conversion rate is an empty string ("") instead of a numeric value.
In the currency_conversion.json file:
When the conversion function attempts to divide by an empty string, JavaScript coerces it to 0, which causes the mathematical operations to result in zero amounts:
const euros = _carry({
units: from.units / data[from.currency_code], // Division by empty string = 0
nanos: from.nanos / data[from.currency_code] // Division by empty string = 0
});
Impact
- Currency conversions involving GBP fail and fallback to original currency
- User experience is degraded when attempting GBP conversions
- Error logs are generated repeatedly, potentially causing alert fatigue
- The service attempts to send Slack notifications (with cooldown) for each failed conversion
Recommended Fix
Update the currency_conversion.json file to include a valid numeric conversion rate for GBP. Based on typical EUR to GBP rates, a value around 0.85 to 0.90 would be appropriate:
Additionally, consider implementing input validation in the conversion function to:
- Check for empty or invalid conversion rates before performing calculations
- Log warnings about invalid conversion data
- Gracefully handle missing or invalid currency rates
Files to Modify
src/currencyservice/data/currency_conversion.json - Fix the empty GBP rate
src/currencyservice/server.js - (Optional) Add input validation for conversion rates
Issue Description
The currencyservice is experiencing critical conversion errors that result in zero amounts when converting from/to certain currencies. The logs show multiple instances of:
Root Cause Analysis
After examining the source code in
src/currencyservice/server.jsand the currency data insrc/currencyservice/data/currency_conversion.json, I've identified the root cause:The GBP (British Pound) conversion rate is an empty string (
"") instead of a numeric value.In the
currency_conversion.jsonfile:When the conversion function attempts to divide by an empty string, JavaScript coerces it to 0, which causes the mathematical operations to result in zero amounts:
Impact
Recommended Fix
Update the
currency_conversion.jsonfile to include a valid numeric conversion rate for GBP. Based on typical EUR to GBP rates, a value around0.85to0.90would be appropriate:Additionally, consider implementing input validation in the conversion function to:
Files to Modify
src/currencyservice/data/currency_conversion.json- Fix the empty GBP ratesrc/currencyservice/server.js- (Optional) Add input validation for conversion rates