Skip to content

Commit d2fd310

Browse files
mfazekasclaude
andcommitted
refactor: simplify error types and add tuple return to Android
- Rename DataBindingError to ViewModelInstanceNotFound - Remove IncorrectAnimationName (map to Unknown) - Remove TextRunNotFoundError (map to Unknown) - Make Android detectErrorType return Pair<RiveErrorType, String> for consistency with iOS - Update both platforms to use cleaner error messages - Regenerate Nitrogen bindings 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 81ff8bf commit d2fd310

7 files changed

Lines changed: 32 additions & 41 deletions

File tree

android/src/main/java/com/margelo/nitro/rive/HybridRiveView.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,25 +225,28 @@ class HybridRiveView(val context: ThemedReactContext) : HybridRiveViewSpec() {
225225
}
226226
}
227227

228-
private fun detectErrorType(exception: Exception): RiveErrorType {
229-
return when (exception) {
228+
private fun detectErrorType(exception: Exception): Pair<RiveErrorType, String> {
229+
val message = exception.message ?: exception.toString()
230+
val type = when (exception) {
230231
is ArtboardException -> RiveErrorType.INCORRECTARTBOARDNAME
231232
is StateMachineException -> RiveErrorType.INCORRECTSTATEMACHINENAME
232-
is AnimationException -> RiveErrorType.INCORRECTANIMATIONNAME
233+
is AnimationException -> RiveErrorType.UNKNOWN
233234
is MalformedFileException -> RiveErrorType.MALFORMEDFILE
234235
is StateMachineInputException -> RiveErrorType.INCORRECTSTATEMACHINEINPUTNAME
235-
is TextValueRunException -> RiveErrorType.TEXTRUNNOTFOUNDERROR
236-
is ViewModelException -> RiveErrorType.DATABINDINGERROR
236+
is TextValueRunException -> RiveErrorType.UNKNOWN
237+
is ViewModelException -> RiveErrorType.VIEWMODELINSTANCENOTFOUND
237238
else -> RiveErrorType.UNKNOWN
238239
}
240+
return Pair(type, message)
239241
}
240242

241243
fun logged(tag: String, note: String? = null, fn: () -> Unit) {
242244
try {
243245
fn()
244246
} catch (e: Exception) {
245-
val errorMessage = "[RIVE] $tag ${note ?: ""} $e"
246-
val errorType = detectErrorType(e)
247+
val (errorType, errorDescription) = detectErrorType(e)
248+
val noteString = note?.let { " $it" } ?: ""
249+
val errorMessage = "[RIVE] $tag$noteString $errorDescription"
247250
val riveError = RiveError(
248251
type = errorType,
249252
message = errorMessage

ios/HybridRiveView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ extension HybridRiveView {
209209
private func detectErrorType(_ error: Error) -> (RiveErrorType, String) {
210210
switch error {
211211
case NitroRiveError.instanceNotFound(let message):
212-
return (.databindingerror, message)
212+
return (.viewmodelinstancenotfound, message)
213213
case NitroRiveError.fileNotFound(let message):
214214
return (.filenotfound, message)
215215
default:
@@ -226,7 +226,7 @@ extension HybridRiveView {
226226
case RiveErrorCode.noStateMachineFound.rawValue:
227227
return (.incorrectstatemachinename, message)
228228
case RiveErrorCode.noAnimationFound.rawValue:
229-
return (.incorrectanimationname, message)
229+
return (.unknown, message)
230230
case RiveErrorCode.malformedFile.rawValue:
231231
return (.malformedfile, message)
232232
case RiveErrorCode.noStateMachineInputFound.rawValue:

nitrogen/generated/android/c++/JRiveErrorType.hpp

Lines changed: 3 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nitrogen/generated/android/kotlin/com/margelo/nitro/rive/RiveErrorType.kt

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nitrogen/generated/ios/swift/RiveErrorType.swift

Lines changed: 4 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nitrogen/generated/shared/c++/RiveErrorType.hpp

Lines changed: 11 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/Errors.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ export enum RiveErrorType {
44
MalformedFile = 2,
55
IncorrectArtboardName = 3,
66
IncorrectStateMachineName = 4,
7-
IncorrectAnimationName = 5,
8-
DataBindingError = 6,
9-
TextRunNotFoundError = 7,
7+
ViewModelInstanceNotFound = 6,
108
IncorrectStateMachineInputName = 8,
119
}
1210

0 commit comments

Comments
 (0)