ZhuLinsen/daily_stock_analysis · warning · Error
Invalid share image record ID
Error message
Invalid share image record ID
What it means
Raised by PortfolioService.query_trades when both date_from and date_to are supplied and date_from is strictly later than date_to. It is a request-contract check executed before the repository query, so no SQL runs; the API layer maps it to code=validation_error.
Source
Thrown at apps/dsa-desktop/main.js:1347
}, 3000);
return waitAndClear();
}
function resolveDesktopVersion() {
return String(app.getVersion() || '').trim();
}
function buildMainPageUrl(port, timestamp = Date.now(), host = DESKTOP_BACKEND_DEFAULT_HOST) {
const url = new URL(buildBackendUrl(host, port, '/'));
url.searchParams.set('desktop_version', resolveDesktopVersion() || 'unknown');
url.searchParams.set('cache_bust', String(timestamp));
return url.toString();
}
function buildDesktopShareImageUrl(pageUrl, recordId, expectedBackendOrigin = '') {
if (!Number.isSafeInteger(recordId) || recordId <= 0) {
throw new Error('Invalid share image record ID');
}
let page;
try {
page = new URL(pageUrl);
} catch (_error) {
throw new Error('Desktop backend URL is unavailable');
}
let expectedOrigin = page.origin;
if (expectedBackendOrigin) {
try {
expectedOrigin = new URL(expectedBackendOrigin).origin;
} catch (_error) {
throw new Error('Desktop backend origin is invalid');
}
}
if (page.protocol !== 'http:' || !page.port || page.origin !== expectedOrigin) {View on GitHub (pinned to 5159bd72e8)
Solutions
- Swap the two dates when date_from > date_to before submitting the query
- Fix the range-builder in the caller (e.g. use min(start,end)/max(start,end))
- Validate the range client-side in the Web/Desktop UI and disable submit when inverted
- If dates derive from timestamps, convert to dates in a single timezone before comparing
Example fix
# before svc.query_trades(date_from=end_date, date_to=start_date) # after svc.query_trades(date_from=min(start_date, end_date), date_to=max(start_date, end_date))
Defensive patterns
Strategy: validation
Validate before calling
def safe_range(date_from, date_to):
if date_from and date_to and date_from > date_to:
date_from, date_to = date_to, date_from
return date_from, date_to Type guard
from datetime import date
def is_valid_date_range(d_from: date | None, d_to: date | None) -> bool:
return d_from is None or d_to is None or d_from <= d_to Try / catch
try:
svc.query_trades(date_from=f, date_to=t)
except ValueError as exc:
if "date_from must be <= date_to" in str(exc):
f, t = t, f # or reject the request
svc.query_trades(date_from=f, date_to=t)
else:
raise Prevention
- Always construct ranges as (min(start,end), max(start,end))
- Block inverted ranges in date-picker UIs
- Convert timestamps to dates in one timezone before comparing
When it happens
Trigger: GET /portfolio/trades?date_from=2025-06-30&date_to=2025-01-01, or the equivalent Python call query_trades(date_from=date(2025,6,30), date_to=date(2025,1,1)). Equal dates are allowed; only a strictly greater date_from raises.
Common situations: UI date-range pickers that let users pick an inverted range; timezone shifts that flip a 'last 7 days' calculation; copy-paste of date strings where from/to fields are swapped; programmatic ranges built from max/min in the wrong order.
Related errors
- Desktop backend URL is unavailable
- Desktop backend origin is invalid
- Desktop share images require the configured backend origin
- Desktop share image source did not return HTML
- Backend executable not found: ${backendPath}
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/2a316ae1c604843a.
Report an issue: GitHub.