Repository navigation
RC-T47 Map Routing App Fixes #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -271,14 +271,18 @@ export default function CallDetail() { | |
| * Opens the device's native maps application with directions to the call location | ||
| */ | ||
| const handleRoute = async () => { | ||
| if (coordinates.latitude === null || coordinates.longitude === null) { | ||
| // A withheld address must not leave the app in a navigation URL; coordinates still route. | ||
| const routableAddress = call?.Address && !isFieldRedacted(call.RedactedFields, ProtectedFieldIds.callAddress, call.Address) ? call.Address.trim() : ''; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potentially absent RedactedFields and direct call.Address dereferencing can cause errors before isFieldRedacted or trim executes. Use optional chaining and a default value for both properties before passing the data to isFieldRedacted or trim. Kody rule violation: Add null checks before accessing properties const address = call?.Address?.trim() ?? ''; const routableAddress = address && !isFieldRedacted(call?.RedactedFields ?? [], ProtectedFieldIds.callAddress, address) ? address : '';Prompt for LLMTalk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Direct dereferencing of potentially null call properties can cause a NullReferenceException. Guard all call properties with optional chaining and null-coalescing before dereferencing them. Kody rule violation: Add null checks to prevent NullReferenceException const address = call?.Address?.trim() ?? ''; const routableAddress = address && !isFieldRedacted(call?.RedactedFields ?? [], ProtectedFieldIds.callAddress, address) ? address : '';Prompt for LLMTalk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. |
||
|
|
||
| if ((coordinates.latitude === null || coordinates.longitude === null) && !routableAddress) { | ||
| showToast('error', t('call_detail.no_location_for_routing')); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const destinationName = call?.Address || t('call_detail.call_location'); | ||
| const success = await openMapsWithDirections(coordinates.latitude, coordinates.longitude, destinationName, userLatitude || undefined, userLongitude || undefined); | ||
| const destinationName = routableAddress || t('call_detail.call_location'); | ||
| // Without usable coordinates the helper navigates to the address instead. | ||
| const success = await openMapsWithDirections(coordinates.latitude, coordinates.longitude, destinationName, userLatitude || undefined, userLongitude || undefined, routableAddress); | ||
|
|
||
| if (!success) { | ||
| showToast('error', t('call_detail.failed_to_open_maps')); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,16 @@ | ||
| import { LockIcon } from 'lucide-react-native'; | ||
| import React, { useCallback, useEffect } from 'react'; | ||
| import { useTranslation } from 'react-i18next'; | ||
| import { Linking, View } from 'react-native'; | ||
| import { View } from 'react-native'; | ||
|
|
||
| import { ProtectedRevealBar } from '@/components/data-protection/protected-reveal-bar'; | ||
| import { HStack } from '@/components/ui/hstack'; | ||
| import { HomeIcon, MapPinIcon, SettingsIcon } from '@/components/ui/lucide-icons'; | ||
| import { Pressable } from '@/components/ui/pressable'; | ||
| import { Text } from '@/components/ui/text'; | ||
| import { VStack } from '@/components/ui/vstack'; | ||
| import { mapsUrls } from '@/lib/contacts/format'; | ||
| import { logger } from '@/lib/logging'; | ||
| import { parseCoordinates } from '@/lib/contacts/format'; | ||
| import { openMapsWithAddress, openMapsWithDirections } from '@/lib/navigation'; | ||
| import { type ContactAddressData, type ContactResultData } from '@/models/v4/contacts/contactResultData'; | ||
| import { useContactsStore } from '@/stores/contacts/store'; | ||
|
|
||
|
|
@@ -20,17 +20,14 @@ interface ContactDetailsExtraProps { | |
| showCustomFields?: boolean; | ||
| } | ||
|
|
||
| // Opens the navigation app chosen in Settings, which also logs a failure. A "lat,lng" value routes to the point. | ||
| const openMaps = async (query: string) => { | ||
| const { app, web } = mapsUrls(query); | ||
| try { | ||
| if (app && (await Linking.canOpenURL(app))) { | ||
| await Linking.openURL(app); | ||
| return; | ||
| } | ||
| await Linking.openURL(web); | ||
| } catch (error) { | ||
| logger.warn({ message: 'Could not open maps for contact address', context: { error } }); | ||
| const coordinates = parseCoordinates(query); | ||
| if (coordinates) { | ||
| await openMapsWithDirections(coordinates.latitude, coordinates.longitude, undefined, undefined, undefined, query); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unhandled failures from the external openMapsWithDirections navigation call leave the application without contextual diagnostics or application-level handling. Wrap the call in try/catch and log the operation, query, and error with logger.warn; this also applies to src/components/contacts/contact-details-extra.tsx:30-30 and src/components/contacts/contact-details-sheet.tsx:90-90. Kody rule violation: Add try-catch blocks for external calls try {
await openMapsWithDirections(coordinates.latitude, coordinates.longitude, undefined, undefined, undefined, query);
} catch (error) {
logger.warn({ message: 'Could not open map directions', context: { operation: 'openMapsWithDirections', query, error } });
}Prompt for LLMTalk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. |
||
| return; | ||
| } | ||
| await openMapsWithAddress(query); | ||
| }; | ||
|
|
||
| const AddressRow = ({ label, address }: { label: string; address: ContactAddressData }) => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unhandled rejections from the awaited openMapsWithDirections call can prevent the existing failure feedback from reaching the user. Wrap the call in try/catch and show the existing error toast; this also applies to src/components/contacts/contact-details-extra.tsx:27-27, src/components/contacts/contact-details-extra.tsx:30-30, src/components/contacts/contact-details-sheet.tsx:90-90, src/app/call/tests/[id].test.tsx:834-834, src/app/call/tests/[id].test.tsx:845-845, src/app/call/tests/[id].test.tsx:857-857, src/app/call/tests/[id].test.tsx:868-868, src/app/call/tests/[id].test.tsx:881-881, and src/lib/tests/navigation.test.ts:95-95, src/lib/tests/navigation.test.ts:114-114, src/lib/tests/navigation.test.ts:125-125, src/lib/tests/navigation.test.ts:136-136, src/lib/tests/navigation.test.ts:166-166, src/lib/tests/navigation.test.ts:179-179, src/lib/tests/navigation.test.ts:187-187, src/lib/tests/navigation.test.ts:195-195, src/lib/tests/navigation.test.ts:203-203, src/lib/tests/navigation.test.ts:222-222, src/lib/tests/navigation.test.ts:233-233, src/lib/tests/navigation.test.ts:244-244, src/lib/tests/navigation.test.ts:270-270, src/lib/tests/navigation.test.ts:280-280, src/lib/tests/navigation.test.ts:292-292, src/lib/tests/navigation.test.ts:298-298, src/lib/tests/navigation.test.ts:304-304, src/lib/tests/navigation.test.ts:310-310, src/lib/tests/navigation.test.ts:316-316, src/lib/tests/navigation.test.ts:322-322, src/lib/tests/navigation.test.ts:342-342, src/lib/tests/navigation.test.ts:352-352, src/lib/tests/navigation.test.ts:360-360, src/lib/tests/navigation.test.ts:366-366, src/lib/tests/navigation.test.ts:374-374, src/lib/tests/navigation.test.ts:386-386, src/lib/tests/navigation.test.ts:398-398, src/lib/tests/navigation.test.ts:407-407, src/lib/tests/navigation.test.ts:419-419, src/lib/tests/navigation.test.ts:448-448, src/lib/tests/navigation.test.ts:475-475, src/lib/tests/navigation.test.ts:486-486, src/lib/tests/navigation.test.ts:496-496, src/lib/tests/navigation.test.ts:505-505, src/lib/tests/navigation.test.ts:522-522, src/lib/tests/navigation.test.ts:529-529, and src/lib/tests/navigation.test.ts:538-538.
Kody rule violation: Handle async operations with proper error handling
Prompt for LLM
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.