-
Notifications
You must be signed in to change notification settings - Fork 626
Added FirebaseMlException and Logging round 1. #2259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fc4307b
Added FirebaseMlException and Logging round 1.
annzimmer 2b49694
Updating files per failed tests.
annzimmer 5cae374
Fixing to single junit.
annzimmer 7c80a09
Updates FirebaseMlLogEvent ModelOption name to Options to make intern…
annzimmer 3b1e244
Add ability to get download id for file progress tracking.
annzimmer 6aa3bb1
removing androidTestImplementation - these are not used.
annzimmer f4d85e8
Merge branch 'master' into mlLogging2
annzimmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
...ldownloader/src/main/java/com/google/firebase/ml/modeldownloader/FirebaseMlException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.ml.modeldownloader; | ||
|
||
import androidx.annotation.IntDef; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import com.google.android.gms.common.internal.Preconditions; | ||
import com.google.firebase.FirebaseException; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
/** | ||
* Represents an Exception resulting from an operation on a {@link FirebaseModelDownloader}. Error | ||
* mappings should remain consistent with the original firebase_ml_sdk whenever possible. | ||
*/ | ||
public class FirebaseMlException extends FirebaseException { | ||
/** The operation was cancelled (typically by the caller). */ | ||
public static final int CANCELLED = 1; | ||
|
||
/** Unknown error or an error from a different error domain. */ | ||
public static final int UNKNOWN = 2; | ||
|
||
/** | ||
* Client specified an invalid argument. Note that this differs from FAILED_PRECONDITION. | ||
* INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the system | ||
* (e.g., an invalid field name). | ||
*/ | ||
public static final int INVALID_ARGUMENT = 3; | ||
|
||
/** | ||
* Deadline expired before operation could complete. For operations that change the state of the | ||
* system, this error may be returned even if the operation has completed successfully. For | ||
* example, a successful response from a server could have been delayed long enough for the | ||
* deadline to expire. | ||
*/ | ||
public static final int DEADLINE_EXCEEDED = 4; | ||
|
||
/** Some requested resource was not found. */ | ||
public static final int NOT_FOUND = 5; | ||
|
||
/** Some resource that we attempted to create already exists. */ | ||
public static final int ALREADY_EXISTS = 6; | ||
|
||
/** The caller does not have permission to execute the specified operation. */ | ||
public static final int PERMISSION_DENIED = 7; | ||
|
||
/** | ||
* Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system | ||
* is out of space. | ||
*/ | ||
public static final int RESOURCE_EXHAUSTED = 8; | ||
|
||
/** | ||
* Operation was rejected because the system is not in a state required for the operation's | ||
* execution. | ||
*/ | ||
public static final int FAILED_PRECONDITION = 9; | ||
|
||
/** | ||
* The operation was aborted, typically due to a concurrency issue like transaction aborts, etc. | ||
*/ | ||
public static final int ABORTED = 10; | ||
|
||
/** Operation was attempted past the valid range. */ | ||
public static final int OUT_OF_RANGE = 11; | ||
|
||
/** Operation is not implemented or not supported/enabled. */ | ||
public static final int UNIMPLEMENTED = 12; | ||
|
||
/** | ||
* Internal errors. Means some invariants expected by underlying system has been broken. If you | ||
* see one of these errors, something is very broken. | ||
*/ | ||
// annz used | ||
public static final int INTERNAL = 13; | ||
|
||
/** | ||
* The service is currently unavailable. This is a most likely a transient condition and may be | ||
* corrected by retrying with a backoff. | ||
* | ||
* <p>In ML Kit, this error is mostly about the models being not available yet. | ||
*/ | ||
public static final int UNAVAILABLE = 14; | ||
|
||
/** The request does not have valid authentication credentials for the operation. */ | ||
public static final int UNAUTHENTICATED = 16; | ||
|
||
// =============================================================================================== | ||
// Error codes: 100 to 149 reserved for errors during model downloading/loading. | ||
/** There is not enough space left on the device. */ | ||
// annz used | ||
public static final int NOT_ENOUGH_SPACE = 101; | ||
|
||
/** | ||
* The set of Firebase ML status codes. The codes are based on <a | ||
* href="https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto">Canonical | ||
* error codes for Google APIs</a> | ||
*/ | ||
@IntDef({ | ||
CANCELLED, | ||
UNKNOWN, | ||
INVALID_ARGUMENT, | ||
DEADLINE_EXCEEDED, | ||
NOT_FOUND, | ||
ALREADY_EXISTS, | ||
PERMISSION_DENIED, | ||
RESOURCE_EXHAUSTED, | ||
FAILED_PRECONDITION, | ||
ABORTED, | ||
OUT_OF_RANGE, | ||
UNIMPLEMENTED, | ||
INTERNAL, | ||
UNAVAILABLE, | ||
UNAUTHENTICATED, | ||
NOT_ENOUGH_SPACE | ||
}) | ||
@Retention(RetentionPolicy.CLASS) | ||
public @interface Code {} | ||
|
||
@Code private final int code; | ||
|
||
/** @hide */ | ||
public FirebaseMlException(@NonNull String detailMessage, @Code int code) { | ||
super(Preconditions.checkNotEmpty(detailMessage, "Provided message must not be empty.")); | ||
this.code = code; | ||
} | ||
|
||
/** @hide */ | ||
public FirebaseMlException( | ||
@NonNull String detailMessage, @Code int code, @Nullable Throwable cause) { | ||
super(Preconditions.checkNotEmpty(detailMessage, "Provided message must not be empty."), cause); | ||
this.code = code; | ||
} | ||
|
||
/** Gets the error code for the Firebase ML operation that failed. */ | ||
@Code | ||
public int getCode() { | ||
return code; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
option 'lite'
(see firebase-firestore.gradle )There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I add that then - JsonFormat.parser().merge fails (based on testLogRequest_jsontToProto) which doesn't use lite option. Can you suggest an alternative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note - the proto is only for testing and shouldn't affect the sdk sizing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right. JsonFormat parser actually requires the full runtime to work. Since it's used for tests, I think you can do the same crashlytics is doing https://github.com/firebase/firebase-android-sdk/blob/master/firebase-crashlytics/firebase-crashlytics.gradle#L88
just use
testImplementation
instead ofandroidTestImplementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed all the androidTestImplementation - these were not used. The encoding was already there for the regular implementation level (and validated it is needed at that level)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK you can just get rid of the whole generateProtoTasks sections.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appears required - gives error when removed:
Execution failed for task ':firebase-ml-modeldownloader:generateDebugUnitTestProto'.
protoc: stdout: . stderr: Missing output directives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thanks for following through!