added panic recovery to software mutations flow just to be safe (#26932)

> For #24784

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->
- [x] Added/updated automated tests
- [x] Manual QA for all new/changed functionality
This commit is contained in:
Jahziel Villasana-Espinoza 2025-03-07 10:24:56 -05:00 committed by GitHub
parent eb6020846a
commit 32c5c47b1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View file

@ -372,6 +372,11 @@ var (
func mutateSoftware(software *fleet.Software, logger log.Logger) {
for _, transformer := range softwareTransformers {
if transformer.matches(software) {
defer func() {
if r := recover(); r != nil {
level.Warn(logger).Log("msg", "panic during software mutation", "softwareName", software.Name, "softwareVersion", software.Version, "error", r)
}
}()
transformer.mutate(software, logger)
break
}

View file

@ -2134,7 +2134,7 @@ func TestMutateSoftware(t *testing.T) {
},
} {
t.Run(tc.name, func(t *testing.T) {
mutateSoftware(tc.s, log.NewNopLogger())
require.NotPanics(t, func() { mutateSoftware(tc.s, log.NewNopLogger()) })
require.Equal(t, tc.sanitized, tc.s)
})
}