Skip to content

Commit

Permalink
Add original nmea message to all kind of error, this makes errors eas…
Browse files Browse the repository at this point in the history
…ier to analyze
  • Loading branch information
SamYStudiO committed Dec 22, 2023
1 parent e3510a9 commit d4aaa26
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 8 deletions.
45 changes: 45 additions & 0 deletions .idea/appInsightsSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
0.7.2
--------------
- Add original nmea message to all kind of error, this makes errors easier to analyze
- Bump libraries

0.7.1 (2023-11-20)
--------------
- Add observeBarometricAltitudeAndAccuracyUpdates to get barometric altitude along with accuracy state + allow observeBarometricAltitudeUpdates to specify minimum accuracy to filters events
- Bump libraries


0.7.0 (2022-10-19)
--------------
- Add Nmea throwIfContentInvalid parameter to allow more flexibility when parsing nmea by not throwing any error when content is mal formatted
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ kotlin.code.style=official
SONATYPE_HOST=DEFAULT
RELEASE_SIGNING_ENABLED=true
GROUP=net.samystudio.rxlocationmanager
VERSION_NAME=0.7.2
VERSION_NAME=0.7.2-SNAPSHOT
POM_URL=https://github.com/SamYStudiO/RxLocationManager/
POM_SCM_URL=https://github.com/SamYStudiO/RxLocationManager/
POM_SCM_CONNECTION=scm:git:git://github.com/SamYStudiO/RxLocationManager.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class Nmea(val message: String, throwIfContentInvalid: Boolean = true)
throw NmeaException(BLANK_ERROR_MESSAGE)
}
if (!message.startsWith("$")) {
throw NmeaException(MISSING_DOLLAR_ERROR_MESSAGE, 0)
throw NmeaException(getMissingDollarErrorMessage(message), 0)
}

val validators =
Expand All @@ -34,13 +34,14 @@ abstract class Nmea(val message: String, throwIfContentInvalid: Boolean = true)
}

if (!message.contains("*")) {
throw NmeaException(CANNOT_FIND_CHECKSUM_ERROR_MESSAGE)
throw NmeaException(getCannotFindChecksumErrorMessage(message))
}
if (computeChecksum() != checksum) {
throw NmeaException(
getChecksumErrorMessage(
checksum,
computeChecksum(),
message
),
)
}
Expand Down Expand Up @@ -71,10 +72,13 @@ abstract class Nmea(val message: String, throwIfContentInvalid: Boolean = true)
companion object {
private const val CANNOT_PARSE_INDEX_ERROR_MESSAGE =
"Cannot parse message at index %s with validator %s from source %s"
private const val CHECKSUM_ERROR_MESSAGE = "Message checksum %s doesn't match %s"
private const val CHECKSUM_ERROR_MESSAGE =
"Message checksum %s doesn't match %s from source %s"
internal const val BLANK_ERROR_MESSAGE = "Message is blank"
internal const val MISSING_DOLLAR_ERROR_MESSAGE = "Message should stat with $"
internal const val CANNOT_FIND_CHECKSUM_ERROR_MESSAGE = "Cannot find checksum from message"
internal const val MISSING_DOLLAR_ERROR_MESSAGE =
"Message should stat with $ from source %s"
internal const val CANNOT_FIND_CHECKSUM_ERROR_MESSAGE =
"Cannot find checksum from source %s"

internal fun computeChecksum(message: String): String {
val data = message.split("*")[0]
Expand All @@ -97,6 +101,15 @@ abstract class Nmea(val message: String, throwIfContentInvalid: Boolean = true)
internal fun getChecksumErrorMessage(
expectedChecksum: String,
actualChecksum: String,
) = CHECKSUM_ERROR_MESSAGE.format(expectedChecksum, actualChecksum)
message: String,
) = CHECKSUM_ERROR_MESSAGE.format(expectedChecksum, actualChecksum, message)

internal fun getMissingDollarErrorMessage(
message: String,
) = MISSING_DOLLAR_ERROR_MESSAGE.format(message)

internal fun getCannotFindChecksumErrorMessage(
message: String,
) = CANNOT_FIND_CHECKSUM_ERROR_MESSAGE.format(message)
}
}

0 comments on commit d4aaa26

Please sign in to comment.