Skip to content

Commit 87b1864

Browse files
committed
Error handling
1 parent 510e5d0 commit 87b1864

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

src/gui/AppController+GeneralActions.inc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
11
- (void)startServer:(id)sender
22
{
33
(void)sender;
4+
5+
/* Pre-flight validation with clear error messages */
6+
if (![_processManager hasBinary]) {
7+
NSRunAlertPanel(@"Cannot Start Server",
8+
@"The server binary was not found inside the application bundle. "
9+
@"Please reinstall Lemoniscate.",
10+
@"OK", nil, nil);
11+
return;
12+
}
13+
14+
if (_serverPort < 1 || _serverPort > 65535) {
15+
NSRunAlertPanel(@"Invalid Port",
16+
@"The Hotline port must be between 1 and 65535. "
17+
@"The default is 5500.",
18+
@"OK", nil, nil);
19+
return;
20+
}
21+
22+
NSString *fileRoot = _fileRootField ? [_fileRootField stringValue] : @"";
23+
if ([fileRoot length] == 0) {
24+
NSRunAlertPanel(@"No File Root Set",
25+
@"Please set a File Root directory in the server settings. "
26+
@"This is the folder that will be shared with connected users.",
27+
@"OK", nil, nil);
28+
return;
29+
}
30+
31+
BOOL isDir = NO;
32+
if (![[NSFileManager defaultManager] fileExistsAtPath:fileRoot isDirectory:&isDir] || !isDir) {
33+
NSRunAlertPanel(@"File Root Not Found",
34+
[NSString stringWithFormat:
35+
@"The File Root directory does not exist:\n\n%@\n\n"
36+
@"Please create it or choose a different folder.", fileRoot],
37+
@"OK", nil, nil);
38+
return;
39+
}
40+
441
[self saveSettings:nil];
542
[self ensureConfigScaffolding];
643
[self writeConfigToDisk];

src/gui/ProcessManager.m

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,22 @@ - (void)startWithConfigDir:(NSString *)configDir port:(int)port
9999
if (_task != nil) return;
100100

101101
if (![self hasBinary]) {
102-
[self setError:@"Server binary not found"];
102+
[self setError:@"Server binary not found in application bundle. "
103+
@"Please reinstall Lemoniscate."];
103104
return;
104105
}
105106

106107
/* Validate port */
107108
if (port < 1 || port > 65535) {
108-
[self setError:@"Port must be between 1 and 65535"];
109+
[self setError:@"Port must be between 1 and 65535. The default is 5500."];
110+
return;
111+
}
112+
113+
/* Check config directory exists */
114+
BOOL isDir = NO;
115+
if (![[NSFileManager defaultManager] fileExistsAtPath:configDir isDirectory:&isDir] || !isDir) {
116+
[self setError:[NSString stringWithFormat:
117+
@"Configuration directory not found: %@", configDir]];
109118
return;
110119
}
111120

@@ -276,8 +285,27 @@ - (void)taskDidTerminate:(NSNotification *)note
276285
if (exitStatus == 0 || exitStatus == SIGTERM || exitStatus == SIGINT) {
277286
[self setStatus:ServerStatusStopped];
278287
} else {
279-
[self setError:[NSString stringWithFormat:
280-
@"Server exited with code %d", exitStatus]];
288+
NSString *detail;
289+
switch (exitStatus) {
290+
case 1:
291+
detail = @"Server failed to start. Check that the port is not "
292+
@"already in use and the configuration is valid.";
293+
break;
294+
case 11: /* SIGSEGV */
295+
detail = @"Server crashed (segmentation fault). "
296+
@"Please report this issue.";
297+
break;
298+
case 6: /* SIGABRT */
299+
detail = @"Server aborted unexpectedly. "
300+
@"Check the log for details.";
301+
break;
302+
default:
303+
detail = [NSString stringWithFormat:
304+
@"Server exited unexpectedly (code %d). "
305+
@"Check the log tab for details.", exitStatus];
306+
break;
307+
}
308+
[self setError:detail];
281309
}
282310
}
283311

0 commit comments

Comments
 (0)