Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSRegularExpression: Improved Error and Exception handling to match macOS behaviour #343

Merged
merged 4 commits into from
Nov 13, 2023

Conversation

hmelder
Copy link
Contributor

@hmelder hmelder commented Nov 11, 2023

When creating a NSRegularExpression object on macOS, the following error message is created.

NSRegularExpression *exp;
exp = [NSRegularExpression regularExpressionWithPattern:@"(abc" options:0 error:&error];
if (!exp) {
  NSLog(@"%@", error);
}

Output macOS 14.0

2023-11-11 19:43:08.886 objc-boilerplate[7287:328207] Error Domain=NSCocoaErrorDomain Code=2048 "The value “(abc” is invalid." UserInfo={NSInvalidValue=(abc}

On GNUstep we did not populate the error value.

Additionally, we did not check nil values:

NSRegularExpression *exp;
exp = [NSRegularExpression regularExpressionWithPattern:nil options:0 error:&error];

Output macOS 14.0

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSRegularExpression initWithPattern:options:error:]: nil argument'
*** First throw call stack:
(
        0   CoreFoundation                      0x000000018f4a88c0 __exceptionPreprocess + 176
        1   libobjc.A.dylib                     0x000000018efa1eb4 objc_exception_throw + 60
        2   Foundation                          0x0000000190535ce0 -[NSRegularExpression initWithPattern:options:error:] + 664
        3   Foundation                          0x0000000190535a28 +[NSRegularExpression regularExpressionWithPattern:options:error:] + 52
        4   objc-boilerplate                    0x0000000102113df0 main + 928
        5   dyld                                0x000000018efdd058 start + 2224

This PR aligns the GNUstep implementation with Apple's Foundation framework, and supplies test cases for testing correct behaviour.

Copy link
Contributor

@rfm rfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. It would be better if the changes matched GNUstep coding style (but I can easily fix that).

@hmelder
Copy link
Contributor Author

hmelder commented Nov 13, 2023

OK. It would be better if the changes matched GNUstep coding style (but I can easily fix that).

The whole file uses two space indentation which is not up to the GNUstep coding style.

@hmelder hmelder merged commit ac38295 into master Nov 13, 2023
9 checks passed
@hmelder hmelder deleted the nsregularexpression-error branch November 13, 2023 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants