Skip to content

Add descriptive error when attempting to list tests before building #8046

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

Merged
merged 4 commits into from
Oct 17, 2024

Conversation

plemarquand
Copy link
Contributor

Motivation:

Typically a build is performed before a swift test list command, but by passing the --skip-build flag it is possible to get a cryptic, unhelpful error message if the test artifacts haven't already been built.

Modifications:

Add a descriptive error for this case, only checking for test artifact existence in the failure case to avoid any performance impact on the happy path.

Typically a build is performed before a `swift test list` command, but
by passing the `--skip-build` flag it is possible to get a cryptic,
unhelpful erorr message if the test artifacts haven't already been
built.

Add a descriptive error for this case, only checking for test artifact
existence in the failure case to avoid any performance impact on the
happy path.
try await self.runCommand(swiftCommandState)
} catch let error as FileSystemError {
if sharedOptions.shouldSkipBuilding {
throw ErrorWithContext(error, "Test build artifacts were not found in the build folder. Found the --skip-build flag; build the tests first or rerun the command without --skip-build")
Copy link
Contributor

@MaxDesiatov MaxDesiatov Oct 16, 2024

Choose a reason for hiding this comment

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

Could the error message be more detailed? Which build folder at what path? Can it provide a list of artifacts that were expected to be found? Otherwise it may not be fully actionable for a user if they're willing to investigate what exactly went wrong. Also, "build the tests first" should provide an example command or an exact command for building tests.

Copy link
Contributor Author

@plemarquand plemarquand Oct 16, 2024

Choose a reason for hiding this comment

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

The wrapped error contains the detailed information about what file wasn't found. Here is the error message as it stands right now:

error: 	Test build artifacts were not found in the build folder.
	The `--skip-build` flag was provided; either build the tests first with `swift build --build tests` or rerun the `swift test list` command without `--skip-build`
	/Users/plemarquand/work/testapps/TestApp/.build/arm64-apple-macosx/debug/TestAppPackageTests.xctest doesn't exist in file system

Because the xctest codepath throws a FileSystemError as soon as it encounters a missing file we'd need to rework the architecture a bit to keep iterating and collect up all the errors in order to show a list of all the files that aren't found. I can go that route if need be but its going to make the code more complex for a small gain I think.

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

Thanks!

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@MaxDesiatov MaxDesiatov requested a review from grynspan October 16, 2024 19:41
@MaxDesiatov MaxDesiatov added the swift test Changes impacting `swift test` tool label Oct 16, 2024
@plemarquand
Copy link
Contributor Author

@swift-ci test

@plemarquand plemarquand merged commit 4fbe8e8 into swiftlang:main Oct 17, 2024
5 checks passed
@plemarquand plemarquand deleted the skip-build-list-error branch October 17, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostics enhancement swift test Changes impacting `swift test` tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants