Skip to content

Commit f055963

Browse files
committed
Fix notifications messages, fix log level, relative paths
- Relative paths entered by user are striped of leading slashed /\ - fixed log depth - wrong stacktrace was taken - changed notification messages' texts
1 parent 83cab85 commit f055963

File tree

9 files changed

+41
-43
lines changed

9 files changed

+41
-43
lines changed

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/Client.kt

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import kotlinx.coroutines.runBlocking
1818
import kotlinx.coroutines.withTimeout
1919
import org.jetbrains.annotations.TestOnly
2020
import org.utbot.cpp.clion.plugin.UTBot
21+
import org.utbot.cpp.clion.plugin.actions.ShowSettingsAction
2122
import org.utbot.cpp.clion.plugin.client.channels.LogChannel
2223
import org.utbot.cpp.clion.plugin.grpc.IllegalPathException
2324
import org.utbot.cpp.clion.plugin.client.logger.ClientLogger
@@ -103,24 +104,9 @@ class Client(
103104
UTBot.message("notify.cancelled", id, e.message ?: ""),
104105
project
105106
)
106-
Status.FAILED_PRECONDITION.code -> notifyError(
107+
Status.FAILED_PRECONDITION.code, Status.INTERNAL.code, Status.UNIMPLEMENTED.code, Status.INVALID_ARGUMENT.code -> notifyError(
107108
UTBot.message("notify.title.failed.precondition"),
108-
UTBot.message("notify.failed.precondition", e.message ?: "", id),
109-
project
110-
)
111-
Status.INTERNAL.code -> notifyError(
112-
UTBot.message("notify.title.internal.error"),
113-
UTBot.message("notify.internal.error", request, e.message ?: ""),
114-
project
115-
)
116-
Status.UNIMPLEMENTED.code -> notifyError(
117-
UTBot.message("notify.title.server.error"),
118-
UTBot.message("notify.unimplemented", id, e.message ?: ""),
119-
project
120-
)
121-
Status.INVALID_ARGUMENT.code -> notifyError(
122-
UTBot.message("notify.title.invalid.argument"),
123-
UTBot.message("notify.invalid.argument", e.message ?: "", id),
109+
UTBot.message("notify.request.failed", e.message ?: "", id),
124110
project
125111
)
126112
else -> notifyError(
@@ -133,7 +119,8 @@ class Client(
133119
notifyError(
134120
UTBot.message("notify.bad.settings.title"),
135121
UTBot.message("notify.bad.path", e.message ?: ""),
136-
project
122+
project,
123+
ShowSettingsAction()
137124
)
138125
}
139126
}

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/handlers/StreamHandler.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import kotlinx.coroutines.flow.Flow
55
import kotlinx.coroutines.flow.cancellable
66
import kotlinx.coroutines.flow.collect
77
import kotlinx.coroutines.flow.onCompletion
8-
import org.tinylog.kotlin.Logger
98

109
/**
1110
* Base class for handling stream of server responses

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/handlers/StreamHandlerWithProgress.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract class StreamHandlerWithProgress<T>(
1717
progressName: String,
1818
cancellationJob: Job
1919
): StreamHandler<T>(project, grpcStream) {
20-
private val indicator = UTBotRequestProgressIndicator(progressName, cancellationJob, project)
20+
protected val indicator = UTBotRequestProgressIndicator(progressName, cancellationJob, project)
2121

2222
override fun onStart() {
2323
super.onStart()
@@ -49,10 +49,10 @@ abstract class StreamHandlerWithProgress<T>(
4949
abstract fun T.getProgress(): Util.Progress
5050

5151
override fun onCompletion(exception: Throwable?) {
52+
invokeOnEdt {
53+
indicator.stop()
54+
}
5255
if (exception != null) {
53-
invokeOnEdt {
54-
indicator.stop()
55-
}
5656
throw exception
5757
}
5858
}

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/handlers/TestsStreamHandler.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.utbot.cpp.clion.plugin.settings.settings
1010
import org.utbot.cpp.clion.plugin.ui.services.TestsResultsStorage
1111
import org.utbot.cpp.clion.plugin.utils.convertFromRemotePathIfNeeded
1212
import org.utbot.cpp.clion.plugin.utils.createFileWithText
13+
import org.utbot.cpp.clion.plugin.utils.invokeOnEdt
1314
import org.utbot.cpp.clion.plugin.utils.isSarifReport
1415
import org.utbot.cpp.clion.plugin.utils.logger
1516
import org.utbot.cpp.clion.plugin.utils.markDirtyAndRefresh
@@ -60,6 +61,9 @@ class TestsStreamHandler(
6061
}
6162

6263
override fun onCompletion(exception: Throwable?) {
64+
invokeOnEdt {
65+
indicator.stop()
66+
}
6367
if (exception != null ) {
6468
if (exception !is CancellationException)
6569
onError(exception)

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/client/logger/ClientLogger.kt

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,31 @@ import com.intellij.openapi.components.Service
55
import com.intellij.openapi.project.Project
66

77
interface Logger {
8-
fun info(message: String, depth: Int = 3) = log({ message }, LogLevel.INFO, depth)
8+
fun info(message: String, depth: Int = DEFAULT_LOG_DEPTH) = log({ message }, LogLevel.INFO, depth)
99

10-
fun warn(message: String, depth: Int = 3) = log({ message }, LogLevel.WARN, depth)
10+
fun warn(message: String, depth: Int = DEFAULT_LOG_DEPTH) = log({ message }, LogLevel.WARN, depth)
1111

12-
fun error(message: String, depth: Int = 3) = log({ message }, LogLevel.ERROR, depth)
12+
fun error(message: String, depth: Int = DEFAULT_LOG_DEPTH) = log({ message }, LogLevel.ERROR, depth)
1313

14-
fun debug(message: String, depth: Int = 3) = log({ message }, LogLevel.DEBUG, depth)
14+
fun debug(message: String, depth: Int = DEFAULT_LOG_DEPTH) = log({ message }, LogLevel.DEBUG, depth)
1515

16-
fun trace(message: String, depth: Int = 3) = log({ message }, LogLevel.TRACE, depth)
16+
fun trace(message: String, depth: Int = DEFAULT_LOG_DEPTH) = log({ message }, LogLevel.TRACE, depth)
1717

18-
fun info(depth: Int = 3, message: () -> String) = log(message, LogLevel.INFO, depth)
18+
fun info(depth: Int = DEFAULT_LOG_DEPTH, message: () -> String) = log(message, LogLevel.INFO, depth)
1919

20-
fun warn(depth: Int = 3, message: () -> String) = log(message, LogLevel.WARN, depth)
20+
fun warn(depth: Int = DEFAULT_LOG_DEPTH, message: () -> String) = log(message, LogLevel.WARN, depth)
2121

22-
fun error(depth: Int = 3, message: () -> String) = log(message, LogLevel.ERROR, depth)
22+
fun error(depth: Int = DEFAULT_LOG_DEPTH, message: () -> String) = log(message, LogLevel.ERROR, depth)
2323

24-
fun debug(depth: Int = 3, message: () -> String) = log(message, LogLevel.DEBUG, depth)
24+
fun debug(depth: Int = DEFAULT_LOG_DEPTH, message: () -> String) = log(message, LogLevel.DEBUG, depth)
2525

26-
fun trace(depth: Int = 3, message: () -> String) = log(message, LogLevel.TRACE, depth)
26+
fun trace(depth: Int = DEFAULT_LOG_DEPTH, message: () -> String) = log(message, LogLevel.TRACE, depth)
2727

28-
fun log(messageSupplier: () -> (String), level: LogLevel, depth: Int = 3)
28+
fun log(messageSupplier: () -> (String), level: LogLevel, depth: Int = DEFAULT_LOG_DEPTH)
29+
30+
companion object {
31+
const val DEFAULT_LOG_DEPTH = 4
32+
}
2933
}
3034

3135
@Service

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/grpc/GrpcRequestBuilder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import java.nio.file.Paths
1010

1111
abstract class ClientException(message: String) : Exception(message)
1212

13-
class IllegalPathException(val path: String, val info: String) :
14-
ClientException("Bad path: $path. Info: $info")
13+
class IllegalPathException(val path: String, val pathName: String, message: String? = null) :
14+
ClientException(message ?: "Illegal: $pathName: $path")
1515

1616

1717
data class RemoteMapping(val localProjectPath: String, val remoteProjectPath: String, val shouldConvert: Boolean = true) {

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/settings/UTBotProjectStoredSettings.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.utbot.cpp.clion.plugin.ui.utbotToolWindow.targetToolWindow.UTBotTarge
1313
import org.utbot.cpp.clion.plugin.ui.wizard.UTBotWizard
1414
import org.utbot.cpp.clion.plugin.utils.invokeOnEdt
1515
import org.utbot.cpp.clion.plugin.utils.path
16+
import org.utbot.cpp.clion.plugin.utils.stripLeadingSlashes
1617
import java.nio.file.Paths
1718

1819
/**
@@ -101,7 +102,7 @@ class UTBotProjectStoredSettings(val project: Project) : PersistentStateComponen
101102
}
102103

103104
var testDirRelativePath: String
104-
get() = myState.testsDirRelativePath
105+
get() = myState.testsDirRelativePath.stripLeadingSlashes()
105106
set(value) {
106107
myState.testsDirRelativePath = value
107108
}
@@ -129,7 +130,7 @@ class UTBotProjectStoredSettings(val project: Project) : PersistentStateComponen
129130
Paths.get(project.path).relativize(Paths.get(targetPath)).toString()
130131

131132
var buildDirRelativePath: String
132-
get() = myState.buildDirRelativePath
133+
get() = myState.buildDirRelativePath.stripLeadingSlashes()
133134
set(value) {
134135
myState.buildDirRelativePath = value
135136
}

clion-plugin/src/main/kotlin/org/utbot/cpp/clion/plugin/utils/PathUtils.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ private fun removeSuffix(path: Path, suffix: String): Path {
184184
)
185185
}
186186

187+
fun String.stripLeadingSlashes() = this.replace("""^[\\/]+""".toRegex(), "")
188+
187189
val VirtualFile.localPath: Path
188190
get() = this.fileSystem.getNioPath(this) ?: error("Could not get filesystem path from $this")
189191

clion-plugin/src/main/resources/messages/UTBot.properties

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,20 @@ notify.title.unknown.server.error=UTBot: Unknown Server Error
7878
notify.unknown.server.error=Server threw an unknown exception
7979
notify.title.cancelled=UTBot: Request was cancelled
8080
#0 - exception message, #1 - request id
81-
notify.cancelled={0}. Request: "{1}" cancelled.
81+
notify.cancelled={0} <br>Request "{1}" cancelled.
82+
notify.request.failed={0}<br>Request "{1}" failed
8283
notify.title.failed.precondition=UTBot: Failed Precondition
83-
notify.failed.precondition={0}. Request: "{1}" failed.
84+
notify.failed.precondition={0} <br>Request "{1}" failed.
8485
notify.title.internal.error=UTBot: Server internal error
8586
#0 - exception message, #1 - request id
86-
notify.internal.error={0}. Request: "{1}" failed.
87+
notify.internal.error={0} <br>Request "{1}" failed.
8788
#0 - exception message, #1 - request id
88-
notify.unimplemented={0}. Request: "{1}" failed.
89+
notify.unimplemented={0} <br>Request "{1}" failed.
8990
notify.title.error=UTBot: Error
9091
notify.title.server.error=UTBot: Server Error
9192
notify.title.invalid.argument=UTBot: Invalid input
9293
#0 - exception message, #1 - request id
93-
notify.invalid.argument={0}. Request: "{1}" failed.
94+
notify.invalid.argument={0} <br>Request "{1}" failed.
9495
notify.coverage.received.title=UTBot: Coverage gathered
9596
notify.coverage.received=Coverage response received from server.
9697
notify.build.dir.created.title=UTBot: Build Directory was created

0 commit comments

Comments
 (0)