Skip to content

Commit f9877c0

Browse files
authored
fix(amplify-xcode): Fixing errors during amplify pull (#3536)
* fix(amplify-xcode): Fixing quick start project errors * updating errors names
1 parent 5ddf98c commit f9877c0

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

AmplifyTools/AmplifyXcode/Sources/AmplifyXcodeCore/Commands/CommandImportModels.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@ enum CommandImportModelsTasks {
1313
args: CommandImportModels.TaskArgs) -> AmplifyCommandTaskResult {
1414
let modelsPath = environment.path(for: args.generatedModelsPath)
1515
guard environment.directoryExists(atPath: modelsPath) else {
16-
return .failure(
17-
AmplifyCommandError(
18-
.folderNotFound,
19-
errorDescription: "Amplify generated models not found at \(modelsPath)",
20-
recoverySuggestion: "Run amplify codegen models."))
16+
do {
17+
_ = try environment.createDirectory(atPath: args.generatedModelsPath)
18+
}
19+
catch {
20+
return .failure(
21+
AmplifyCommandError(
22+
.folderNotFound,
23+
errorDescription: "Unable to create a new folder for models at path: \(modelsPath)",
24+
recoverySuggestion: "Run amplify codegen models."))
25+
}
26+
27+
return .success("Amplify models folder created at \(modelsPath)")
2128
}
2229

2330
return .success("Amplify models folder found at \(modelsPath)")

AmplifyTools/AmplifyXcode/Sources/AmplifyXcodeCore/Environment/CommandEnvironment.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ extension CommandEnvironment {
8989
if xcodeProjFiles.count != 1 {
9090
throw AmplifyCommandError(
9191
.xcodeProject,
92+
errorDescription: "Unable to find an Xcode project (i.e. `xcodeproj` file) in directory: \(path)",
93+
recoverySuggestion: "Please create a new Xcode project or import one at \(path).",
9294
error: XcodeProjectError.notFound(path: path))
9395
}
9496
let projectName = xcodeProjFiles[0]

AmplifyTools/AmplifyXcode/Tests/AmplifyXcodeCoreTests/Commands/CommandImportModelsTasksTests.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,19 @@ class CommandImportModelsTasksTests: XCTestCase {
6161
_ = super.directoryExists(atPath: dirPath)
6262
return false
6363
}
64+
65+
override func createDirectory(atPath path: String) throws -> String {
66+
_ = try super.createDirectory(atPath: path)
67+
return "created"
68+
}
6469
}
6570
let environment = FailingEnvironment(basePath: basePath, fileManager: fileManager)
6671
let result = CommandImportModelsTasks.projectHasGeneratedModels(environment: environment, args: taskArgs)
67-
if case .success = result {
72+
guard case .success(let message) = result else {
6873
XCTFail("projectHasGeneratedModels should not have succeeded")
74+
return
6975
}
76+
XCTAssertTrue(message.hasPrefix("Amplify models folder created at"))
7077
}
7178

7279
}

0 commit comments

Comments
 (0)