Skip to content

Commit 3673e14

Browse files
committed
fix(model-api): handle exceptions while getting concepts in tryResolve
PNodeAdapter.concept throws a RuntimeException if the concept cannot be resolved.
1 parent 9243851 commit 3673e14

File tree

1 file changed

+32
-3
lines changed
  • model-api/src/commonMain/kotlin/org/modelix/model/api

1 file changed

+32
-3
lines changed

model-api/src/commonMain/kotlin/org/modelix/model/api/INode.kt

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,17 @@ fun INode.resolveProperty(role: String): IProperty {
323323
?: throw RuntimeException("Property '$role' not found in concept ${c.getLongName()}")
324324
}
325325

326+
/**
327+
* Attempts to resolve the child link.
328+
* @return resolved child link
329+
* or null, if this concept has no child link or an exception was thrown during concept resolution
330+
*/
326331
fun INode.tryResolveChildLink(role: String): IChildLink? {
327-
val c = this.concept ?: return null
332+
val c = try {
333+
this.concept ?: return null
334+
} catch (e: RuntimeException) {
335+
return null
336+
}
328337
val allLinks = c.getAllChildLinks()
329338
return allLinks.find { it.key(this) == role }
330339
?: allLinks.find { it.getSimpleName() == role }
@@ -334,8 +343,18 @@ fun INode.resolveChildLinkOrFallback(role: String?): IChildLink {
334343
if (role == null) return NullChildLink
335344
return tryResolveChildLink(role) ?: IChildLink.fromName(role)
336345
}
346+
347+
/**
348+
* Attempts to resolve the reference link.
349+
* @return resolved reference link
350+
* or null, if this node has no reference link or an exception was thrown during concept resolution
351+
*/
337352
fun INode.tryResolveReferenceLink(role: String): IReferenceLink? {
338-
val c = this.concept ?: return null
353+
val c = try {
354+
this.concept ?: return null
355+
} catch (e: RuntimeException) {
356+
return null
357+
}
339358
val allLinks = c.getAllReferenceLinks()
340359
return allLinks.find { it.key(this) == role }
341360
?: allLinks.find { it.getSimpleName() == role }
@@ -344,8 +363,18 @@ fun INode.tryResolveReferenceLink(role: String): IReferenceLink? {
344363
fun INode.resolveReferenceLinkOrFallback(role: String): IReferenceLink {
345364
return tryResolveReferenceLink(role) ?: IReferenceLink.fromName(role)
346365
}
366+
367+
/**
368+
* Attempts to resolve the property.
369+
* @return resolved property
370+
* or null, if this node has no concept or an exception was thrown during concept resolution
371+
*/
347372
fun INode.tryResolveProperty(role: String): IProperty? {
348-
val c = this.concept ?: return null
373+
val c = try {
374+
this.concept ?: return null
375+
} catch (e: RuntimeException) {
376+
return null
377+
}
349378
val allLinks = c.getAllProperties()
350379
return allLinks.find { it.key(this) == role }
351380
?: allLinks.find { it.getSimpleName() == role }

0 commit comments

Comments
 (0)