Skip to content

Commit

Permalink
improve error logging: log catched errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rush42 committed Nov 19, 2024
1 parent cecf17d commit 5bf46ed
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 25 deletions.
5 changes: 3 additions & 2 deletions processing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ try {
}

await logTileInfo(params.environment)
} catch (e) {
synologyLogError('Processing failed')
} catch (error) {
synologyLogError(`Processing failed: ${error}`)
throw error
}
7 changes: 4 additions & 3 deletions processing/steps/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,19 @@ export async function downloadFile(fileURL: URL, skipIfExists: boolean) {
}

if (eTag === (await readPersistent(fileName))) {
console.log('Skipped download because the file has not changed')
console.log('Skipped download because the file has not changed.')
return { fileName, fileChanged: false }
}

// download file and write to disc
console.log(`Downloading file "${fileName}"...`)
const response = await fetch(fileURL.toString())

if (response.status !== 200 || !response.body) {
throw new Error(`Failed to download file. Status code: ${response.status}`)
if (!response.ok || !response.body) {
throw new Error(`Failed to download file. Status code: ${response.statusText}`)
}

// we need to download the file as a stream to avoid memory issues
const reader = response.body.getReader()
const writer = file.writer()
while (true) {
Expand Down
8 changes: 4 additions & 4 deletions processing/steps/externalTriggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export async function clearCache() {
try {
await $`rm -rf "/var/cache/nginx/*"`
console.log('Succesfully cleared the cache.')
} catch {
console.warn('Clearing the cache failed.')
} catch (error) {
console.warn(`Clearing the cache failed: ${error}`)
}
}

Expand All @@ -41,7 +41,7 @@ export async function restartTileServer() {
try {
await $`docker restart tiles > /dev/null`
console.log('Succesfully restarted the tiles container.')
} catch {
throw new Error('Restarting the tiles container failed.')
} catch (error) {
throw new Error(`Restarting the tiles container failed: ${error}`)
}
}
8 changes: 4 additions & 4 deletions processing/steps/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export async function tagFilter(fileName: string, fileChanged: boolean) {
--expressions ${FILTER_EXPRESSIONS} \
--output=${filteredFilePath(fileName)} \
${originalFilePath(fileName)}`
} catch {
throw new Error('Failed to filter the OSM file.')
} catch (error) {
throw new Error(`Failed to filter the OSM file: ${error}`)
}
} else {
console.log('⏩ Skipping tag filter. The file and filters are unchanged.')
Expand All @@ -59,8 +59,8 @@ export async function idFilter(fileName: string, ids: string) {
--output=${filteredFilePath(ID_FILTERED_FILE)} \
--verbose-ids ${filteredFilePath(fileName)} \
${ids}`
} catch {
throw new Error('Failed to filter the OSM file by ids.')
} catch (error) {
throw new Error(`Failed to filter the OSM file by ids: ${error}`)
}

return ID_FILTERED_FILE
Expand Down
4 changes: 2 additions & 2 deletions processing/steps/generateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export async function generateTypes(environment: string, processedTables: string
await Bun.write(typeFile, tableIdType)
try {
await $`bunx prettier -w --config=/processing/.prettierrc ${TYPES_DIR} > /dev/null`
} catch {
throw new Error('Failed to run prettier on auto generated types')
} catch (error) {
throw new Error(`Failed to run prettier on auto generated types: ${error}`)
}
}
}
4 changes: 2 additions & 2 deletions processing/steps/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export async function getFileTimestamp(fileName: string) {
const timestamp =
await $`osmium fileinfo ${filteredFilePath(fileName)} -g header.option.timestamp`.text()
return timestamp.trim()
} catch {
throw new Error(`Failed to get timestamp from file ${fileName}`)
} catch (error) {
throw new Error(`Failed to get timestamp from file "${fileName}": ${error}`)
}
}

Expand Down
8 changes: 4 additions & 4 deletions processing/steps/processTopics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ async function runSQL(topic: Topic) {
if (await Bun.file(psqlFile).exists()) {
try {
await $`psql -q -f ${psqlFile}`
} catch {
throw new Error(`Failed to run SQL file ${psqlFile}`)
} catch (error) {
throw new Error(`Failed to run SQL file "${psqlFile}": ${error}`)
}
}
}
Expand All @@ -50,8 +50,8 @@ async function runLua(fileName: string, topic: Topic) {
--extra-attributes \
--style=${luaFile} \
${filePath}`
} catch {
throw new Error(`Failed to run lua file ${luaFile}`)
} catch (error) {
throw new Error(`Failed to run lua file "${luaFile}": ${error}`)
}
}

Expand Down
4 changes: 2 additions & 2 deletions processing/utils/diffing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export async function getTopicTables(topic: Topic) {
.text()
.then((tables) => new Set(tables.split('\n').filter((table) => table !== '')))
return tables
} catch {
} catch (error) {
throw new Error(
`Failed to get tables for topic ${topic}. This is likely due to some required columns missing.`,
`Failed to get tables for topic "${topic}". This is likely due to some required columns missing: ${error}`,
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions processing/utils/hashing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ async function computeDirectoryHash(path: string) {
try {
const hash = await $`find "${path}" -type f | sort | xargs shasum`.text()
return hash
} catch {
throw new Error('Could not compute the hash of the directory')
} catch (error) {
throw new Error(`Could not compute the hash of the directory "${path}": ${error}`)
}
}

Expand Down

0 comments on commit 5bf46ed

Please sign in to comment.