Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SCInject/ContainerError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct ContainerError: Error {
}

static func raise(reason: String, type: String, name: String?) {
ContainerException.raise(reason: reason, type: type, name: nil)
ContainerException.raise(reason: reason, type: type, name: name)
}

// MARK: - Private
Expand Down
13 changes: 10 additions & 3 deletions Sources/SCInjectObjc/ContainerException.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,24 @@

NSString* const CSContainerExceptionTypeKey = @"SCContainerExceptionTypeKey";
NSString* const CSContainerExceptionNameKey = @"SCContainerExceptionNameKey";
NSString* const CSContainerExceptionReasonKey = @"SCContainerExceptionReasonKey";

@implementation ContainerException

+ (void)raiseWithReason:(NSString *)reason type:(NSString *)type name:(nullable NSString *)name {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{
CSContainerExceptionTypeKey: type
CSContainerExceptionTypeKey: type,
CSContainerExceptionReasonKey: reason
}];
NSMutableString *details = [[NSMutableString alloc] init];
[details appendFormat:@"TYPE=%@", type];
if (name) {
userInfo[CSContainerExceptionNameKey] = name;
[details appendFormat:@" NAME=%@", name];
}

@throw [NSException exceptionWithName:@"SCBasicObjc.Exception"
reason:reason
reason:[NSString stringWithFormat:@"%@ -- %@", reason, details]
userInfo:userInfo];
}

Expand All @@ -42,7 +48,8 @@ + (void)catchException:(__attribute__((noescape)) void (^)(void))operation
if (error) {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{
NSLocalizedDescriptionKey: exception.reason,
NSLocalizedFailureReasonErrorKey: exception.name,
NSLocalizedFailureErrorKey: exception.name,
CSContainerExceptionReasonKey: exception.userInfo[CSContainerExceptionReasonKey],
CSContainerExceptionTypeKey: exception.userInfo[CSContainerExceptionTypeKey]
}];
NSString *name = exception.userInfo[CSContainerExceptionNameKey];
Expand Down
6 changes: 3 additions & 3 deletions Tests/SCInject/ContainerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ final class ContainerTests: XCTestCase {
XCTAssertNoThrow(try container.validate())
}

func testValidate_missingNamedType() {
func testValidate_missingNamedType() throws {
// Given
let second: RegistrationName = .init(rawValue: "second")
let container = DefaultContainer()
Expand All @@ -116,9 +116,9 @@ final class ContainerTests: XCTestCase {
// When / Then
XCTAssertThrowsError(try container.validate()) { error in
let error = error as? ContainerError
XCTAssertEqual(error?.reason, "Failed to resolve given type")
XCTAssertEqual(error?.reason, "Failed to resolve given type -- TYPE=TestClass1 NAME=second")
XCTAssertEqual(error?.type, "TestClass1")
XCTAssertNil(error?.name)
XCTAssertEqual(error?.name, second.rawValue)
}
}
}
Expand Down