mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Return errors and use them to raise exception in -launch
This commit is contained in:
parent
94b08cf647
commit
2ffa8c1cad
1 changed files with 49 additions and 18 deletions
|
@ -415,7 +415,13 @@ pty_slave(const char* name)
|
|||
*/
|
||||
- (void) launch
|
||||
{
|
||||
[self launchAndReturnError: NULL];
|
||||
NSError *e;
|
||||
|
||||
if (NO == [self launchAndReturnError: &e])
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"%@", e ? e : @"Unable to launch"];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -881,15 +887,17 @@ pty_slave(const char* name)
|
|||
// macOS 10.13 methods...
|
||||
|
||||
+ (NSTask *) launchedTaskWithExecutableURL: (NSURL *)url
|
||||
arguments: (NSArray *)arguments
|
||||
error: (NSError **)error
|
||||
terminationHandler: (GSTaskTerminationHandler)terminationHandler
|
||||
arguments: (NSArray *)arguments
|
||||
error: (NSError **)error
|
||||
terminationHandler: (GSTaskTerminationHandler)terminationHandler
|
||||
{
|
||||
NSTask *task = [self launchedTaskWithLaunchPath: [url path]
|
||||
arguments: arguments];
|
||||
NSTask *task = [self launchedTaskWithLaunchPath: [url path]
|
||||
arguments: arguments];
|
||||
task->_handler = terminationHandler;
|
||||
*error = nil;
|
||||
|
||||
if (error)
|
||||
{
|
||||
*error = nil;
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
||||
|
@ -899,7 +907,6 @@ pty_slave(const char* name)
|
|||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (NSURL *) executableURL
|
||||
{
|
||||
return [NSURL URLWithString: [self launchPath]];;
|
||||
|
@ -1195,8 +1202,17 @@ quotedFromString(NSString *aString)
|
|||
|
||||
if (_hasLaunched)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - task has already been launched"];
|
||||
if (error)
|
||||
{
|
||||
NSDictionary *info;
|
||||
|
||||
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"task has already been launched", NSLocalizedDescriptionKey, nil];
|
||||
*error = [NSError errorWithDomain: NSCocoaErrorDomain
|
||||
code: 0
|
||||
userInfo: info];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
[super launchAndReturnError: error];
|
||||
|
@ -1356,7 +1372,7 @@ quotedFromString(NSString *aString)
|
|||
(const unichar*)[[self currentDirectoryPath] fileSystemRepresentation],
|
||||
&start_info,
|
||||
&procInfo);
|
||||
if (result == 0)
|
||||
if (0 == result)
|
||||
{
|
||||
last = [NSError _last];
|
||||
}
|
||||
|
@ -1368,8 +1384,11 @@ quotedFromString(NSString *aString)
|
|||
|
||||
if (0 == result)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - Error launching task: %@ ... %@", lpath, last];
|
||||
if (error)
|
||||
{
|
||||
*error = last;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
_taskId = procInfo.dwProcessId;
|
||||
|
@ -1527,8 +1546,17 @@ GSPrivateCheckTasks()
|
|||
|
||||
if (_hasLaunched)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - task has already been launched"];
|
||||
if (error)
|
||||
{
|
||||
NSDictionary *info;
|
||||
|
||||
info = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"task has already been launched", NSLocalizedDescriptionKey, nil];
|
||||
*error = [NSError errorWithDomain: NSCocoaErrorDomain
|
||||
code: 0
|
||||
userInfo: info];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
[super launchAndReturnError: error];
|
||||
|
@ -1603,8 +1631,11 @@ GSPrivateCheckTasks()
|
|||
pid = vfork();
|
||||
if (pid < 0)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"NSTask - failed to create child process"];
|
||||
if (error)
|
||||
{
|
||||
*error = [NSError _last];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
if (pid == 0)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue