Skip to content

Commit 1f2f730

Browse files
github-actions[bot]ovitrif
authored andcommitted
fix: address PR review - clean up Logger calls
Co-authored-by: Ovi Trif <ovitrif@users.noreply.github.com>
1 parent 702410b commit 1f2f730

3 files changed

Lines changed: 8 additions & 29 deletions

File tree

AGENTS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ suspend fun getData(): Result<Data> = withContext(Dispatchers.IO) {
178178
- NEVER use `runBlocking` in suspend functions
179179
- ALWAYS pass the TAG as context to `Logger` calls, e.g. `Logger.debug("message", context = TAG)`
180180
- NEVER add `e = ` named parameter to Logger calls
181+
- NEVER manually append the `Throwable`'s message or any other props to the string passed as the 1st param of `Logger.*` calls, its internals are already enriching the final log message with the details of the `Throwable` passed via the `e` arg
181182
- ALWAYS log errors at the final handling layer where the error is acted upon, not in intermediate layers that just propagate it
182183
- ALWAYS use the Result API instead of try-catch
183184
- NEVER wrap methods returning `Result<T>` in try-catch
@@ -221,4 +222,4 @@ suspend fun getData(): Result<Data> = withContext(Dispatchers.IO) {
221222
- Use `LightningRepo` to defining the business logic for the node operations, usually delegating to `LightningService`
222223
- Use `WakeNodeWorker` to manage the handling of remote notifications received via cloud messages
223224
- Use `*Services` to wrap rust library code exposed via bindings
224-
- Use CQRS pattern of Command + Handler like it's done in the `NotifyPaymentReceived` + `NotifyPaymentReceivedHandler` setup
225+
- Use CQRS pattern of Command + Handler like it's done in the `NotifyPaymentReceived` + `NotifyPaymentReceivedHandler` setup

app/src/main/java/to/bitkit/repositories/BlocktankRepo.kt

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,7 @@ class BlocktankRepo @Inject constructor(
425425
): Result<GiftClaimResult> = withContext(bgDispatcher) {
426426
runCatching {
427427
require(code.isNotBlank()) { "Gift code cannot be blank" }
428-
429-
if (amount == 0uL) {
430-
Logger.warn(
431-
"Gift amount is 0 - proceeding anyway as backend may provide actual amount",
432-
context = TAG
433-
)
434-
}
428+
require(amount > 0u) { "Gift amount must be positive" }
435429

436430
Logger.debug("Starting gift code claim: amount=$amount, timeout=$waitTimeout", context = TAG)
437431

@@ -449,20 +443,16 @@ class BlocktankRepo @Inject constructor(
449443
context = TAG
450444
)
451445

452-
if (amount > 0uL && maxInboundCapacity >= amount) {
446+
if (maxInboundCapacity >= amount) {
453447
Logger.debug("Sufficient liquidity available, claiming with existing channel", context = TAG)
454448
Result.success(claimGiftCodeWithLiquidity(code))
455449
} else {
456-
if (amount == 0uL) {
457-
Logger.debug("Amount unknown (0), defaulting to channel opening path", context = TAG)
458-
} else {
459-
Logger.debug("Insufficient liquidity, opening new channel", context = TAG)
460-
}
450+
Logger.debug("Insufficient liquidity, opening new channel", context = TAG)
461451
Result.success(claimGiftCodeWithoutLiquidity(code, amount))
462452
}
463453
}.getOrThrow()
464454
}.onFailure {
465-
Logger.error("Failed to claim gift code: ${it.message}", it, context = TAG)
455+
Logger.error("Failed to claim gift code", it, context = TAG)
466456
}
467457
}
468458

app/src/main/java/to/bitkit/ui/sheets/GiftViewModel.kt

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ class GiftViewModel @Inject constructor(
5353
}
5454
this.code = code
5555
this.amount = amount
56-
57-
if (amount == 0uL) {
58-
Logger.warn("Gift amount is 0 from QR code - this may be incorrect", context = TAG)
59-
}
60-
6156
viewModelScope.launch(bgDispatcher) {
6257
claimGift()
6358
}
@@ -123,14 +118,7 @@ class GiftViewModel @Inject constructor(
123118
}
124119

125120
private suspend fun handleGiftClaimError(error: Throwable) {
126-
val errorMessage = buildString {
127-
append("Gift claim failed: ")
128-
append(error.message ?: error.toString())
129-
error.cause?.let {
130-
append(" (cause: ${it.message ?: it})")
131-
}
132-
}
133-
Logger.error(errorMessage, error, context = TAG)
121+
Logger.error("Gift claim failed", error, context = TAG)
134122

135123
val route = when {
136124
errorContains(error, "GIFT_CODE_ALREADY_USED") -> {
@@ -142,7 +130,7 @@ class GiftViewModel @Inject constructor(
142130
GiftRoute.UsedUp
143131
}
144132
else -> {
145-
Logger.error("Unhandled gift claim error type: ${error::class.simpleName}", context = TAG)
133+
Logger.error("Unhandled gift claim error type", error, context = TAG)
146134
GiftRoute.Error
147135
}
148136
}

0 commit comments

Comments
 (0)