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 bbb75fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

> Users must be able to say: “I had this issue, happy to know it's fixed”
- [Plugins/usage-report] Prevent the report creation from failing over and over when previous stats file is empty or incorrect (PR [#8240](https://github.com/vatesfr/xen-orchestra/pull/8240))

### Packages to release

> When modifying a package, add it here with its release type.
Expand All @@ -35,5 +37,6 @@
<!--packages-start-->

- @xen-orchestra/web-core minor
- xo-server-usage-report patch

<!--packages-end-->
9 changes: 8 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,14 @@ 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')
return
}
const newStatsVms = newStats.vms
const oldStatsVms = oldStats.global.vms
const newStatsHosts = newStats.hosts
Expand Down

0 comments on commit bbb75fa

Please sign in to comment.