@@ -117,27 +117,14 @@ private object AnonymousFeedback {
117117 labels = listOf (Label ().apply { name = issueLabel })
118118 }
119119
120- private fun generateGitHubIssueBody (details : MutableMap <String , String >, includeStacktrace : Boolean ): String {
121- val errorDescription = details.remove(" error.description" ).orEmpty()
122- val stackTrace = details.remove(" error.stacktrace" )?.takeIf (String ::isNotBlank) ? : " invalid stacktrace"
123- val result = StringBuilder ()
124- if (errorDescription.isNotEmpty()) {
125- result.append(errorDescription)
126- result.appendln(" \n\n ----------------------\n " )
127- }
128- for ((key, value) in details) {
129- result.append(" - " )
130- result.append(key)
131- result.append(" : " )
132- result.appendln(value)
133- }
134- if (includeStacktrace) {
135- result.appendln(" \n ```" )
136- result.appendln(stackTrace)
137- result.appendln(" ```" )
138- }
139- return result.toString()
140- }
120+ private fun generateGitHubIssueBody (details : MutableMap <String , String >, includeStacktrace : Boolean ) =
121+ buildString {
122+ val errorDescription = details.remove(" error.description" ).orEmpty()
123+ val stackTrace = details.remove(" error.stacktrace" )?.takeIf (String ::isNotBlank) ? : " invalid stacktrace"
124+ if (errorDescription.isNotEmpty()) append(errorDescription).appendln(" \n\n ----------------------\n " )
125+ for ((key, value) in details) append(" - " ).append(key).append(" : " ).appendln(value)
126+ if (includeStacktrace) appendln(" \n ```" ).appendln(stackTrace).appendln(" ```" )
127+ }
141128}
142129
143130private const val initVector = " RandomInitVector"
@@ -171,26 +158,31 @@ private fun encrypt(value: String): String {
171158class GitHubErrorReporter : ErrorReportSubmitter () {
172159 override fun getReportActionText () = ErrorReportBundle .message(" report.error.to.plugin.vendor" )
173160 override fun submit (
174- events : Array <IdeaLoggingEvent >, info : String? , parent : Component , consumer : Consumer <SubmittedReportInfo >) =
175- doSubmit(events[0 ], parent, consumer, GitHubErrorBean (events[0 ].throwable, IdeaLogger .ourLastActionId), info)
161+ events : Array <IdeaLoggingEvent >,
162+ info : String? ,
163+ parent : Component ,
164+ consumer : Consumer <SubmittedReportInfo >): Boolean {
165+ // TODO improve
166+ val event = events.firstOrNull { it.throwable != null } ? : return false
167+ return doSubmit(event, parent, consumer, info)
168+ }
176169
177170 private fun doSubmit (
178171 event : IdeaLoggingEvent ,
179172 parent : Component ,
180173 callback : Consumer <SubmittedReportInfo >,
181- bean : GitHubErrorBean ,
182174 description : String? ): Boolean {
183175 val dataContext = DataManager .getInstance().getDataContext(parent)
184- bean.description = description.toString()
185- bean.message = event.message ? : event. throwable.message.toString()
186- event.throwable?. let { throwable ->
187- IdeErrorsDialog .findPluginId(throwable)?. let { pluginId ->
188- PluginManager .getPlugin(pluginId)?. let { ideaPluginDescriptor ->
189- if ( ! ideaPluginDescriptor.isBundled) {
190- bean.pluginName = ideaPluginDescriptor.name
191- bean.pluginVersion = ideaPluginDescriptor.version
192- }
193- }
176+ val bean = GitHubErrorBean (
177+ event.throwable,
178+ IdeaLogger .ourLastActionId,
179+ description ? : " <No description> " ,
180+ event.message ? : event.throwable.message.toString())
181+ IdeErrorsDialog .findPluginId(event.throwable)?. let { pluginId ->
182+ PluginManager .getPlugin(pluginId)?. let { ideaPluginDescriptor ->
183+ if ( ! ideaPluginDescriptor.isBundled) {
184+ bean.pluginName = ideaPluginDescriptor.name
185+ bean.pluginVersion = ideaPluginDescriptor.version }
194186 }
195187 }
196188
@@ -226,13 +218,20 @@ class GitHubErrorReporter : ErrorReportSubmitter() {
226218 *
227219 * @author patrick (17.06.17).
228220 */
229- class GitHubErrorBean (throwable : Throwable , val lastAction : String ) {
230- val exceptionHash = Arrays .hashCode(throwable.stackTrace).toString()
231- var description = " <null>"
232- var message = " <null>"
221+ class GitHubErrorBean (
222+ throwable : Throwable ,
223+ val lastAction : String ,
224+ val description : String ,
225+ val message : String ) {
226+ val exceptionHash: String
227+ val stackTrace: String
228+ init {
229+ val trace = throwable.stackTrace
230+ exceptionHash = Arrays .hashCode(trace).toString()
231+ stackTrace = trace.joinToString(System .lineSeparator())
232+ }
233233 var pluginName = " "
234234 var pluginVersion = " "
235- var stackTrace = " <null>"
236235 var attachments: List <Attachment > = emptyList()
237236}
238237
0 commit comments