Skip to content

Conversation

@joaquimds
Copy link
Member

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes handling of missing or empty data in the geocoding functionality and refactors GeoJSON API tests.

Changes:

  • Improved null/undefined handling in geocoding for postcodes, areas, and addresses by coalescing values to empty strings before processing
  • Enhanced error messages to be more specific (e.g., "Missing postcode column" instead of "Missing area column")
  • Refactored GeoJSON API tests from using fetch to directly calling the route handler function
  • Updated test expectations to include UKR18 region codes that are now being enriched during geocoding

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/server/mapping/geocode.ts Added null/undefined handling and validation for empty values in geocoding functions, improved error messages
tests/feature/geojsonAPI.test.ts Refactored tests to call GET route handler directly instead of using fetch, added createNextRequest helper function
tests/feature/importDataSource.test.ts Updated test expectations to include UKR18 region codes and additional area code E14001088

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 196 to 199
const address = addressColumns.map((c) => dataRecordJson[c] || "").join(", ");
if (!address) {
throw new Error("Missing address in row");
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The validation logic for empty address is flawed. When all address columns contain empty strings, joining them with ", " will produce a string like ", , " (containing only commas and spaces), which is not empty. The validation should check if all columns are empty or if the trimmed result is effectively empty after removing commas and whitespace.

Consider checking if the address contains any meaningful content after joining, or validate that at least one column has a non-empty value before constructing the address string.

Suggested change
const address = addressColumns.map((c) => dataRecordJson[c] || "").join(", ");
if (!address) {
throw new Error("Missing address in row");
}
const addressParts = addressColumns.map((c) => {
const value = dataRecordJson[c];
if (typeof value === "string") {
return value.trim();
}
return String(value ?? "").trim();
});
const hasMeaningfulAddress = addressParts.some((part) => part.length > 0);
if (!hasMeaningfulAddress) {
throw new Error("Missing address in row");
}
const address = addressParts.join(", ");

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@joaquimds joaquimds merged commit d4ba172 into main Jan 30, 2026
7 checks passed
@joaquimds joaquimds deleted the fix/geocode-missing-data branch January 30, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants