Skip to content

Commit

Permalink
fix: let exploreDirectory continue when encountering invalid TDs
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Dec 6, 2024
1 parent e8373bf commit f3107df
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/src/core/implementation/servient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//
// SPDX-License-Identifier: BSD-3-Clause

import "dart:developer";

import "package:meta/meta.dart";
import "package:uuid/uuid.dart";

Expand Down Expand Up @@ -379,6 +381,21 @@ class InternalServient implements Servient {
return ThingDescription.fromJson(dataSchemaValue.value);
}

Stream<ThingDescription> _processThingDescriptions(
List<Object?> rawThingDescriptions,
) async* {
for (final rawThingDescription in rawThingDescriptions) {
if (rawThingDescription is Map<String, Object?>) {
try {
yield rawThingDescription.toThingDescription();
} on Exception catch (e) {
log(e.toString());
continue;
}
}
}
}

/// Retrieves [ThingDescription] from a Thing Description Directory (TDD).
///
/// This method expects the TDD's Thing Description to be located under the
Expand Down Expand Up @@ -435,9 +452,8 @@ class InternalServient implements Servient {
);
}

final thingDescriptionStream = Stream.fromIterable(
rawThingDescriptions.whereType<Map<String, Object?>>(),
).map((rawThingDescription) => rawThingDescription.toThingDescription());
final thingDescriptionStream =
_processThingDescriptions(rawThingDescriptions);

return ThingDiscoveryProcess(thingDescriptionStream, thingFilter);
}
Expand Down

0 comments on commit f3107df

Please sign in to comment.