Skip to content

Commit

Permalink
fix(usage-report): avoid report failure when previous stats are invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
b-Nollet committed Jan 10, 2025
1 parent 3a21290 commit 8a330ce
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/xo-server-usage-report/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,15 @@ async function storeStats({ data, storedStatsPath }) {

async function computeEvolution({ storedStatsPath, ...newStats }) {
try {
const oldStats = JSON.parse(await pReadFile(storedStatsPath, 'utf8'))
const fileContent = await pReadFile(storedStatsPath, 'utf8')
let oldStats
try {
oldStats = JSON.parse(fileContent)
} catch {
log.warn('Invalid or empty json stats file')
// stats file is empty or invalid
return
}
const newStatsVms = newStats.vms
const oldStatsVms = oldStats.global.vms
const newStatsHosts = newStats.hosts
Expand Down

0 comments on commit 8a330ce

Please sign in to comment.