-
-
Notifications
You must be signed in to change notification settings - Fork 238
Use multiple registry fallbacks instead of one #1246
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
Changes from all commits
435fd1c
452fbe2
27c5f5e
caf429d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -292,17 +292,19 @@ class RegistryPackageSupplier : PackageSupplier { | |
|
|
||
| package abstract class AbstractFallbackPackageSupplier : PackageSupplier | ||
| { | ||
| protected PackageSupplier m_default, m_fallback; | ||
| protected PackageSupplier m_default; | ||
| protected PackageSupplier[] m_fallbacks; | ||
|
|
||
| this(PackageSupplier default_, PackageSupplier fallback) | ||
| this(PackageSupplier default_, PackageSupplier[] fallbacks) | ||
| { | ||
| m_default = default_; | ||
| m_fallback = fallback; | ||
| m_fallbacks = fallbacks; | ||
| } | ||
|
|
||
| override @property string description() | ||
| { | ||
| return format("%s (fallback %s)", m_default.description, m_fallback.description); | ||
| import std.algorithm : map; | ||
| return format("%s (fallback %s)", m_default.description, m_fallbacks.map!(x => x.description)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a blocker, but this is fairly long and detailed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know, but the |
||
| } | ||
|
|
||
| // Workaround https://issues.dlang.org/show_bug.cgi?id=2525 | ||
|
|
@@ -322,7 +324,19 @@ package alias FallbackPackageSupplier = AutoImplement!(AbstractFallbackPackageSu | |
| private template fallback(T, alias func) | ||
| { | ||
| enum fallback = q{ | ||
| scope (failure) return m_fallback.%1$s(args); | ||
| import std.range : back, dropBackOne; | ||
| import dub.internal.vibecompat.core.log : logDebug; | ||
| scope (failure) | ||
| { | ||
| foreach (m_fallback; m_fallbacks.dropBackOne) | ||
| { | ||
| try | ||
| return m_fallback.%1$s(args); | ||
| catch(Exception) | ||
| logDebug("Package supplier %s failed. Trying next fallback.", m_fallback); | ||
| } | ||
| return m_fallbacks.back.%1$s(args); | ||
| } | ||
| return m_default.%1$s(args); | ||
| }.format(__traits(identifier, func)); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could have stayed with the recursive structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I thought the "linear" way is more intuitive, but I don't really mind. If you feel strongly the recursive structure, feel free to change it back.