Resolving “Command PhaseScriptExecution failed with a nonzero exit code” Error in Xcode

Tuğberk Can Özen
2 min readJun 7, 2023
Error

Introduction

As a iOS developer, I’ve encountered and overcome numerous challenges throughout my career. However, each new project tends to present a unique set of issues to tackle. Recently, while working on a sophisticated app, I faced the “Command PhaseScriptExecution failed with a nonzero exit code” error. This arose after incorporating SwiftLint into my Xcode project, a best-practice I regularly adopt to maintain high code quality.

The Problem Emerges

The error message indicated a problem during the build phase of the application. It became evident that the SwiftLint script, integral to the build process, was failing, causing the entire build to fail and display the “nonzero exit code” message.

Deciphering the Issue

Having dealt with a wide range of issues in the past, I was aware that this error typically surfaces when a script run during the build process encounters a problem and terminates with a non-zero exit status. The exit status is a numerical value that a completed process returns to the system. In this context, zero denotes successful execution, whereas any non-zero value flags an error.

Delving into the Solution

I knew that the key to resolving this issue lay in the details of the script execution. I identified a specific line of code in the ios/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh file that seemed to be at the root of the problem:

source="$(readlink "${source}")"

This line was responsible for resolving the symbolic link of a specific source. In certain situations, this operation could fail, leading to the error at hand. As a result of my detailed research, I decided to modify this line to:

source="$(readlink -f "${source}")"

This subtle change would resolve the symbolic link slightly differently, potentially bypassing the issue that was causing the script to fail.

The Outcome

Following this adjustment, I was pleased to find that the error was resolved. The build process completed without issue, and I was able to proceed with my project. This experience served as a reaffirmation of the fact that meticulous code investigation and modification are powerful tools in the arsenal of an experienced developer​

Conclusion and Its Contribution to Me

While this solution addressed my encounter with the “Command PhaseScriptExecution failed with a nonzero exit code” error, it reminded me that each problem often requires a unique solution.

In programming, as in life, understanding the problem is the key to finding the right solution.

--

--

Tuğberk Can Özen

iOS Developer👨🏻‍💻 at @Loodos | Founder at @SwiftAkademi | UIKit • SwiftUI