aws-amplify / aws-sdk-android

AWS SDK for Android. For more information, see our web site:
https://docs.amplify.aws
Other
1.03k stars 548 forks source link

Error in Logcat "Failed to parse HostedUI settings from store" #3188

Closed UrielFrankel closed 1 year ago

UrielFrankel commented 1 year ago

I get an error in the logcat when I start the Android app:

Failed to parse HostedUI settings from store
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object referenceat org.json.JSONTokener.nextCleanInternal(JSONTokener.java:121)
  at org.json.JSONTokener.nextValue(JSONTokener.java:98)
  at org.json.JSONObject.<init>(JSONObject.java:168)
  at org.json.JSONObject.<init>(JSONObject.java:185)
  at com.amazonaws.mobile.client.AWSMobileClient.getHostedUIJSON(AWSMobileClient.java:712)
  at com.amazonaws.mobile.client.AWSMobileClient$2.run(AWSMobileClient.java:617)
  at com.amazonaws.mobile.client.internal.InternalCallback$1.run(InternalCallback.java:101)
  at java.lang.Thread.run(Thread.java:1012)

Can I ignore it?

BTW I made the json a year and a half ago on an old Amplify version - 1.35.4

Which AWS Services are you utilizing? Storage

Provide code snippets (if applicable)

 private fun initAmplify() {
        // https://docs.amplify.aws/lib/storage/getting-started/q/platform/android/#initialize-amplify-storage
        try {
            // Add these lines to add the AWSCognitoAuthPlugin and AWSS3StoragePlugin plugins
            Amplify.addPlugin(AWSCognitoAuthPlugin())
            Amplify.addPlugin(AWSS3StoragePlugin())
            Amplify.configure(applicationContext)
            val plugin = Amplify.Storage.getPlugin("awsS3StoragePlugin") as AWSS3StoragePlugin
            val client = plugin.escapeHatch
            client.setS3ClientOptions(S3ClientOptions.builder().setAccelerateModeEnabled(true).build())
        } catch (error: AmplifyException) {
            Log.e(TAG, "Could not initialize Amplify", error)
        }
    }

Environment(please complete the following information):

Device Information (please complete the following information):

tylerjroach commented 1 year ago

Are you using signInWithWebUI or signInWIthSocialWebUI? If so, then the sdk is failing to read the "Oauth" block of your configuration json. We would need to see your configuration being passed to diagnose.

If you are using SRP sign in and seeing this warning, you could ignore because it would only cause failures on Hosted UI (Web) sign ins.

tylerjroach commented 1 year ago

@UrielFrankel Have you been able to resolve this issue?

UrielFrankel commented 1 year ago

Yes, I upgraded Amplify version and removed the UI from the gradle and the error is gone

JannesNebendahl commented 1 year ago

I have the same issue. @UrielFrankel What have you done when you say "upgraded Amplify version and removed the UI form the gradle"?

tylerjroach commented 1 year ago

@JannesNebendahl, If you are not using web (hosted ui) sign ins, remove the "Oauth" block from your awsconfiguration.json and amplifyconfiguration.json if you have one.

If you are try to use web sign in, please open up a new ticket with your json configuration details and we can help you diagnose what is missing or improperly formatted.

JannesNebendahl commented 1 year ago

I'm using a custom sign in, as described here: https://docs.amplify.aws/lib/auth/signin_with_custom_flow/q/platform/flutter/

I just have a amplifyconfiguration.json file, but without an "Oauth" block inside.

The part where I start to wonder is that a awsconfiguration.json file is mentioned in the error log, but I can't find this file and never recognized it before as well.

My error log looks like this:

I/amplify:flutter:auth_cognito(22656): Added Auth plugin
I/amplify:flutter:api(22656): Added API plugin
D/AWSMobileClient(22656): Using the SignInProviderConfig from `awsconfiguration.json`.
W/AWSMobileClient(22656): Failed to parse HostedUI settings from store
W/AWSMobileClient(22656): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
W/AWSMobileClient(22656):   at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:121)
W/AWSMobileClient(22656):   at org.json.JSONTokener.nextValue(JSONTokener.java:98)
W/AWSMobileClient(22656):   at org.json.JSONObject.<init>(JSONObject.java:165)
W/AWSMobileClient(22656):   at org.json.JSONObject.<init>(JSONObject.java:182)
W/AWSMobileClient(22656):   at com.amazonaws.mobile.client.AWSMobileClient.getHostedUIJSON(AWSMobileClient.java:712)
W/AWSMobileClient(22656):   at com.amazonaws.mobile.client.AWSMobileClient$2.run(AWSMobileClient.java:617)
W/AWSMobileClient(22656):   at com.amazonaws.mobile.client.internal.InternalCallback$1.run(InternalCallback.java:101)
W/AWSMobileClient(22656):   at java.lang.Thread.run(Thread.java:923)

This is my amplifyconfiguration.json file (I replaced all credentials by XXX):

const amplifyconfig = ''' {
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "api": {
        "plugins": {
            "awsAPIPlugin": {
                "SmartGarden": {
                    "endpointType": "GraphQL",
                    "endpoint": "https://XXX.appsync-api.eu-central-1.amazonaws.com/graphql",
                    "region": "eu-central-1",
                    "authorizationType": "API_KEY",
                    "apiKey": "XXX"
                }
            }
        }
    },
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify-cli/0.1.0",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "AppSync": {
                    "Default": {
                        "ApiUrl": "https://XXX.appsync-api.eu-central-1.amazonaws.com/graphql",
                        "Region": "eu-central-1",
                        "AuthMode": "API_KEY",
                        "ApiKey": "XXX",
                        "ClientDatabasePrefix": "SmartGarden_API_KEY"
                    },
                    "SmartGarden_AWS_IAM": {
                        "ApiUrl": "https://XXX.appsync-api.eu-central-1.amazonaws.com/graphql",
                        "Region": "eu-central-1",
                        "AuthMode": "AWS_IAM",
                        "ClientDatabasePrefix": "SmartGarden_AWS_IAM"
                    }
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "eu-central-1:XXX",
                            "Region": "eu-central-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "eu-central-1_XXX",
                        "AppClientId": "XXX",
                        "Region": "eu-central-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH",
                        "mfaConfiguration": "OFF",
                        "mfaTypes": [
                            "SMS"
                        ],
                        "passwordProtectionSettings": {
                            "passwordPolicyMinLength": 8,
                            "passwordPolicyCharacters": []
                        },
                        "signupAttributes": [
                            "EMAIL"
                        ],
                        "socialProviders": [],
                        "usernameAttributes": [
                            "EMAIL"
                        ],
                        "verificationMechanisms": [
                            "EMAIL"
                        ]
                    }
                }
            }
        }
    }
}''';
tylerjroach commented 1 year ago

@JannesNebendahl While this may look alarming as a Warn log in your Logcat, you can safely ignore this message. After further inspection of the block that prints this log, it will display this, not only if hosted ui is configured incorrectly, but if it is not configured at all.

Since you are not using hosted UI, you can ignore.

JannesNebendahl commented 1 year ago

@tylerjroach Okay, this means it is not related to the following error:

W/amplify:aws-api(23633): Websocket listener received a CONNECTION_ERROR event. {"payload":{"errors":[{"errorType":"UnauthorizedException","message":"You are not authorized to make this call.","errorCode":401}]},"type":"connection_error"}
E/amplify:aws-datastore(23633): Failure encountered while attempting to start API sync.
E/amplify:aws-datastore(23633): DataStoreException{message=DataStore subscriptionProcessor failed to start., cause=DataStoreException{message=Error during subscription., cause=ApiException{message=Connection failed., cause=null, recoverySuggestion=Sorry, we don't have a suggested fix for this error yet.}, recoverySuggestion=Evaluate details.}, recoverySuggestion=Check your internet.}
E/amplify:aws-datastore(23633):     at com.amplifyframework.datastore.syncengine.Orchestrator.lambda$startApiSync$3$Orchestrator(Orchestrator.java:308)
E/amplify:aws-datastore(23633):     at com.amplifyframework.datastore.syncengine.-$$Lambda$Orchestrator$PVk58tU0K8ndPJYnH_tRmf4RGwE.subscribe(Unknown Source:2)
E/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.operators.completable.CompletableCreate.subscribeActual(CompletableCreate.java:40)
E/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850)
E/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.operators.completable.CompletablePeek.subscribeActual(CompletablePeek.java:51)
E/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850)
E/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.operators.completable.CompletablePeek.subscribeActual(CompletablePeek.java:51)
E/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850)
E/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.operators.completable.CompletablePeek.subscribeActual(CompletablePeek.java:51)
E/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850)
E/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.operators.completable.CompletableSubscribeOn$SubscribeOnObserver.run(CompletableSubscribeOn.java:64)
E/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.core.Scheduler$DisposeTask.run(Scheduler.java:614)
E/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:65)
E/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:56)
E/amplify:aws-datastore(23633):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/amplify:aws-datastore(23633):     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
E/amplify:aws-datastore(23633):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/amplify:aws-datastore(23633):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/amplify:aws-datastore(23633):     at java.lang.Thread.run(Thread.java:923)
E/amplify:aws-datastore(23633): Caused by: DataStoreException{message=Error during subscription., cause=ApiException{message=Connection failed., cause=null, recoverySuggestion=Sorry, we don't have a suggested fix for this error yet.}, recoverySuggestion=Evaluate details.}
E/amplify:aws-datastore(23633):     at com.amplifyframework.datastore.appsync.AppSyncClient.lambda$subscription$3(AppSyncClient.java:331)
E/amplify:aws-datastore(23633):     at com.amplifyframework.datastore.appsync.-$$Lambda$AppSyncClient$797ziDK0io-qXODzROLOA77stS8.accept(Unknown Source:4)
E/amplify:aws-datastore(23633):     at com.amplifyframework.api.aws.SubscriptionOperation.lambda$null$1$SubscriptionOperation(SubscriptionOperation.java:87)
E/amplify:aws-datastore(23633):     at com.amplifyframework.api.aws.-$$Lambda$SubscriptionOperation$l9lC7Ew6niNmyszMXQSUKS6YhwE.accept(Unknown Source:4)
E/amplify:aws-datastore(23633):     at com.amplifyframework.api.aws.SubscriptionEndpoint.requestSubscription(SubscriptionEndpoint.java:144)
E/amplify:aws-datastore(23633):     at com.amplifyframework.api.aws.SubscriptionOperation.lambda$start$2$SubscriptionOperation(SubscriptionOperation.java:77)
E/amplify:aws-datastore(23633):     at com.amplifyframework.api.aws.-$$Lambda$SubscriptionOperation$dV6kPdbE8Z12Qd0_rE-16cujgUk.run(Unknown Source:2)
E/amplify:aws-datastore(23633):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
E/amplify:aws-datastore(23633):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/amplify:aws-datastore(23633):     ... 3 more
E/amplify:aws-datastore(23633): Caused by: ApiException{message=Connection failed., cause=null, recoverySuggestion=Sorry, we don't have a suggested fix for this error yet.}
E/amplify:aws-datastore(23633):     at com.amplifyframework.api.aws.SubscriptionEndpoint.requestSubscription(SubscriptionEndpoint.java:145)
E/amplify:aws-datastore(23633):     ... 7 more
W/amplify:aws-datastore(23633): API sync failed - transitioning to LOCAL_ONLY.
W/amplify:aws-datastore(23633): DataStoreException{message=DataStore subscriptionProcessor failed to start., cause=DataStoreException{message=Error during subscription., cause=ApiException{message=Connection failed., cause=null, recoverySuggestion=Sorry, we don't have a suggested fix for this error yet.}, recoverySuggestion=Evaluate details.}, recoverySuggestion=Check your internet.}
W/amplify:aws-datastore(23633):     at com.amplifyframework.datastore.syncengine.Orchestrator.lambda$startApiSync$3$Orchestrator(Orchestrator.java:308)
W/amplify:aws-datastore(23633):     at com.amplifyframework.datastore.syncengine.-$$Lambda$Orchestrator$PVk58tU0K8ndPJYnH_tRmf4RGwE.subscribe(Unknown Source:2)
W/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.operators.completable.CompletableCreate.subscribeActual(CompletableCreate.java:40)
W/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850)
W/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.operators.completable.CompletablePeek.subscribeActual(CompletablePeek.java:51)
W/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850)
W/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.operators.completable.CompletablePeek.subscribeActual(CompletablePeek.java:51)
W/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850)
W/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.operators.completable.CompletablePeek.subscribeActual(CompletablePeek.java:51)
W/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.core.Completable.subscribe(Completable.java:2850)
W/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.operators.completable.CompletableSubscribeOn$SubscribeOnObserver.run(CompletableSubscribeOn.java:64)
W/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.core.Scheduler$DisposeTask.run(Scheduler.java:614)
W/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:65)
W/amplify:aws-datastore(23633):     at io.reactivex.rxjava3.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:56)
W/amplify:aws-datastore(23633):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/amplify:aws-datastore(23633):     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
W/amplify:aws-datastore(23633):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
W/amplify:aws-datastore(23633):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/amplify:aws-datastore(23633):     at java.lang.Thread.run(Thread.java:923)
W/amplify:aws-datastore(23633): Caused by: DataStoreException{message=Error during subscription., cause=ApiException{message=Connection failed., cause=null, recoverySuggestion=Sorry, we don't have a suggested fix for this error yet.}, recoverySuggestion=Evaluate details.}
W/amplify:aws-datastore(23633):     at com.amplifyframework.datastore.appsync.AppSyncClient.lambda$subscription$3(AppSyncClient.java:331)
W/amplify:aws-datastore(23633):     at com.amplifyframework.datastore.appsync.-$$Lambda$AppSyncClient$797ziDK0io-qXODzROLOA77stS8.accept(Unknown Source:4)
W/amplify:aws-datastore(23633):     at com.amplifyframework.api.aws.SubscriptionOperation.lambda$null$1$SubscriptionOperation(SubscriptionOperation.java:87)
W/amplify:aws-datastore(23633):     at com.amplifyframework.api.aws.-$$Lambda$SubscriptionOperation$l9lC7Ew6niNmyszMXQSUKS6YhwE.accept(Unknown Source:4)
W/amplify:aws-datastore(23633):     at com.amplifyframework.api.aws.SubscriptionEndpoint.requestSubscription(SubscriptionEndpoint.java:144)
W/amplify:aws-datastore(23633):     at com.amplifyframework.api.aws.SubscriptionOperation.lambda$start$2$SubscriptionOperation(SubscriptionOperation.java:77)
W/amplify:aws-datastore(23633):     at com.amplifyframework.api.aws.-$$Lambda$SubscriptionOperation$dV6kPdbE8Z12Qd0_rE-16cujgUk.run(Unknown Source:2)
W/amplify:aws-datastore(23633):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
W/amplify:aws-datastore(23633):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/amplify:aws-datastore(23633):     ... 3 more
W/amplify:aws-datastore(23633): Caused by: ApiException{message=Connection failed., cause=null, recoverySuggestion=Sorry, we don't have a suggested fix for this error yet.}
W/amplify:aws-datastore(23633):     at com.amplifyframework.api.aws.SubscriptionEndpoint.requestSubscription(SubscriptionEndpoint.java:145)
W/amplify:aws-datastore(23633):     ... 7 more
I/amplify:aws-datastore(23633): Orchestrator transitioning from SYNC_VIA_API to LOCAL_ONLY
I/amplify:aws-datastore(23633): Setting currentState to LOCAL_ONLY
I/amplify:aws-datastore(23633): Stopping subscription processor.
I/amplify:aws-datastore(23633): Stopped subscription processor.

This error appears when the user signs in and the app tries to fetch his data. I thought there could be a correlation, since it is an UnauthorizedException and haven't been there before the above error/warning appeared

tylerjroach commented 1 year ago

@JannesNebendahl I do not believe there would be correlation between the two. Please open up a ticket in the Amplify repo for the issue you are experiencing.