fix(smartplaylist): don't let invalid rules hide all playlists - #6316
Empty nested groups were saved as {} and could not be read back, failing
every playlist query. Drop them while parsing, and log and skip unreadable
rules stored in the DB instead of failing the whole listing.
Signed-off-by: DualFroz <me@dualfroz.com>
This commit is contained in:
1 parent
46e0546b86
commit
45e13950f3
4 files changed
+74
-2
No files matched your search
@@ -26,6 +26,9 @@ func (uc *unmarshalConjunctionType) UnmarshalJSON(data []byte) error {
|
||||
if expr == nil {
|
||||
return fmt.Errorf(`invalid expression key '%s'`, k)
|
||||
}
|
||||
if isEmptyConjunction(expr) {
|
||||
continue
|
||||
}
|
||||
es = append(es, expr)
|
||||
}
|
||||
}
|
||||
@@ -154,6 +157,18 @@ func unmarshalConjunction(conjName string, rawValue json.RawMessage) Expression
|
||||
return nil
|
||||
}
|
||||
|
||||
// isEmptyConjunction reports whether expr is a group with no rules. Such groups are dropped
|
||||
// while parsing: they would be saved as {}, which cannot be read back.
|
||||
func isEmptyConjunction(expr Expression) bool {
|
||||
switch e := expr.(type) {
|
||||
case All:
|
||||
return len(e) == 0
|
||||
case Any:
|
||||
return len(e) == 0
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func marshalExpression(name string, value map[string]any) ([]byte, error) {
|
||||
if len(value) != 1 {
|
||||
return nil, fmt.Errorf(`invalid %s expression length %d for values %v`, name, len(value), value)
|
||||
|
||||
Reference in new issue
Block a user