1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.wm.flicker.traces 18 19 import com.android.server.wm.flicker.assertions.FlickerSubject 20 import com.android.server.wm.traces.common.prettyTimestamp 21 22 /** 23 * Exception thrown by [FlickerSubject]s 24 */ 25 class FlickerSubjectException( 26 internal val subject: FlickerSubject, 27 cause: Throwable 28 ) : AssertionError(cause.message, if (cause is FlickerSubjectException) null else cause) { 29 internal val timestamp = subject.timestamp 30 private val prettyTimestamp = 31 if (timestamp > 0) "${prettyTimestamp(timestamp)} (timestamp=$timestamp)" else "" 32 33 internal val errorType: String = 34 if (cause is AssertionError) "Flicker assertion error" else "Unknown error" 35 <lambda>null36 internal val errorDescription = buildString { 37 appendln("Where? $prettyTimestamp") 38 val message = (cause.message ?: "").split(("\n")) 39 append("What? ") 40 if (message.size == 1) { 41 // Single line error message 42 appendln(message.first()) 43 } else { 44 // Multi line error message 45 appendln() 46 message.forEach { appendln("\t$it") } 47 } 48 } 49 <lambda>null50 internal val subjectInformation = buildString { 51 appendln("Facts:") 52 subject.completeFacts.forEach { append("\t").appendln(it) } 53 } 54 55 override val message: String <lambda>null56 get() = buildString { 57 appendln(errorType) 58 appendln() 59 append(errorDescription) 60 appendln() 61 append(subjectInformation) 62 } 63 }