Greenstand / Greenstand/treetracker-android

Standardize error handling across sync and upload paths

Open
#1,236 2 comments 0 reactions 1 assignee Claimed by @brundamarpadaga View on GitHub
2.3 chore refactor triage
Dominant language
Kotlin
Stars
101
Forks
116
PR merge metrics
No merged PRs in 30d

Description

## Problem

Error handling is inconsistent across the codebase:

1. **Swallowed exceptions** — Some uploaders catch `Exception`, log a message, but don't propagate the error, causing silent failures in critical sync paths
2. **Bare `catch(Exception)`** — Used extensively (~103 try-catch blocks) instead of catching specific exception types
3. **Inconsistent logging context** — Some places log full stack traces, others just the localized message
4. **No structured error types** — Errors are communicated as strings or swallowed entirely rather than using Result types or sealed classes

## Key Locations

- `TreeUploader.kt` — `windowedTreeUpload()` catches and swallows all exceptions
- `PlanterUploader.kt` — silent failures in upload steps
- `TreeSyncWorker` — `doWork()` body lacks comprehensive error wrapping
- `MessagesRepo.kt` — mix of proper CancellationException re-throw and bare catches
- Various repositories — inconsistent error context in Timber logs

## Suggested Fix

1. Replace bare `catch(Exception)` with specific exception types where possible (e.g., `IOException`, `HttpException`)
2. Always re-throw `CancellationException` in coroutine contexts
3. Consider introducing a `Result` or sealed class pattern for error propagation
4. Standardize Timber logging to always include the exception object: `Timber.e(exception, "message")`
5. Ensure sync failures are visible to the user or retry mechanism

## Effort
High — touches many files, but can be addressed incrementally per module.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.