Skip to content

Commit 8a1c150

Browse files
add more validation checks
1 parent bff2df8 commit 8a1c150

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

src/cli.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,23 +367,37 @@ program.command('run')
367367
const editorPath = options.unityEditor?.toString()?.trim() || process.env.UNITY_EDITOR_PATH || undefined;
368368

369369
if (editorPath && editorPath.length > 0) {
370-
unityEditor = new UnityEditor(editorPath);
370+
try {
371+
unityEditor = new UnityEditor(editorPath);
372+
} catch {
373+
Logger.instance.error(`The specified Unity Editor path is invalid: ${editorPath}. Use --unity-editor or set the UNITY_EDITOR_PATH environment variable.`);
374+
process.exit(1);
375+
}
371376
}
372377

373378
let unityProject: UnityProject | undefined;
374379
const projectPath = options.unityProject?.toString()?.trim() || process.env.UNITY_PROJECT_PATH || undefined;
375380

376381
if (projectPath && projectPath.length > 0) {
377-
unityProject = await UnityProject.GetProject(projectPath);
382+
try {
383+
unityProject = await UnityProject.GetProject(projectPath);
378384

379-
if (!unityProject) {
380-
Logger.instance.error(`The specified path is not a valid Unity project: ${projectPath}. Use --unity-project or UNITY_PROJECT_PATH environment variable.`);
385+
if (!unityProject) {
386+
throw Error('Invalid Unity project path.');
387+
}
388+
} catch (error) {
389+
Logger.instance.error(`The specified path is not a valid Unity project: ${projectPath}. Use --unity-project or set the UNITY_PROJECT_PATH environment variable.`);
381390
process.exit(1);
382391
}
383392

384393
if (!unityEditor) {
385394
const unityHub = new UnityHub();
386-
unityEditor = await unityHub.GetEditor(unityProject.version);
395+
try {
396+
unityEditor = await unityHub.GetEditor(unityProject.version);
397+
} catch {
398+
Logger.instance.error(`Could not find Unity Editor version ${unityProject.version.version} installed for project at ${unityProject.projectPath}. Please specify the editor path with --unity-editor or set the UNITY_EDITOR_PATH environment variable.`);
399+
process.exit(1);
400+
}
387401
}
388402
}
389403

0 commit comments

Comments
 (0)