From 4a1bc075ac7a55f2563cde9eb132b09b2fc6ade1 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Thu, 16 Dec 2021 10:53:28 +0100 Subject: [PATCH] Server: Display NTP server domain and port when there is an error, and display message when NTP check is skipped --- packages/lib/ntp.ts | 5 +++-- packages/server/src/app.ts | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/lib/ntp.ts b/packages/lib/ntp.ts index d3339a659d..42000edaf0 100644 --- a/packages/lib/ntp.ts +++ b/packages/lib/ntp.ts @@ -38,8 +38,9 @@ export async function getDeviceTimeDrift(): Promise { break; } catch (error) { if (tryCount >= maxTries) { - error.message = `Cannot retrieve the network time: ${error.message}`; - throw error; + const newError = typeof error === 'string' ? new Error(error) : error; + newError.message = `Cannot retrieve the network time from ${server.domain}:${server.port}: ${newError.message}`; + throw newError; } else { await time.msleep(tryCount * 1000); } diff --git a/packages/server/src/app.ts b/packages/server/src/app.ts index f0e091986e..09438af217 100644 --- a/packages/server/src/app.ts +++ b/packages/server/src/app.ts @@ -254,9 +254,11 @@ async function main() { if (config().maxTimeDrift) { const timeDrift = await getDeviceTimeDrift(); if (Math.abs(timeDrift) > config().maxTimeDrift) { - throw new Error(`The device time drift is ${timeDrift}ms (Max allowed: ${config().maxTimeDrift}ms) - cannot continue as it could cause data loss and conflicts on the sync clients. You may increase env var MAX_TIME_DRIFT to pass the check.`); + throw new Error(`The device time drift is ${timeDrift}ms (Max allowed: ${config().maxTimeDrift}ms) - cannot continue as it could cause data loss and conflicts on the sync clients. You may increase env var MAX_TIME_DRIFT to pass the check, or set to 0 to disabled the check.`); } appLogger().info(`NTP time offset: ${timeDrift}ms`); + } else { + appLogger().info('Skipping NTP time check because MAX_TIME_DRIFT is 0.'); } appLogger().info('Running in Docker:', runningInDocker());