Skip to content

Commit 03f3218

Browse files
committed
add error feedback if obs64 exe is missing
* controller.cpp: Adding new exitcode that represents the obs64 exe could not be found. Updating JS code to properly check the exitCode to avoid a silent failure case * utility.hpp: Output to error stream when connection fails. Previously, the code attempted to return a JS exception but it never got to run due to the exit(1). This way we maintain legacy behavior and exit application with a helpful message * module.js: verify bin folder contains obs64
1 parent 4434fda commit 03f3218

5 files changed

Lines changed: 20 additions & 9 deletions

File tree

js/module.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ function getSourcesSize(sourcesNames) {
121121
return sourcesSize;
122122
}
123123
exports.getSourcesSize = getSourcesSize;
124-
const __dirnameApple = hasDeveloperApp
124+
const appleBinaryFolder = hasDeveloperApp
125125
? path.join(__dirname, 'OSN.app', 'distribute', 'obs-studio-node', 'bin')
126126
: path.join(__dirname, 'bin');
127-
if (fs.existsSync(path.resolve(__dirnameApple).replace('app.asar', 'app.asar.unpacked'))) {
128-
obs.IPC.setServerPath(path.resolve(__dirnameApple, `obs64`).replace('app.asar', 'app.asar.unpacked'), path.resolve(__dirnameApple).replace('app.asar', 'app.asar.unpacked'));
127+
if (fs.existsSync(path.resolve(appleBinaryFolder, 'obs64').replace('app.asar', 'app.asar.unpacked'))) {
128+
obs.IPC.setServerPath(path.resolve(appleBinaryFolder, `obs64`).replace('app.asar', 'app.asar.unpacked'), path.resolve(appleBinaryFolder).replace('app.asar', 'app.asar.unpacked'));
129129
}
130130
else if (fs.existsSync(path.resolve(__dirname, `obs64.exe`).replace('app.asar', 'app.asar.unpacked'))) {
131131
obs.IPC.setServerPath(path.resolve(__dirname, `obs64.exe`).replace('app.asar', 'app.asar.unpacked'), path.resolve(__dirname).replace('app.asar', 'app.asar.unpacked'));

js/module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,11 +1899,11 @@ export const enum VCamOutputType {
18991899
};
19001900

19011901
// Initialization and other stuff which needs local data.
1902-
const __dirnameApple = hasDeveloperApp
1902+
const appleBinaryFolder = hasDeveloperApp
19031903
? path.join(__dirname, 'OSN.app', 'distribute', 'obs-studio-node', 'bin')
19041904
: path.join(__dirname, 'bin');
1905-
if (fs.existsSync(path.resolve(__dirnameApple).replace('app.asar', 'app.asar.unpacked'))) {
1906-
obs.IPC.setServerPath(path.resolve(__dirnameApple, `obs64`).replace('app.asar', 'app.asar.unpacked'), path.resolve(__dirnameApple).replace('app.asar', 'app.asar.unpacked'));
1905+
if (fs.existsSync(path.resolve(appleBinaryFolder, 'obs64').replace('app.asar', 'app.asar.unpacked'))) {
1906+
obs.IPC.setServerPath(path.resolve(appleBinaryFolder, `obs64`).replace('app.asar', 'app.asar.unpacked'), path.resolve(appleBinaryFolder).replace('app.asar', 'app.asar.unpacked'));
19071907
}
19081908
else if (fs.existsSync(path.resolve(__dirname, `obs64.exe`).replace('app.asar', 'app.asar.unpacked'))) {
19091909
obs.IPC.setServerPath(path.resolve(__dirname, `obs64.exe`).replace('app.asar', 'app.asar.unpacked'), path.resolve(__dirname).replace('app.asar', 'app.asar.unpacked'));

obs-studio-client/source/controller.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ Napi::Value js_connect(const Napi::CallbackInfo &info)
449449
if (exit_code == STATUS_DLL_NOT_FOUND)
450450
exit_code = ProcessInfo::MISSING_DEPENDENCY;
451451
#endif
452-
452+
if (exit_code == 0 && cl == nullptr) {
453+
exit_code = ProcessInfo::OTHER_ERROR; // Null ipc client which can be caused due to missing obs64
454+
}
453455
return Napi::Number::New(info.Env(), exit_code);
454456
}
455457

@@ -475,6 +477,9 @@ Napi::Value js_host(const Napi::CallbackInfo &info)
475477
exit_code = ProcessInfo::MISSING_DEPENDENCY;
476478
#endif
477479

480+
if (exit_code == 0 && cl == nullptr) {
481+
exit_code = ProcessInfo::OTHER_ERROR; // Null ipc client which can be caused due to missing obs64
482+
}
478483
return Napi::Number::New(info.Env(), exit_code);
479484
}
480485

obs-studio-client/source/utility.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static FORCE_INLINE std::shared_ptr<ipc::client> GetConnection(const Napi::Callb
122122
{
123123
auto conn = Controller::GetInstance().GetConnection();
124124
if (!conn) {
125-
Napi::Error::New(info.Env(), "Failed to obtain IPC connection.").ThrowAsJavaScriptException();
125+
std::cerr << "Failed to obtain IPC connection." << std::endl;
126126
exit(1);
127127
}
128128
return conn;

tests/osn-tests/util/obs_handler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ export class OBSHandler {
108108
logInfo(this.osnTestName, 'Initializing OBS');
109109

110110
try {
111-
osn.NodeObs.IPC.host(this.pipeName);
111+
const exitCode = osn.NodeObs.IPC.host(this.pipeName);
112+
if (exitCode != osn.EVideoCodes.Success) {
113+
if (exitCode == osn.EIPCError.OTHER_ERROR) {
114+
throw Error('OBS IPC host failed: missing executable or some other error.');
115+
}
116+
throw Error(`OBS IPC host failed with code ${exitCode}. See osn.EIPCError for more details.`);
117+
}
112118
osn.NodeObs.SetWorkingDirectory(this.workingDirectory);
113119
initResult = osn.NodeObs.OBS_API_initAPI(this.language, this.obsPath, this.version, this.crashServer);
114120
} catch (e) {

0 commit comments

Comments
 (0)