Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit d8f67b2

Browse files
Guard these - preventing a crash
1 parent f58aa21 commit d8f67b2

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/mlkit/naturallanguageidentification/index.android.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import {
77
export function identifyNaturalLanguage(options: MLKitNaturalLanguageIdentificationOptions): Promise<MLKitNaturalLanguageIdentificationResult> {
88
return new Promise((resolve, reject) => {
99
try {
10+
if (!options.text) {
11+
reject("'text' property not set to a valid value");
12+
return;
13+
}
14+
1015
const languageIdentifier: com.google.firebase.ml.naturallanguage.languageid.FirebaseLanguageIdentification =
1116
com.google.firebase.ml.naturallanguage.FirebaseNaturalLanguage.getInstance().getLanguageIdentification(
1217
new com.google.firebase.ml.naturallanguage.languageid.FirebaseLanguageIdentificationOptions.Builder()

src/mlkit/naturallanguageidentification/index.ios.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import {
77
export function identifyNaturalLanguage(options: MLKitNaturalLanguageIdentificationOptions): Promise<MLKitNaturalLanguageIdentificationResult> {
88
return new Promise((resolve, reject) => {
99
try {
10+
if (!options.text) {
11+
reject("'text' property not set to a valid value");
12+
return;
13+
}
14+
1015
const naturalLanguage = FIRNaturalLanguage.naturalLanguage();
1116
const languageId = naturalLanguage.languageIdentificationWithOptions(
1217
FIRLanguageIdentificationOptions.alloc().initWithConfidenceThreshold(options.confidenceThreshold || 0.5));

0 commit comments

Comments
 (0)