Skip to content

Commit 3984f42

Browse files
committed
Merge branch 'main' into strictmode_diskread_violation
2 parents 0722252 + e91c467 commit 3984f42

File tree

12 files changed

+49
-214
lines changed

12 files changed

+49
-214
lines changed

.github/workflows/ci_tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
- name: Add google-services.json
6565
env:
6666
INTEG_TESTS_GOOGLE_SERVICES: ${{ secrets.INTEG_TESTS_GOOGLE_SERVICES }}
67+
if: env.INTEG_TESTS_GOOGLE_SERVICES != '' && env.INTEG_TESTS_GOOGLE_SERVICES != 'null'
6768
run: |
6869
echo $INTEG_TESTS_GOOGLE_SERVICES | base64 -d > google-services.json
6970
@@ -129,6 +130,7 @@ jobs:
129130
- name: Add google-services.json
130131
env:
131132
INTEG_TESTS_GOOGLE_SERVICES: ${{ secrets.INTEG_TESTS_GOOGLE_SERVICES }}
133+
if: env.INTEG_TESTS_GOOGLE_SERVICES != '' && env.INTEG_TESTS_GOOGLE_SERVICES != 'null'
132134
run: |
133135
echo $INTEG_TESTS_GOOGLE_SERVICES | base64 -d > google-services.json
134136
- uses: google-github-actions/auth@71f986410dfbc7added4569d411d040a91dc6935 # v2.1.8

firebase-ai/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
- [changed] Removed redundant internal exception types. (#7475)
4+
35
# 17.4.0
46

57
- [changed] **Breaking Change**: Removed the `candidateCount` option from `LiveGenerationConfig`

firebase-ai/src/main/kotlin/com/google/firebase/ai/ImagenModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package com.google.firebase.ai
1919
import com.google.firebase.FirebaseApp
2020
import com.google.firebase.ai.common.APIController
2121
import com.google.firebase.ai.common.AppCheckHeaderProvider
22-
import com.google.firebase.ai.common.ContentBlockedException
2322
import com.google.firebase.ai.common.GenerateImageRequest
23+
import com.google.firebase.ai.type.ContentBlockedException
2424
import com.google.firebase.ai.type.Dimensions
2525
import com.google.firebase.ai.type.FirebaseAIException
2626
import com.google.firebase.ai.type.ImagenEditMode

firebase-ai/src/main/kotlin/com/google/firebase/ai/common/APIController.kt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,26 @@ import com.google.firebase.Firebase
2121
import com.google.firebase.FirebaseApp
2222
import com.google.firebase.ai.common.util.decodeToFlow
2323
import com.google.firebase.ai.common.util.fullModelName
24+
import com.google.firebase.ai.type.APINotConfiguredException
2425
import com.google.firebase.ai.type.CountTokensResponse
2526
import com.google.firebase.ai.type.FinishReason
27+
import com.google.firebase.ai.type.FirebaseAIException
2628
import com.google.firebase.ai.type.GRpcErrorResponse
2729
import com.google.firebase.ai.type.GenerateContentResponse
2830
import com.google.firebase.ai.type.GenerativeBackend
2931
import com.google.firebase.ai.type.GenerativeBackendEnum
3032
import com.google.firebase.ai.type.ImagenGenerationResponse
33+
import com.google.firebase.ai.type.InvalidAPIKeyException
34+
import com.google.firebase.ai.type.PromptBlockedException
3135
import com.google.firebase.ai.type.PublicPreviewAPI
36+
import com.google.firebase.ai.type.QuotaExceededException
3237
import com.google.firebase.ai.type.RequestOptions
3338
import com.google.firebase.ai.type.Response
39+
import com.google.firebase.ai.type.ResponseStoppedException
40+
import com.google.firebase.ai.type.SerializationException
41+
import com.google.firebase.ai.type.ServerException
42+
import com.google.firebase.ai.type.ServiceDisabledException
43+
import com.google.firebase.ai.type.UnsupportedUserLocationException
3444
import com.google.firebase.options
3545
import io.ktor.client.HttpClient
3646
import io.ktor.client.call.body
@@ -149,7 +159,7 @@ internal constructor(
149159
.body<GenerateContentResponse.Internal>()
150160
.validate()
151161
} catch (e: Throwable) {
152-
throw FirebaseCommonAIException.from(e)
162+
throw FirebaseAIException.from(e)
153163
}
154164

155165
suspend fun generateImage(request: GenerateImageRequest): ImagenGenerationResponse.Internal =
@@ -162,7 +172,7 @@ internal constructor(
162172
.also { validateResponse(it) }
163173
.body<ImagenGenerationResponse.Internal>()
164174
} catch (e: Throwable) {
165-
throw FirebaseCommonAIException.from(e)
175+
throw FirebaseAIException.from(e)
166176
}
167177

168178
private fun getBidiEndpoint(location: String): String =
@@ -187,7 +197,7 @@ internal constructor(
187197
applyCommonConfiguration(request)
188198
}
189199
.map { it.validate() }
190-
.catch { throw FirebaseCommonAIException.from(it) }
200+
.catch { throw FirebaseAIException.from(it) }
191201

192202
suspend fun countTokens(request: CountTokensRequest): CountTokensResponse.Internal =
193203
try {
@@ -199,7 +209,7 @@ internal constructor(
199209
.also { validateResponse(it) }
200210
.body()
201211
} catch (e: Throwable) {
202-
throw FirebaseCommonAIException.from(e)
212+
throw FirebaseAIException.from(e)
203213
}
204214

205215
private fun HttpRequestBuilder.applyCommonHeaders() {
@@ -372,9 +382,9 @@ private fun GenerateContentResponse.Internal.validate() = apply {
372382
if ((candidates?.isEmpty() != false) && promptFeedback == null) {
373383
throw SerializationException("Error deserializing response, found no valid fields")
374384
}
375-
promptFeedback?.blockReason?.let { throw PromptBlockedException(this) }
385+
promptFeedback?.blockReason?.let { throw PromptBlockedException(this.toPublic(), null, null) }
376386
candidates
377387
?.mapNotNull { it.finishReason }
378388
?.firstOrNull { it != FinishReason.Internal.STOP }
379-
?.let { throw ResponseStoppedException(this) }
389+
?.let { throw ResponseStoppedException(this.toPublic()) }
380390
}

firebase-ai/src/main/kotlin/com/google/firebase/ai/common/Exceptions.kt

Lines changed: 0 additions & 159 deletions
This file was deleted.

firebase-ai/src/main/kotlin/com/google/firebase/ai/common/util/serialization.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.google.firebase.ai.common.util
1818

1919
import android.util.Log
20-
import com.google.firebase.ai.common.SerializationException
20+
import com.google.firebase.ai.type.SerializationException
2121
import kotlin.reflect.KClass
2222
import kotlinx.serialization.KSerializer
2323
import kotlinx.serialization.SerialName

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/Exceptions.kt

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.google.firebase.ai.type
1818

1919
import com.google.firebase.ai.FirebaseAI
20-
import com.google.firebase.ai.common.FirebaseCommonAIException
2120
import kotlinx.coroutines.TimeoutCancellationException
2221

2322
/** Parent class for any errors that occur from the [FirebaseAI] SDK. */
@@ -35,36 +34,6 @@ internal constructor(message: String, cause: Throwable? = null) : RuntimeExcepti
3534
internal fun from(cause: Throwable): FirebaseAIException =
3635
when (cause) {
3736
is FirebaseAIException -> cause
38-
is FirebaseCommonAIException ->
39-
when (cause) {
40-
is com.google.firebase.ai.common.SerializationException ->
41-
SerializationException(cause.message ?: "", cause.cause)
42-
is com.google.firebase.ai.common.ServerException ->
43-
ServerException(cause.message ?: "", cause.cause)
44-
is com.google.firebase.ai.common.InvalidAPIKeyException ->
45-
InvalidAPIKeyException(cause.message ?: "")
46-
is com.google.firebase.ai.common.PromptBlockedException ->
47-
PromptBlockedException(cause.response?.toPublic(), cause.cause)
48-
is com.google.firebase.ai.common.UnsupportedUserLocationException ->
49-
UnsupportedUserLocationException(cause.cause)
50-
is com.google.firebase.ai.common.InvalidStateException ->
51-
InvalidStateException(cause.message ?: "", cause)
52-
is com.google.firebase.ai.common.ResponseStoppedException ->
53-
ResponseStoppedException(cause.response.toPublic(), cause.cause)
54-
is com.google.firebase.ai.common.RequestTimeoutException ->
55-
RequestTimeoutException(cause.message ?: "", cause.cause)
56-
is com.google.firebase.ai.common.ServiceDisabledException ->
57-
ServiceDisabledException(cause.message ?: "", cause.cause)
58-
is com.google.firebase.ai.common.UnknownException ->
59-
UnknownException(cause.message ?: "", cause.cause)
60-
is com.google.firebase.ai.common.ContentBlockedException ->
61-
ContentBlockedException(cause.message ?: "", cause.cause)
62-
is com.google.firebase.ai.common.QuotaExceededException ->
63-
QuotaExceededException(cause.message ?: "", cause.cause)
64-
is com.google.firebase.ai.common.APINotConfiguredException ->
65-
APINotConfiguredException(cause.message ?: "", cause.cause)
66-
else -> UnknownException(cause.message ?: "", cause)
67-
}
6837
is TimeoutCancellationException ->
6938
RequestTimeoutException("The request failed to complete in the allotted time.")
7039
else -> UnknownException("Something unexpected happened.", cause)
@@ -238,3 +207,18 @@ public class PermissionMissingException(message: String, cause: Throwable? = nul
238207
/** Catch all case for exceptions not explicitly expected. */
239208
public class UnknownException internal constructor(message: String, cause: Throwable? = null) :
240209
FirebaseAIException(message, cause)
210+
211+
internal fun makeMissingCaseException(
212+
source: String,
213+
ordinal: Int
214+
): com.google.firebase.ai.type.SerializationException {
215+
return com.google.firebase.ai.type.SerializationException(
216+
"""
217+
|Missing case for a $source: $ordinal
218+
|This error indicates that one of the `toInternal` conversions needs updating.
219+
|If you're a developer seeing this exception, please file an issue on our GitHub repo:
220+
|https://github.com/firebase/firebase-android-sdk
221+
"""
222+
.trimMargin()
223+
)
224+
}

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/HarmBlockMethod.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.firebase.ai.type
1818

19-
import com.google.firebase.ai.common.makeMissingCaseException
2019
import kotlinx.serialization.SerialName
2120
import kotlinx.serialization.Serializable
2221

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/HarmBlockThreshold.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.firebase.ai.type
1818

19-
import com.google.firebase.ai.common.makeMissingCaseException
2019
import kotlinx.serialization.SerialName
2120
import kotlinx.serialization.Serializable
2221

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/HarmCategory.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.firebase.ai.type
1818

19-
import com.google.firebase.ai.common.makeMissingCaseException
2019
import com.google.firebase.ai.common.util.FirstOrdinalSerializer
2120
import kotlinx.serialization.KSerializer
2221
import kotlinx.serialization.SerialName

0 commit comments

Comments
 (0)