Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report error when fails to write mock file #193

Merged
merged 4 commits into from
Jul 2, 2022

Conversation

maiyama18
Copy link
Contributor

Close #189

This PR makes mockolo command report error in log message and finish with non-zero exit code when it fails to create mock file. Change of the log message for that situation is shown below.

before

❯ mockolo --sourcedirs Path/To/SourceDir --destination /NonexistentDirectory/Mocks.swift
Start...
["Process input mock files..."]
["Took", 4.1961669921875e-05]
["Process source files and generate an annotated/protocol map..."]
["Took", 0.023231029510498047]
["Resolve inheritance and generate unique entity models..."]
["Took", 0.0008450746536254883]
["Render models with templates..."]
["Took", 0.0002319812774658203]
["Write the mock results and import lines to", "/NonexistentDirectory/Mocks.swift"]
["Took", 0.0001609325408935547]
["TOTAL", 0.024510979652404785]
["#Protocols = 3, #Annotated protocols = 3, #Parent mock classes = 0, #Final mock classes = 3, File LoC = 77"]
["Done. Exiting program."]
Done.

after

❯ mockolo --sourcedirs Path/To/SourceDir --destination /NonexistentDirectory/Mocks.swift
Start...
["Process input mock files..."]
["Took", 6.496906280517578e-05]
["Process source files and generate an annotated/protocol map..."]
["Took", 0.07189595699310303]
["Resolve inheritance and generate unique entity models..."]
["Took", 7.808208465576172e-05]
["Render models with templates..."]
["Took", 9.894371032714844e-06]
["Write the mock results and import lines to", "/NonexistentDirectory/Mocks.swift"]
Mockolo/Executor.swift:213: Fatal error: Generation error: Error Domain=NSCocoaErrorDomain Code=4 "The folder “Mocks.swift” doesn’t exist." UserInfo={NSFilePath=/NonexistentDirectory/Mocks.swift, NSUserStringVariant=Folder, NSUnderlyingError=0x600003ce90e0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
zsh: trace trap  .build/arm64-apple-macosx/debug/mockolo --sourcedirs Sources --destination

@@ -46,7 +46,7 @@ func write(candidates: [(String, Int64)],
return ret
}

_ = try? ret.write(toFile: outputFilePath, atomically: true, encoding: .utf8)
_ = try ret.write(toFile: outputFilePath, atomically: true, encoding: .utf8)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several options to resolve #189, but I thought that not ignoring write error is more versatile than others. Since mockolo command's primary purpose is creating mock file, it seems natural to finish whole process and report this error as the cause when failed to write mock file.

@CLAassistant
Copy link

CLAassistant commented Jun 23, 2022

CLA assistant check
All committers have signed the CLA.

Tests/MockoloTestCase.swift Outdated Show resolved Hide resolved
@uhooi uhooi merged commit 5317796 into uber:master Jul 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fails silently when destination directory does not exist
3 participants