Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 12 additions & 14 deletions src/screens/CalendarScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
getPdfExtractorHtml, parseShiftCells,
type ParsedSchedule, type ParsedEmployee, type ParsedShift,
} from '../utils/pdfShiftParser';
import { useLanguage } from '../context/LanguageContext';
import { useLanguage } from '../context/LanguageContext';
import { handleError } from '../utils/errorHandler';

const STORAGE_KEY = '@shift_import_name';

Expand Down Expand Up @@ -111,7 +112,7 @@ export default function CalendarScreen() {
setManualModalOpen(false);
fetchCalendar(true);
Alert.alert(t('calShiftSaved'));
} catch (e: any) { Alert.alert('Errore', e.message); }
} catch (e: unknown) { handleError(e, 'calendar'); }
};

const SCREEN_W = Dimensions.get('window').width;
Expand Down Expand Up @@ -198,7 +199,7 @@ export default function CalendarScreen() {
setEventsData(localData);
setLoading(false);
fetchWeatherAndFlights(start, end, localData);
} catch (e) { if (__DEV__) console.error(e); setLoading(false); }
} catch (e: unknown) { handleError(e, 'calendar'); setLoading(false); }
};

const fetchWeatherAndFlights = async (start: Date, end: Date, localData: Record<string, ShiftEvent[]>) => {
Expand All @@ -216,7 +217,7 @@ export default function CalendarScreen() {
dict[date] = { weatherText: m.text, weatherIcon: m.icon, flightCount: 0 };
});
}
} catch (e) { if (__DEV__) console.warn('[calWeather]', e); }
} catch (e: unknown) { handleError(e, 'network', true); }
try {
const { arrivals, departures } = await fetchAirportScheduleRaw(airportCode);
const allF = [...arrivals, ...departures];
Expand All @@ -232,7 +233,7 @@ export default function CalendarScreen() {
if (dict[iso]) dict[iso].flightCount = cnt; else dict[iso] = { weatherText: 'N/A', weatherIcon: '❓', flightCount: cnt };
}
});
} catch (e) { if (__DEV__) console.warn('[calFlights]', e); }
} catch (e: unknown) { handleError(e, 'flight', true); }
setDailyStats(dict);
};

Expand Down Expand Up @@ -261,9 +262,8 @@ export default function CalendarScreen() {
setImportStep('extracting');
setImportModalVisible(true);
setPdfHtml(getPdfExtractorHtml(base64));
} catch (e: any) {
if (__DEV__) console.error(`Import error at step=${step}:`, e);
Alert.alert('Errore', `Errore (${step}): ${e?.message || e}`);
} catch (e: unknown) {
handleError(e instanceof Error ? new Error(`Errore (${step}): ${e.message}`, { cause: e }) : e, 'import');
}
Comment on lines +265 to 267
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this catch, the user-facing message includes the step only when the thrown value is an Error. If something throws a non-Error (string/object), handleError will end up alerting String(e) and the step context is lost compared to the previous behavior. Consider always wrapping into a new Error that includes step (and attach the original value as cause) so the alert stays consistent and actionable.

Copilot uses AI. Check for mistakes.
};

Expand Down Expand Up @@ -302,9 +302,8 @@ export default function CalendarScreen() {
}

setImportStep('pickName');
} catch (e) {
if (__DEV__) console.error(e);
Alert.alert('Errore', 'Errore nel parsing del PDF');
} catch (e: unknown) {
handleError(e instanceof Error ? new Error('Errore nel parsing del PDF', { cause: e }) : e, 'import');
setImportModalVisible(false);
setImportStep('idle');
}
Comment on lines +305 to 309
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This catch only wraps the error (with the friendly message) when e is an Error; for non-Error throws the alert message becomes String(e) instead of the intended "Errore nel parsing del PDF". Consider always passing a user-friendly Error message here (and attach the original thrown value as cause) so the user sees a consistent, localized message regardless of what was thrown.

Copilot uses AI. Check for mistakes.
Expand Down Expand Up @@ -348,9 +347,8 @@ export default function CalendarScreen() {
fetchCalendar(true);
Alert.alert(t('calImportComplete'), `${saved} turni salvati nel calendario`);
}, 800);
} catch (e) {
if (__DEV__) console.error(e);
Alert.alert('Errore', t('calImportError'));
} catch (e: unknown) {
handleError(e instanceof Error ? new Error(t('calImportError'), { cause: e }) : e, 'import');
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the other catch blocks: if a non-Error value is thrown, this will bypass the friendly t('calImportError') message and show String(e) to the user. Consider always wrapping with the translated message (and storing the original thrown value as cause) so the user-visible alert remains consistent.

Suggested change
handleError(e instanceof Error ? new Error(t('calImportError'), { cause: e }) : e, 'import');
handleError(
new Error(t('calImportError'), {
cause: e instanceof Error ? e : new Error(String(e)),
}),
'import',
);

Copilot uses AI. Check for mistakes.
setImportStep('idle');
}
};
Expand Down
Loading