Skip to content

Commit 9b4331a

Browse files
committed
DataConnectOperationException added
1 parent d0dc250 commit 9b4331a

19 files changed

+971
-679
lines changed

firebase-dataconnect/api.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,47 @@ package com.google.firebase.dataconnect {
4242
ctor public DataConnectException(String message, Throwable? cause = null);
4343
}
4444

45+
public class DataConnectOperationException extends com.google.firebase.dataconnect.DataConnectException {
46+
ctor public DataConnectOperationException(String message, Throwable? cause = null, com.google.firebase.dataconnect.DataConnectOperationFailureResponse<? extends java.lang.Object?> response);
47+
method public final com.google.firebase.dataconnect.DataConnectOperationFailureResponse<? extends java.lang.Object?> getResponse();
48+
property public final com.google.firebase.dataconnect.DataConnectOperationFailureResponse<? extends java.lang.Object?> response;
49+
}
50+
51+
public interface DataConnectOperationFailureResponse<Data> {
52+
method public Data? getData();
53+
method public java.util.List<com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo> getErrors();
54+
method public java.util.Map<java.lang.String,java.lang.Object?>? getRawData();
55+
method public String toString();
56+
property public abstract Data? data;
57+
property public abstract java.util.List<com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo> errors;
58+
property public abstract java.util.Map<java.lang.String,java.lang.Object?>? rawData;
59+
}
60+
61+
public static interface DataConnectOperationFailureResponse.ErrorInfo {
62+
method public boolean equals(Object? other);
63+
method public String getMessage();
64+
method public java.util.List<com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo.PathSegment> getPath();
65+
method public int hashCode();
66+
method public String toString();
67+
property public abstract String message;
68+
property public abstract java.util.List<com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo.PathSegment> path;
69+
}
70+
71+
public static sealed interface DataConnectOperationFailureResponse.ErrorInfo.PathSegment {
72+
}
73+
74+
@kotlin.jvm.JvmInline public static final value class DataConnectOperationFailureResponse.ErrorInfo.PathSegment.Field implements com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo.PathSegment {
75+
ctor public DataConnectOperationFailureResponse.ErrorInfo.PathSegment.Field(String field);
76+
method public String getField();
77+
property public final String field;
78+
}
79+
80+
@kotlin.jvm.JvmInline public static final value class DataConnectOperationFailureResponse.ErrorInfo.PathSegment.ListIndex implements com.google.firebase.dataconnect.DataConnectOperationFailureResponse.ErrorInfo.PathSegment {
81+
ctor public DataConnectOperationFailureResponse.ErrorInfo.PathSegment.ListIndex(int index);
82+
method public int getIndex();
83+
property public final int index;
84+
}
85+
4586
public final class DataConnectSettings {
4687
ctor public DataConnectSettings(String host = "firebasedataconnect.googleapis.com", boolean sslEnabled = true);
4788
method public String getHost();

firebase-dataconnect/firebase-dataconnect.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ dependencies {
103103

104104
compileOnly(libs.javax.annotation.jsr250)
105105
compileOnly(libs.kotlinx.datetime)
106+
compileOnly(libs.kotlinx.serialization.json)
106107
implementation(libs.grpc.android)
107108
implementation(libs.grpc.kotlin.stub)
108109
implementation(libs.grpc.okhttp)

firebase-dataconnect/src/main/kotlin/com/google/firebase/dataconnect/DataConnectError.kt

Lines changed: 0 additions & 89 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2025 Google LLC
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.google.firebase.dataconnect
18+
19+
/**
20+
* The exception thrown when an error occurs in the execution of a Firebase Data Connect operation
21+
* (that is, a query or mutation). This exception means that a response was, indeed, received from
22+
* the backend but either the response included one or more errors or the client could not
23+
* successfully process the result (for example, decoding the response data failed).
24+
*/
25+
public open class DataConnectOperationException(
26+
message: String,
27+
cause: Throwable? = null,
28+
public val response: DataConnectOperationFailureResponse<*>,
29+
) : DataConnectException(message, cause)
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Copyright 2025 Google LLC
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.google.firebase.dataconnect
18+
19+
// Googlers see go/dataconnect:sdk:partial-errors for design details.
20+
21+
/** The data and errors provided by the backend in the response message. */
22+
public interface DataConnectOperationFailureResponse<Data> {
23+
24+
/**
25+
* The raw, un-decoded data provided by the backend in the response message. Will be `null` if,
26+
* and only if, the backend explicitly sent null for the data or if the data was not present in
27+
* the response.
28+
*
29+
* Otherwise, the values in the map will be one of the following:
30+
* * `null`
31+
* * [String]
32+
* * [Boolean]
33+
* * [Double]
34+
* * [List] containing any of the types in this list of types
35+
* * [Map] with [String] keys and values of of the types in this list of types
36+
*
37+
* Consider using [toJson] to get a higher-level object.
38+
*/
39+
public val rawData: Map<String, Any?>?
40+
41+
/**
42+
* The list of errors provided by the backend in the response message; may be empty.
43+
*
44+
* See https://spec.graphql.org/draft/#sec-Errors for details.
45+
*/
46+
public val errors: List<ErrorInfo>
47+
48+
/**
49+
* The successfully-decoded [rawData], if any.
50+
*
51+
* Will be `null` if [rawData] is `null`, or if decoding the [rawData] failed.
52+
*/
53+
public val data: Data?
54+
55+
/**
56+
* Returns a string representation of this object, useful for debugging.
57+
*
58+
* The string representation is _not_ guaranteed to be stable and may change without notice at any
59+
* time. Therefore, the only recommended usage of the returned string is debugging and/or logging.
60+
* Namely, parsing the returned string or storing the returned string in non-volatile storage
61+
* should generally be avoided in order to be robust in case that the string representation
62+
* changes.
63+
*
64+
* @return a string representation of this object, which includes the class name and the values of
65+
* all public properties.
66+
*/
67+
override fun toString(): String
68+
69+
/**
70+
* Information about the error, as provided in the response payload from the backend.
71+
*
72+
* See https://spec.graphql.org/draft/#sec-Errors for details.
73+
*/
74+
public interface ErrorInfo {
75+
/** The error's message. */
76+
public val message: String
77+
78+
/** The path of the field in the response data to which this error relates. */
79+
public val path: List<PathSegment>
80+
81+
/**
82+
* Compares this object with another object for equality.
83+
*
84+
* @param other The object to compare to this for equality.
85+
* @return true if, and only if, the other object is an instance of the same implementation of
86+
* [ErrorInfo] whose public properties compare equal using the `==` operator to the
87+
* corresponding properties of this object.
88+
*/
89+
override fun equals(other: Any?): Boolean
90+
91+
/**
92+
* Calculates and returns the hash code for this object.
93+
*
94+
* The hash code is _not_ guaranteed to be stable across application restarts.
95+
*
96+
* @return the hash code for this object, that incorporates the values of this object's public
97+
* properties.
98+
*/
99+
override fun hashCode(): Int
100+
101+
/**
102+
* Returns a string representation of this object, useful for debugging.
103+
*
104+
* The string representation is _not_ guaranteed to be stable and may change without notice at
105+
* any time. Therefore, the only recommended usage of the returned string is debugging and/or
106+
* logging. Namely, parsing the returned string or storing the returned string in non-volatile
107+
* storage should generally be avoided in order to be robust in case that the string
108+
* representation changes.
109+
*
110+
* @return a string representation of this object, suitable for logging the error indicated by
111+
* this object; it will include the path formatted into a human-readable string (if the path is
112+
* not empty), and the message.
113+
*/
114+
override fun toString(): String
115+
116+
/** The "segment" of a path to a field in the response data. */
117+
public sealed interface PathSegment {
118+
119+
/** A named field in a path to a field in the response data. */
120+
@JvmInline
121+
public value class Field(public val field: String) : PathSegment {
122+
123+
/**
124+
* Returns a string representation of this object, useful for debugging.
125+
*
126+
* The string representation is _not_ guaranteed to be stable and may change without notice
127+
* at any time. Therefore, the only recommended usage of the returned string is debugging
128+
* and/or logging. Namely, parsing the returned string or storing the returned string in
129+
* non-volatile storage should generally be avoided in order to be robust in case that the
130+
* string representation changes.
131+
*
132+
* @return returns simply [field].
133+
*/
134+
override fun toString(): String = field
135+
}
136+
137+
/** An index of a list in a path to a field in the response data. */
138+
@JvmInline
139+
public value class ListIndex(public val index: Int) : PathSegment {
140+
/**
141+
* Returns a string representation of this object, useful for debugging.
142+
*
143+
* The string representation is _not_ guaranteed to be stable and may change without notice
144+
* at any time. Therefore, the only recommended usage of the returned string is debugging
145+
* and/or logging. Namely, parsing the returned string or storing the returned string in
146+
* non-volatile storage should generally be avoided in order to be robust in case that the
147+
* string representation changes.
148+
*
149+
* @return returns simply the string representation of [index].
150+
*/
151+
override fun toString(): String = index.toString()
152+
}
153+
}
154+
}
155+
}

firebase-dataconnect/src/main/kotlin/com/google/firebase/dataconnect/DataConnectUntypedData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import kotlinx.serialization.encoding.Decoder
2222

2323
internal class DataConnectUntypedData(
2424
val data: Map<String, Any?>?,
25-
val errors: List<DataConnectError>
25+
val errors: List<DataConnectOperationFailureResponse.ErrorInfo>
2626
) {
2727

2828
override fun equals(other: Any?) =

0 commit comments

Comments
 (0)