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

Print nested types in errors, hash keys using full typenames #221

Merged
merged 2 commits into from
Nov 10, 2019

Conversation

stevenkramer
Copy link

Hi Ilya, we're using nested types a lot and the "leafs" have identical names, which leads to conflicts when type matching and non-specific log messages. This change uses the fully scoped names.

}

func reflect(_ type: Any.Type) -> String
{
return String(reflecting: type)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you please just use this rather than introducing free function?

@@ -41,7 +41,7 @@ public struct DefinitionKey: Hashable, CustomStringConvertible {
}

public var description: String {
return "type: \(type), arguments: \(typeOfArguments), tag: \(tag.desc)"
return "type: \(reflect(type)), arguments: \(typeOfArguments), tag: \(tag.desc)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return "type: \(reflect(type)), arguments: \(typeOfArguments), tag: \(tag.desc)"
return "type: \(String(reflecting: type)), arguments: \(typeOfArguments), tag: \(tag.desc)"

@@ -77,18 +77,21 @@ public enum DipError: Error, CustomStringConvertible {
public var description: String {
switch self {
case let .definitionNotFound(key):
return "No definition registered for \(key).\nCheck the tag, type you try to resolve, number, order and types of runtime arguments passed to `resolve()` and match them with registered factories for type \(key.type)."
return "No definition registered for \(key).\nCheck the tag, type you try to resolve, number, order and types of runtime arguments passed to `resolve()` and match them with registered factories for type \(reflect(key.type))."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return "No definition registered for \(key).\nCheck the tag, type you try to resolve, number, order and types of runtime arguments passed to `resolve()` and match them with registered factories for type \(reflect(key.type))."
return "No definition registered for \(key).\nCheck the tag, type you try to resolve, number, order and types of runtime arguments passed to `resolve()` and match them with registered factories for type \(String(reflecting: key.type))."

case let .autoInjectionFailed(label, type, error):
return "Failed to auto-inject property \"\(label.desc)\" of type \(type). \(error)"
return "Failed to auto-inject property \"\(label.desc)\" of type \(reflect(type)). \(error)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return "Failed to auto-inject property \"\(label.desc)\" of type \(reflect(type)). \(error)"
return "Failed to auto-inject property \"\(label.desc)\" of type \(String(reflecting: type)). \(error)"

case let .autoWiringFailed(type, error):
return "Failed to auto-wire type \"\(type)\". \(error)"
return "Failed to auto-wire type \"\(reflect(type))\". \(error)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return "Failed to auto-wire type \"\(reflect(type))\". \(error)"
return "Failed to auto-wire type \"\(String(reflecting: type))\". \(error)"

case let .ambiguousDefinitions(type, definitions):
return "Ambiguous definitions for \(type):\n" +
return "Ambiguous definitions for \(reflect(type)):\n" +
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return "Ambiguous definitions for \(reflect(type)):\n" +
return "Ambiguous definitions for \(String(reflecting: type)):\n" +

definitions.map({ "\($0)" }).joined(separator: ";\n")
case let .invalidType(resolved, key):
return "Resolved instance \(resolved ?? "nil") does not implement expected type \(key.type)."
return "Resolved instance \(resolved ?? "nil") does not implement expected type \(reflect(key.type))."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return "Resolved instance \(resolved ?? "nil") does not implement expected type \(reflect(key.type))."
return "Resolved instance \(resolved ?? "nil") does not implement expected type \(String(reflecting: key.type))."

@ilyapuchka ilyapuchka merged commit e368bb3 into AliSoftware:develop Nov 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants