Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions firebase-vertexai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Unreleased
* [changed] **Breaking Change**: Migrated `FirebaseVertexAIException` from a sealed class to an abstract class, and marked constructor as internal. (#6368)
* [feature] Added support for `title` and `publicationDate` in citations. (#6309)
* [feature] Added support for `frequencyPenalty`, `presencePenalty`, and `HarmBlockMethod`. (#6309)
* [changed] **Breaking Change**: Introduced `Citations` class. Now `CitationMetadata` wraps that type. (#6276)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.google.firebase.vertexai.internal.util.toPublic
import kotlinx.coroutines.TimeoutCancellationException

/** Parent class for any errors that occur from the [FirebaseVertexAI] SDK. */
public sealed class FirebaseVertexAIException(message: String, cause: Throwable? = null) :
public abstract class FirebaseVertexAIException internal constructor(message: String, cause: Throwable? = null) :
RuntimeException(message, cause) {

internal companion object {
Expand Down Expand Up @@ -68,29 +68,29 @@ public sealed class FirebaseVertexAIException(message: String, cause: Throwable?
}

/** Something went wrong while trying to deserialize a response from the server. */
public class SerializationException(message: String, cause: Throwable? = null) :
public class SerializationException
internal constructor(message: String, cause: Throwable? = null) :
FirebaseVertexAIException(message, cause)

/** The server responded with a non 200 response code. */
public class ServerException(message: String, cause: Throwable? = null) :
public class ServerException internal constructor(message: String, cause: Throwable? = null) :
FirebaseVertexAIException(message, cause)

/** The server responded that the API Key is not valid. */
public class InvalidAPIKeyException(message: String, cause: Throwable? = null) :
/** The provided API Key is not valid. */
public class InvalidAPIKeyException
internal constructor(message: String, cause: Throwable? = null) :
FirebaseVertexAIException(message, cause)

/**
* A request was blocked for some reason.
* A request was blocked.
*
* See the [response's][response] `promptFeedback.blockReason` for more information.
*
* @property response the full server response for the request.
* @property response The full server response.
*/
// TODO(rlazo): Add secondary constructor to pass through the message?
public class PromptBlockedException(
public val response: GenerateContentResponse,
cause: Throwable? = null
) :
public class PromptBlockedException
internal constructor(public val response: GenerateContentResponse, cause: Throwable? = null) :
FirebaseVertexAIException(
"Prompt was blocked: ${response.promptFeedback?.blockReason?.name}",
cause,
Expand All @@ -104,26 +104,24 @@ public class PromptBlockedException(
* (countries and territories) where the API is available.
*/
// TODO(rlazo): Add secondary constructor to pass through the message?
public class UnsupportedUserLocationException(cause: Throwable? = null) :
public class UnsupportedUserLocationException internal constructor(cause: Throwable? = null) :
FirebaseVertexAIException("User location is not supported for the API use.", cause)

/**
* Some form of state occurred that shouldn't have.
*
* Usually indicative of consumer error.
*/
public class InvalidStateException(message: String, cause: Throwable? = null) :
public class InvalidStateException internal constructor(message: String, cause: Throwable? = null) :
FirebaseVertexAIException(message, cause)

/**
* A request was stopped during generation for some reason.
*
* @property response the full server response for the request
* @property response The full server response.
*/
public class ResponseStoppedException(
public val response: GenerateContentResponse,
cause: Throwable? = null
) :
public class ResponseStoppedException
internal constructor(public val response: GenerateContentResponse, cause: Throwable? = null) :
FirebaseVertexAIException(
"Content generation stopped. Reason: ${response.candidates.first().finishReason?.name}",
cause,
Expand All @@ -134,7 +132,8 @@ public class ResponseStoppedException(
*
* Usually occurs due to a user specified [timeout][RequestOptions.timeout].
*/
public class RequestTimeoutException(message: String, cause: Throwable? = null) :
public class RequestTimeoutException
internal constructor(message: String, cause: Throwable? = null) :
FirebaseVertexAIException(message, cause)

/**
Expand All @@ -143,17 +142,19 @@ public class RequestTimeoutException(message: String, cause: Throwable? = null)
* For a list of valid locations, see
* [Vertex AI locations.](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions)
*/
public class InvalidLocationException(location: String, cause: Throwable? = null) :
public class InvalidLocationException
internal constructor(location: String, cause: Throwable? = null) :
FirebaseVertexAIException("Invalid location \"${location}\"", cause)

/**
* The service is not enabled for this Firebase project. Learn how to enable the required services
* in the
* [Firebase documentation.](https://firebase.google.com/docs/vertex-ai/faq-and-troubleshooting#required-apis)
*/
public class ServiceDisabledException(message: String, cause: Throwable? = null) :
public class ServiceDisabledException
internal constructor(message: String, cause: Throwable? = null) :
FirebaseVertexAIException(message, cause)

/** Catch all case for exceptions not explicitly expected. */
public class UnknownException(message: String, cause: Throwable? = null) :
public class UnknownException internal constructor(message: String, cause: Throwable? = null) :
FirebaseVertexAIException(message, cause)
Loading