Skip to content

Commit

Permalink
Step 18 42 errors (#202)
Browse files Browse the repository at this point in the history
* Update top-level error messages

* Improved error messages and some minor improvements

* Removed ',error' suffix from errors messages

* Update errors
  • Loading branch information
godrei authored Feb 24, 2022
1 parent ff0eab7 commit 3185a95
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 79 deletions.
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ func run() int {
xcodeTestRunner := createStep(logger)
config, err := xcodeTestRunner.ProcessConfig()
if err != nil {
logger.Errorf(err.Error())
logger.Errorf("Process config: %s", err)
return 1

}

if err := xcodeTestRunner.InstallDeps(config.LogFormatter == xcodebuild.XcprettyTool); err != nil {
logger.Warnf("Failed to install deps: %s", err)
logger.Warnf("Install dependencies: %s", err)
logger.Printf("Switching to xcodebuild for output tool")
config.LogFormatter = xcodebuild.XcodebuildTool
}
Expand All @@ -45,12 +45,12 @@ func run() int {
exportErr := xcodeTestRunner.Export(res, runErr != nil)

if runErr != nil {
logger.Errorf(runErr.Error())
logger.Errorf("Run: %s", runErr)
return 1
}

if exportErr != nil {
logger.Errorf(exportErr.Error())
logger.Errorf("Export outputs: %s", err)
return 1
}

Expand Down
20 changes: 10 additions & 10 deletions output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ func (e exporter) ExportTestRunResult(failed bool) {
status = "failed"
}
if err := e.envRepository.Set("BITRISE_XCODE_TEST_RESULT", status); err != nil {
e.logger.Warnf("Failed to export: BITRISE_XCODE_TEST_RESULT, error: %s", err)
e.logger.Warnf("Failed to export: BITRISE_XCODE_TEST_RESULT: %s", err)
}
}

func (e exporter) ExportXCResultBundle(deployDir, xcResultPath, scheme string) {
// export xcresult bundle
if err := e.envRepository.Set("BITRISE_XCRESULT_PATH", xcResultPath); err != nil {
e.logger.Warnf("Failed to export: BITRISE_XCRESULT_PATH, error: %s", err)
e.logger.Warnf("Failed to export: BITRISE_XCRESULT_PATH: %s", err)
}

xcresultZipPath := filepath.Join(deployDir, filepath.Base(xcResultPath)+".zip")
if err := output.ZipAndExportOutput([]string{xcResultPath}, xcresultZipPath, "BITRISE_XCRESULT_ZIP_PATH"); err != nil {
e.logger.Warnf("Failed to export: BITRISE_XCRESULT_ZIP_PATH, error: %s", err)
e.logger.Warnf("Failed to export: BITRISE_XCRESULT_ZIP_PATH: %s", err)
}

// export xcresult for the testing addon
Expand All @@ -68,7 +68,7 @@ func (e exporter) ExportXCResultBundle(deployDir, xcResultPath, scheme string) {
TargetAddonPath: addonResultPath,
TargetAddonBundleName: scheme,
}); err != nil {
e.logger.Warnf("Failed to export test results, error: %s", err)
e.logger.Warnf("Failed to export test results: %s", err)
}
}
}
Expand All @@ -81,11 +81,11 @@ func (e exporter) ExportXcodebuildBuildLog(deployDir, xcodebuildBuildLog string)

deployPth := filepath.Join(deployDir, "xcodebuild_build.log")
if err := command.CopyFile(pth, deployPth); err != nil {
return fmt.Errorf("failed to copy xcodebuild output log file from (%s) to (%s), error: %s", pth, deployPth, err)
return fmt.Errorf("failed to copy xcodebuild output log file from (%s) to (%s): %w", pth, deployPth, err)
}

if err := e.envRepository.Set("BITRISE_XCODEBUILD_BUILD_LOG_PATH", deployPth); err != nil {
e.logger.Warnf("Failed to export: BITRISE_XCODEBUILD_BUILD_LOG_PATH, error: %s", err)
e.logger.Warnf("Failed to export: BITRISE_XCODEBUILD_BUILD_LOG_PATH: %s", err)
}

return nil
Expand All @@ -94,16 +94,16 @@ func (e exporter) ExportXcodebuildBuildLog(deployDir, xcodebuildBuildLog string)
func (e exporter) ExportXcodebuildTestLog(deployDir, xcodebuildTestLog string) error {
pth, err := saveRawOutputToLogFile(xcodebuildTestLog)
if err != nil {
e.logger.Warnf("Failed to save the Raw Output, error: %s", err)
e.logger.Warnf("Failed to save the Raw Output: %s", err)
}

deployPth := filepath.Join(deployDir, "xcodebuild_test.log")
if err := command.CopyFile(pth, deployPth); err != nil {
return fmt.Errorf("failed to copy xcodebuild output log file from (%s) to (%s), error: %s", pth, deployPth, err)
return fmt.Errorf("failed to copy xcodebuild output log file from (%s) to (%s): %w", pth, deployPth, err)
}

if err := e.envRepository.Set("BITRISE_XCODEBUILD_TEST_LOG_PATH", deployPth); err != nil {
e.logger.Warnf("Failed to export: BITRISE_XCODEBUILD_TEST_LOG_PATH, error: %s", err)
e.logger.Warnf("Failed to export: BITRISE_XCODEBUILD_TEST_LOG_PATH: %s", err)
}

return nil
Expand All @@ -112,7 +112,7 @@ func (e exporter) ExportXcodebuildTestLog(deployDir, xcodebuildTestLog string) e
func (e exporter) ExportSimulatorDiagnostics(deployDir, pth, name string) error {
outputPath := filepath.Join(deployDir, name)
if err := ziputil.ZipDir(pth, outputPath, true); err != nil {
return fmt.Errorf("failed to compress simulator diagnostics result: %v", err)
return fmt.Errorf("failed to compress simulator diagnostics result: %w", err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions output/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
func saveRawOutputToLogFile(rawXcodebuildOutput string) (string, error) {
tmpDir, err := pathutil.NormalizedOSTempDirPath("xcodebuild-output")
if err != nil {
return "", fmt.Errorf("failed to create temp dir, error: %s", err)
return "", fmt.Errorf("failed to create temp dir: %w", err)
}
logFileName := "raw-xcodebuild-output.log"
logPth := filepath.Join(tmpDir, logFileName)
if err := fileutil.WriteStringToFile(logPth, rawXcodebuildOutput); err != nil {
return "", fmt.Errorf("failed to write xcodebuild output to file, error: %s", err)
return "", fmt.Errorf("failed to write xcodebuild output to file: %w", err)
}

return logPth, nil
Expand Down
2 changes: 1 addition & 1 deletion simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (m manager) SimulatorShutdown(id string) error {
func (m manager) SimulatorDiagnosticsName() (string, error) {
timestamp, err := time.Now().MarshalText()
if err != nil {
return "", fmt.Errorf("failed to collect Simulator diagnostics, failed to marshal timestamp: %v", err)
return "", fmt.Errorf("failed to marshal timestamp: %w", err)
}

return fmt.Sprintf("simctl_diagnose_%s.zip", strings.ReplaceAll(string(timestamp), ":", "-")), nil
Expand Down
34 changes: 17 additions & 17 deletions step/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (s XcodeTestRunner) ProcessConfig() (Config, error) {
// validate Xcode version
xcodebuildVersion, err := s.xcodebuild.Version()
if err != nil {
return Config{}, fmt.Errorf("failed to determine Xcode version, error: %s", err)
return Config{}, fmt.Errorf("failed to determine Xcode version: %w", err)
}
s.logger.Printf("- xcodebuildVersion: %s (%s)", xcodebuildVersion.Version, xcodebuildVersion.BuildVersion)

Expand All @@ -154,7 +154,7 @@ func (s XcodeTestRunner) ProcessConfig() (Config, error) {
// validate project path
projectPath, err := s.pathModifier.AbsPath(input.ProjectPath)
if err != nil {
return Config{}, fmt.Errorf("failed to get absolute project path, error: %s", err)
return Config{}, fmt.Errorf("failed to get absolute project path: %w", err)
}
if filepath.Ext(projectPath) != ".xcodeproj" && filepath.Ext(projectPath) != ".xcworkspace" {
return Config{}, fmt.Errorf("invalid project file (%s), extension should be (.xcodeproj/.xcworkspace)", projectPath)
Expand All @@ -171,7 +171,7 @@ func (s XcodeTestRunner) ProcessConfig() (Config, error) {
}

if input.RelaunchTestsForEachRepetition && input.TestRepetitionMode == xcodebuild.TestRepetitionNone {
return Config{}, errors.New("Relaunch Tests for Each Repetition (relaunch_tests_for_each_repetition) cannot be used if Test Repetition Mode (test_repetition_mode) is 'none'")
return Config{}, errors.New("the 'Relaunch Tests for Each Repetition' (relaunch_tests_for_each_repetition) cannot be used if 'Test Repetition Mode' (test_repetition_mode) is 'none'")
}

return createConfig(input, projectPath, int(xcodebuildVersion.MajorVersion), sim), nil
Expand All @@ -185,9 +185,9 @@ func (s XcodeTestRunner) InstallDeps(xcpretty bool) error {

xcprettyVersion, err := s.xcprettyInstaller.Install()
if err != nil {
return fmt.Errorf("an error occured during installing xcpretty: %s", err)
return fmt.Errorf("installing xcpretty: %w", err)
}
s.logger.Printf("- xcprettyVersion: %s", xcprettyVersion.String())
s.logger.Printf("- xcpretty version: %s", xcprettyVersion.String())
s.logger.Println()

return nil
Expand Down Expand Up @@ -229,14 +229,14 @@ func (s XcodeTestRunner) Run(cfg Config) (Result, error) {
if testErr != nil {
s.logger.Println()
s.logger.Warnf("Xcode Test command exit code: %d", testExitCode)
s.logger.Errorf("Xcode Test command failed, error: %s", testErr)
s.logger.Errorf("Xcode Test command failed: %s", testErr)
return result, testErr
}

// Cache swift PM
if cfg.XcodeMajorVersion >= 11 && cfg.CacheLevel == "swift_packages" {
if err := s.cache.CollectSwiftPackages(cfg.ProjectPath); err != nil {
s.logger.Warnf("Failed to mark swift packages for caching, error: %s", err)
s.logger.Warnf("Failed to mark swift packages for caching: %s", err)
}
}

Expand Down Expand Up @@ -273,11 +273,11 @@ func (s XcodeTestRunner) Export(result Result, testFailed bool) error {
if result.SimulatorDiagnosticsPath != "" {
diagnosticsName, err := s.simulatorManager.SimulatorDiagnosticsName()
if err != nil {
return err
return fmt.Errorf("failed to get simulator diagnostics name: %w", err)
}

if err := s.outputExporter.ExportSimulatorDiagnostics(result.DeployDir, result.SimulatorDiagnosticsPath, diagnosticsName); err != nil {
return err
return fmt.Errorf("failed to export simulator diagnostics: %w", err)
}
}

Expand Down Expand Up @@ -322,7 +322,7 @@ func (s XcodeTestRunner) getSimulatorForDestination(destinationSpecifier string)

simulatorDestination, err := destination.NewSimulator(destinationSpecifier)
if err != nil {
return simulator.Simulator{}, fmt.Errorf("invalid destination specifier: %v", err)
return simulator.Simulator{}, fmt.Errorf("invalid destination specifier (%s): %w", destinationSpecifier, err)
}

platform := strings.TrimSuffix(simulatorDestination.Platform, " Simulator")
Expand Down Expand Up @@ -354,7 +354,7 @@ func (s XcodeTestRunner) getSimulatorForDestination(destinationSpecifier string)

return errGetSimulator
}); err != nil {
return simulator.Simulator{}, fmt.Errorf("simulator UDID lookup failed: %s", err)
return simulator.Simulator{}, fmt.Errorf("simulator UDID lookup failed: %w", err)
}

s.logger.Infof("Simulator infos")
Expand All @@ -366,7 +366,7 @@ func (s XcodeTestRunner) getSimulatorForDestination(destinationSpecifier string)
func (s XcodeTestRunner) prepareSimulator(enableSimulatorVerboseLog bool, simulatorID string, launchSimulator bool) error {
err := s.simulatorManager.ResetLaunchServices()
if err != nil {
s.logger.Warnf("Failed to apply simulator boot workaround, error: %s", err)
s.logger.Warnf("Failed to apply simulator boot workaround: %s", err)
}

// Boot simulator
Expand All @@ -387,7 +387,7 @@ func (s XcodeTestRunner) prepareSimulator(enableSimulatorVerboseLog bool, simula
s.logger.Infof("Booting simulator (%s)...", simulatorID)

if err := s.simulatorManager.LaunchSimulator(simulatorID); err != nil {
return fmt.Errorf("failed to boot simulator, error: %s", err)
return fmt.Errorf("failed to boot simulator: %w", err)
}

progress.NewDefaultWrapper("Waiting for simulator boot").WrapAction(func() {
Expand All @@ -410,7 +410,7 @@ func (s XcodeTestRunner) runTests(cfg Config) (Result, int, error) {
// Run test
tempDir, err := s.pathProvider.CreateTempDir("XCUITestOutput")
if err != nil {
return result, -1, fmt.Errorf("could not create test output temporary directory: %s", err)
return result, -1, fmt.Errorf("could not create test output temporary directory: %w", err)
}
xcresultPath := path.Join(tempDir, fmt.Sprintf("Test-%s.xcresult", cfg.Scheme))

Expand All @@ -419,7 +419,7 @@ func (s XcodeTestRunner) runTests(cfg Config) (Result, int, error) {
var err error
swiftPackagesPath, err = s.cache.SwiftPackagesPath(cfg.ProjectPath)
if err != nil {
return result, -1, fmt.Errorf("failed to get Swift Packages path, error: %s", err)
return result, -1, fmt.Errorf("failed to get Swift Packages path: %w", err)
}
}

Expand All @@ -445,7 +445,7 @@ func (s XcodeTestRunner) teardownSimulator(simulatorID string, simulatorDebug ex

diagnosticsPath, err := s.simulatorManager.SimulatorCollectDiagnostics()
if err != nil {
s.logger.Warnf("%v", err)
s.logger.Warnf(err.Error())
} else {
s.logger.Donef("Simulator diagnostics are available as an artifact (%s)", diagnosticsPath)
simulatorDiagnosticsPath = diagnosticsPath
Expand All @@ -455,7 +455,7 @@ func (s XcodeTestRunner) teardownSimulator(simulatorID string, simulatorDebug ex
// Shut down the simulator if it was started by the step for diagnostic logs.
if !isSimulatorBooted && simulatorDebug != never {
if err := s.simulatorManager.SimulatorShutdown(simulatorID); err != nil {
s.logger.Warnf("%v", err)
s.logger.Warnf(err.Error())
}
}

Expand Down
8 changes: 4 additions & 4 deletions testaddon/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func replaceUnsupportedFilenameCharacters(s string) string {

func copyDirectory(sourceBundle string, targetDir string) error {
if err := os.MkdirAll(targetDir, 0700); err != nil {
return fmt.Errorf("failed to create directory (%s), error: %s", targetDir, err)
return fmt.Errorf("failed to create directory (%s): %w", targetDir, err)
}

// the leading `/` means to copy not the content but the whole dir
Expand All @@ -32,7 +32,7 @@ func copyDirectory(sourceBundle string, targetDir string) error {
// TODO: migrate log
log.Donef("$ %s", cmd.PrintableCommandArgs())
if out, err := cmd.RunAndReturnTrimmedCombinedOutput(); err != nil {
return fmt.Errorf("copy failed, error: %s, output: %s", err, out)
return fmt.Errorf("copy failed: %w, output: %s", err, out)
}

return nil
Expand All @@ -47,10 +47,10 @@ func saveBundleMetadata(outputDir string, bundleName string) error {
BundleName: bundleName,
})
if err != nil {
return fmt.Errorf("could not encode metadata, error: %s", err)
return fmt.Errorf("could not encode metadata: %w", err)
}
if err = ioutil.WriteFile(filepath.Join(outputDir, "test-info.json"), bytes, 0600); err != nil {
return fmt.Errorf("failed to write file, error: %s", err)
return fmt.Errorf("failed to write file: %w", err)
}
return nil
}
Loading

0 comments on commit 3185a95

Please sign in to comment.