From f9877c04dbf7a16e5589fab64ece59832a33a8e1 Mon Sep 17 00:00:00 2001 From: Harsh <6162866+harsh62@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:51:46 -0500 Subject: [PATCH] fix(amplify-xcode): Fixing errors during amplify pull (#3536) * fix(amplify-xcode): Fixing quick start project errors * updating errors names --- .../Commands/CommandImportModels.swift | 17 ++++++++++++----- .../Environment/CommandEnvironment.swift | 2 ++ .../CommandImportModelsTasksTests.swift | 9 ++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/AmplifyTools/AmplifyXcode/Sources/AmplifyXcodeCore/Commands/CommandImportModels.swift b/AmplifyTools/AmplifyXcode/Sources/AmplifyXcodeCore/Commands/CommandImportModels.swift index 539ed8c209..f1a15061ee 100644 --- a/AmplifyTools/AmplifyXcode/Sources/AmplifyXcodeCore/Commands/CommandImportModels.swift +++ b/AmplifyTools/AmplifyXcode/Sources/AmplifyXcodeCore/Commands/CommandImportModels.swift @@ -13,11 +13,18 @@ enum CommandImportModelsTasks { args: CommandImportModels.TaskArgs) -> AmplifyCommandTaskResult { let modelsPath = environment.path(for: args.generatedModelsPath) guard environment.directoryExists(atPath: modelsPath) else { - return .failure( - AmplifyCommandError( - .folderNotFound, - errorDescription: "Amplify generated models not found at \(modelsPath)", - recoverySuggestion: "Run amplify codegen models.")) + do { + _ = try environment.createDirectory(atPath: args.generatedModelsPath) + } + catch { + return .failure( + AmplifyCommandError( + .folderNotFound, + errorDescription: "Unable to create a new folder for models at path: \(modelsPath)", + recoverySuggestion: "Run amplify codegen models.")) + } + + return .success("Amplify models folder created at \(modelsPath)") } return .success("Amplify models folder found at \(modelsPath)") diff --git a/AmplifyTools/AmplifyXcode/Sources/AmplifyXcodeCore/Environment/CommandEnvironment.swift b/AmplifyTools/AmplifyXcode/Sources/AmplifyXcodeCore/Environment/CommandEnvironment.swift index c11228751d..f27ef1c488 100644 --- a/AmplifyTools/AmplifyXcode/Sources/AmplifyXcodeCore/Environment/CommandEnvironment.swift +++ b/AmplifyTools/AmplifyXcode/Sources/AmplifyXcodeCore/Environment/CommandEnvironment.swift @@ -89,6 +89,8 @@ extension CommandEnvironment { if xcodeProjFiles.count != 1 { throw AmplifyCommandError( .xcodeProject, + errorDescription: "Unable to find an Xcode project (i.e. `xcodeproj` file) in directory: \(path)", + recoverySuggestion: "Please create a new Xcode project or import one at \(path).", error: XcodeProjectError.notFound(path: path)) } let projectName = xcodeProjFiles[0] diff --git a/AmplifyTools/AmplifyXcode/Tests/AmplifyXcodeCoreTests/Commands/CommandImportModelsTasksTests.swift b/AmplifyTools/AmplifyXcode/Tests/AmplifyXcodeCoreTests/Commands/CommandImportModelsTasksTests.swift index 3b9f016bc7..7aa3e807fc 100644 --- a/AmplifyTools/AmplifyXcode/Tests/AmplifyXcodeCoreTests/Commands/CommandImportModelsTasksTests.swift +++ b/AmplifyTools/AmplifyXcode/Tests/AmplifyXcodeCoreTests/Commands/CommandImportModelsTasksTests.swift @@ -61,12 +61,19 @@ class CommandImportModelsTasksTests: XCTestCase { _ = super.directoryExists(atPath: dirPath) return false } + + override func createDirectory(atPath path: String) throws -> String { + _ = try super.createDirectory(atPath: path) + return "created" + } } let environment = FailingEnvironment(basePath: basePath, fileManager: fileManager) let result = CommandImportModelsTasks.projectHasGeneratedModels(environment: environment, args: taskArgs) - if case .success = result { + guard case .success(let message) = result else { XCTFail("projectHasGeneratedModels should not have succeeded") + return } + XCTAssertTrue(message.hasPrefix("Amplify models folder created at")) } }