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 16, 2025
1 parent d044dda commit a1b430e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”
- Fix SR tags not being listed in tag selectors (PR [#8251](https://github.com/vatesfr/xen-orchestra/pull/8251))
- [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

Expand All @@ -37,6 +38,7 @@
<!--packages-start-->

- @xen-orchestra/web-core minor
- xo-server-usage-report patch
- xo-web 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 a1b430e

Please sign in to comment.