From 5bf46ed52e8ea2018d084e3c1d24cedffaaab955 Mon Sep 17 00:00:00 2001 From: Laurenz Rasche Date: Tue, 19 Nov 2024 14:28:58 +0100 Subject: [PATCH] improve error logging: log catched errors --- processing/index.ts | 5 +++-- processing/steps/download.ts | 7 ++++--- processing/steps/externalTriggers.ts | 8 ++++---- processing/steps/filter.ts | 8 ++++---- processing/steps/generateTypes.ts | 4 ++-- processing/steps/metadata.ts | 4 ++-- processing/steps/processTopics.ts | 8 ++++---- processing/utils/diffing.ts | 4 ++-- processing/utils/hashing.ts | 4 ++-- 9 files changed, 27 insertions(+), 25 deletions(-) diff --git a/processing/index.ts b/processing/index.ts index e1aea13cd..a0ff0c810 100644 --- a/processing/index.ts +++ b/processing/index.ts @@ -65,6 +65,7 @@ try { } await logTileInfo(params.environment) -} catch (e) { - synologyLogError('Processing failed') +} catch (error) { + synologyLogError(`Processing failed: ${error}`) + throw error } diff --git a/processing/steps/download.ts b/processing/steps/download.ts index 7bfc7cba8..0662f8c6d 100644 --- a/processing/steps/download.ts +++ b/processing/steps/download.ts @@ -76,7 +76,7 @@ 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 } } @@ -84,10 +84,11 @@ export async function downloadFile(fileURL: URL, skipIfExists: boolean) { 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) { diff --git a/processing/steps/externalTriggers.ts b/processing/steps/externalTriggers.ts index c7f5d2bf1..648b8cbf0 100644 --- a/processing/steps/externalTriggers.ts +++ b/processing/steps/externalTriggers.ts @@ -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}`) } } @@ -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}`) } } diff --git a/processing/steps/filter.ts b/processing/steps/filter.ts index ed24258db..18af04079 100644 --- a/processing/steps/filter.ts +++ b/processing/steps/filter.ts @@ -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.') @@ -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 diff --git a/processing/steps/generateTypes.ts b/processing/steps/generateTypes.ts index 4add6ea50..aaeda8cf8 100644 --- a/processing/steps/generateTypes.ts +++ b/processing/steps/generateTypes.ts @@ -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}`) } } } diff --git a/processing/steps/metadata.ts b/processing/steps/metadata.ts index e6c8969e9..0739bdf7c 100644 --- a/processing/steps/metadata.ts +++ b/processing/steps/metadata.ts @@ -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}`) } } diff --git a/processing/steps/processTopics.ts b/processing/steps/processTopics.ts index 7f82b896e..1e7d89a40 100644 --- a/processing/steps/processTopics.ts +++ b/processing/steps/processTopics.ts @@ -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}`) } } } @@ -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}`) } } diff --git a/processing/utils/diffing.ts b/processing/utils/diffing.ts index b8e1336d3..37274476b 100644 --- a/processing/utils/diffing.ts +++ b/processing/utils/diffing.ts @@ -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}`, ) } } diff --git a/processing/utils/hashing.ts b/processing/utils/hashing.ts index 8777c9ce8..e29a1cdc3 100644 --- a/processing/utils/hashing.ts +++ b/processing/utils/hashing.ts @@ -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}`) } }