Skip to content

Commit

Permalink
Print invalid received reports
Browse files Browse the repository at this point in the history
  • Loading branch information
F43nd1r committed Oct 12, 2023
1 parent 4092fca commit fa0b2bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Expand Up @@ -21,7 +21,6 @@ import com.faendir.acra.persistence.bug.BugRepository
import com.faendir.acra.persistence.device.DeviceRepository
import com.faendir.acra.persistence.report.Report
import com.faendir.acra.persistence.report.ReportRepository
import com.faendir.acra.persistence.version.VersionKey
import com.faendir.acra.persistence.version.VersionRepository
import com.faendir.acra.settings.AcrariumConfiguration
import com.faendir.acra.util.findInt
Expand All @@ -30,6 +29,7 @@ import com.faendir.acra.util.toDate
import org.acra.ReportField
import org.intellij.lang.annotations.Language
import org.jooq.JSON
import org.json.JSONException
import org.json.JSONObject
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.stereotype.Service
Expand Down Expand Up @@ -57,7 +57,12 @@ class ReportService(
): Report {
val appId = appRepository.findId(reporterUserName) ?: throw IllegalArgumentException("No app for reporter $reporterUserName")

val json = JSONObject(content)

val json = try {
JSONObject(content)
} catch (e: JSONException) {
throw IllegalArgumentException("Invalid JSON:\n$content", e)
}

val stacktrace = json.getString(ReportField.STACK_TRACE.name)
val bugIdentifier = BugIdentifier.fromStacktrace(acrariumConfiguration, appId, stacktrace)
Expand Down
@@ -1,5 +1,5 @@
/*
* (C) Copyright 2022 Lukas Morawietz (https://github.com/F43nd1r)
* (C) Copyright 2022-2023 Lukas Morawietz (https://github.com/F43nd1r)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@ package com.faendir.acra.navigation

import com.faendir.acra.persistence.app.AppId
import com.faendir.acra.persistence.bug.BugId
import com.faendir.acra.util.*
import com.faendir.acra.util.toNullable
import com.vaadin.flow.component.UI
import com.vaadin.flow.router.BeforeEnterEvent
import com.vaadin.flow.router.BeforeEnterListener
Expand Down Expand Up @@ -49,8 +49,9 @@ class RouteParams : UIInitListener, BeforeEnterListener {
fun installationId(): String = parse(PARAM_INSTALLATION) { it }

fun <T> parse(param: String, parse: (String) -> T?): T {
return parse(cache[UI.getCurrent().uiId]?.get(param)?.toNullable() ?: throw IllegalArgumentException("Parameter $param not present"))
?: throw IllegalArgumentException("Parse failure for parameter $param")
val id = UI.getCurrent()?.uiId ?: throw IllegalStateException("No UI present")
val value = cache[id]?.get(param)?.toNullable() ?: throw IllegalArgumentException("Parameter $param not present")
return parse(value) ?: throw IllegalArgumentException("Parse failure for parameter $param")
}
}

Expand Down

0 comments on commit fa0b2bb

Please sign in to comment.