amplify-swift: 1.0.0-rc.1 crashes at runtime when APIPlugin is added but backend does not exist yet

Describe the bug Amplify 1.0.0-rc.1 When the code adds the APIPlugin but the amplify push has not been made yet (there is no API / backend), the execution crashes.

To Reproduce Steps to reproduce the behavior:

  1. Create a new project, create the pod, create the DataStore schema and do a codegen
  2. Initialize amplify in your code with
        do {
//            Amplify.Logging.logLevel = .info
            
            try Amplify.add(plugin: AWSAPIPlugin())
            try Amplify.add(plugin: AWSDataStorePlugin(modelRegistration: AmplifyModels()))
           
            try Amplify.configure()
            print("Amplify initialized")
...

Expected behavior No crash

Screenshots If applicable, add screenshots to help explain your problem.

Environment(please complete the following information):

  • Amplify Framework Version: 1.0.0-rc.1
  • Dependency Manager: cocoapod 1.9.2
  • Swift Version : 5.x

Device Information (please complete the following information):

  • Device: simulator
  • iOS Version: 13.x
  • Specific to simulators:

Additional context Error in my console :

Amplify initialized
==HUB== HubPayload(eventName: "Amplify.configured", context: nil, data: nil)
Fatal error: API category is not configured. Call Amplify.configure() before using any methods on the category.: file /Users/stormacq/Documents/amazon/code/amplify/amplify-mobile-news-blog/amplify-lib-ios-demo/Pods/Amplify/Amplify/Categories/API/AmplifyAPICategory.swift, line 17
2020-05-22 21:18:04.867104+0200 amplify-lib-ios-demo[28171:4552336] Fatal error: API category is not configured. Call Amplify.configure() before using any methods on the category.: file /Users/stormacq/Documents/amazon/code/amplify/amplify-mobile-news-blog/amplify-lib-ios-demo/Pods/Amplify/Amplify/Categories/API/AmplifyAPICategory.swift, line 17

Line that causes the crash

#6	0x0000000101a6b2d0 in AmplifyAPICategory.plugin.getter at /Users/stormacq/Documents/amazon/code/amplify/amplify-mobile-news-blog/amplify-lib-ios-demo/Pods/Amplify/Amplify/Categories/API/AmplifyAPICategory.swift:17

Error message in the debugger :

Thread 5: Fatal error: API category is not configured. Call Amplify.configure() before using any methods on the category.
image

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (5 by maintainers)

Most upvoted comments

I am afraid I can not help anymore. Wait for 1.0.0 to be released and try again with a fresh project and the updated CLI

I am writing a blog post for Amplify Mobile 1.0.0 launch, that will be the missing README 😃 It should not be very long anymore.

Can you check your Auth category is correctly configured ? (you have an Auth property in awsconfiguration.json ? and a 'authproperty inamplify configuration.json` ?)

This is my amplifyconfiguration.json (notice the Auth from awsconfiguration.json is duplicated there, this will be added automatically by amplify CLI when 1.0.0 will be released)

{
    "api": {
        "plugins": {
            "awsAPIPlugin": {
                "amplifyDatasource": {
                    "endpointType": "GraphQL",
                    "endpoint": "https://3sq.appsync-api.eu-west-1.amazonaws.com/graphql",
                    "region": "eu-west-1",
                    "authorizationType": "API_KEY",
                    "apiKey": "da2-cli64d4"
                }
            }
        }
    },
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify/cli",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "AppSync": {
                    "Default": {
                        "ApiUrl": "https://3nrsq.appsync-api.eu-west-1.amazonaws.com/graphql",
                        "Region": "eu-west-1",
                        "AuthMode": "API_KEY",
                        "ApiKey": "da2-cli6dd4",
                        "ClientDatabasePrefix": "amplifyDatasource_API_KEY"
                    }
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "eu-west-1:8761f7",
                            "Region": "eu-west-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "eu-west-1_gjqXwlSJs",
                        "AppClientId": "6sk0",
                        "AppClientSecret": "1q157",
                        "Region": "eu-west-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "OAuth": {
                            "WebDomain": "amplify-lib-ios-demo-amplify.auth.eu-west-1.amazoncognito.com",
                            "AppClientId": "6sk0",
                            "AppClientSecret": "1q57",
                            "SignInRedirectURI": "myapp://",
                            "SignOutRedirectURI": "myapp://",
                            "Scopes": [
                                "phone",
                                "email",
                                "openid",
                                "profile",
                                "aws.cognito.signin.user.admin"
                            ]
                        },
                        "authenticationFlowType": "USER_SRP_AUTH"
                    }
                }
            }
        }
    },
    "predictions": {
        "plugins": {
            "awsPredictionsPlugin": {
                "defaultRegion": "eu-west-1",
                "convert": {
                    "translateText": {
                        "targetLang": "fr",
                        "sourceLang": "en",
                        "region": "eu-west-1",
                        "defaultNetworkPolicy": "auto"
                    }
                }
            }
        }
    }
}

Amplify 1.0.0-rc1 is unreleased yet, this is just a release candidate, the doc is not published yet.

You do not need to use AWSMobileClient anymore

Have a look at my sample project at https://github.com/sebsto/amplify-mobile-news-blog