Skip to content

Commit

Permalink
Add depending mod to missing dependency exception
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 15, 2017
1 parent fd270eb commit 28c981e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 16 deletions.
7 changes: 7 additions & 0 deletions Cmdline/Action/Install.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ public int RunCommand(CKAN.KSP ksp, object raw_options)
var installer = ModuleInstaller.GetInstance(ksp, user);
installer.InstallList(options.modules, install_ops);
}
catch (DependencyNotSatisfiedKraken ex)
{
user.RaiseMessage("{0} requires {1} but it is not listed in the index, or not available for your version of KSP.", ex.parent, ex.module);
user.RaiseMessage("If you're lucky, you can do a `ckan update` and try again.");
user.RaiseMessage("Try `ckan install --no-recommends` to skip installation of recommended modules.");
return Exit.ERROR;
}
catch (ModuleNotFoundKraken ex)
{
user.RaiseMessage("Module {0} required but it is not listed in the index, or not available for your version of KSP.", ex.module);
Expand Down
4 changes: 3 additions & 1 deletion ConsoleUI/InstallScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ public override void Run(Action process = null)

} catch (BadMetadataKraken ex) {
RaiseError($"Bad metadata detected for {ex.module}: {ex.Message}");
} catch (DependencyNotSatisfiedKraken ex) {
RaiseError($"{ex.parent} requires {ex.module}, but it is not listed in the index, or not available for your version of KSP.\r\n{ex.Message}");
} catch (ModuleNotFoundKraken ex) {
RaiseError($"Module {ex.module} required but it is not listed in the index, or not available for your version of KSP. {ex.Message}");
RaiseError($"Module {ex.module} required but it is not listed in the index, or not available for your version of KSP.\r\n{ex.Message}");
} catch (ModNotInstalledKraken ex) {
RaiseError($"{ex.mod} is not installed, can't remove");
}
Expand Down
4 changes: 2 additions & 2 deletions Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ private void ResolveStanza(IEnumerable<RelationshipDescriptor> stanza, Selection
{
if (!soft_resolve)
{
log.ErrorFormat("Dependency on {0} found but it is not listed in the index, or not available for your version of KSP.", dep_name);
throw new ModuleNotFoundKraken(dep_name);
log.InfoFormat("Dependency on {0} found but it is not listed in the index, or not available for your version of KSP.", dep_name);
throw new DependencyNotSatisfiedKraken(reason.Parent, dep_name);
}
log.InfoFormat("{0} is recommended/suggested but it is not listed in the index, or not available for your version of KSP.", dep_name);
continue;
Expand Down
25 changes: 25 additions & 0 deletions Core/Types/Kraken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,31 @@ public ModuleNotFoundKraken(string module, string version = null, string reason
}
}

/// <summary>
/// Exception describing a missing dependency
/// </summary>
public class DependencyNotSatisfiedKraken : ModuleNotFoundKraken
{
/// <summary>
/// The mod with an unmet dependency
/// </summary>
public readonly CkanModule parent;

/// <summary>
/// Initialize the exceptions
/// </summary>
/// <param name="parentModule">The module with the unmet dependency</param>
/// <param name="module">The name of the missing dependency</param>
/// <param name="reason">Message parameter for base class</param>
/// <param name="innerException">Originating exception parameter for base class</param>
public DependencyNotSatisfiedKraken(CkanModule parentModule,
string module, string version = null, string reason = null, Exception innerException = null)
: base(module, version, reason, innerException)
{
parent = parentModule;
}
}

public class NotKSPDirKraken : Kraken
{
public string path;
Expand Down
7 changes: 7 additions & 0 deletions GUI/MainInstall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ private static bool WasSuccessful(Action action)
{
action();
}
catch (DependencyNotSatisfiedKraken ex)
{
GUI.user.RaiseMessage(
"{0} requires {1} but it is not listed in the index, or not available for your version of KSP.",
ex.parent, ex.module);
return false;
}
catch (ModuleNotFoundKraken ex)
{
GUI.user.RaiseMessage(
Expand Down
26 changes: 13 additions & 13 deletions Tests/Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Constructor_WithConflictingModules()
list.Add(mod_a.identifier);
list.Add(mod_b.identifier);
AddToRegistry(mod_a, mod_b);

Assert.Throws<InconsistentKraken>(() => new RelationshipResolver(
list,
options,
Expand Down Expand Up @@ -473,7 +473,7 @@ public void Constructor_WithMissingDependants_Throws()
list.Add(depender.identifier);
registry.AddAvailable(depender);

Assert.Throws<ModuleNotFoundKraken>(() => new RelationshipResolver(
Assert.Throws<DependencyNotSatisfiedKraken>(() => new RelationshipResolver(
list,
options,
registry,
Expand All @@ -495,10 +495,10 @@ public void Constructor_WithMissingDependantsVersion_Throws(string ver, string d
{
new RelationshipDescriptor {name = dependant.identifier, version = new Version(dep)}
});
list.Add(depender.identifier);
list.Add(depender.identifier);
AddToRegistry(depender, dependant);

Assert.Throws<ModuleNotFoundKraken>(() => new RelationshipResolver(
Assert.Throws<DependencyNotSatisfiedKraken>(() => new RelationshipResolver(
list,
options,
registry,
Expand All @@ -517,10 +517,10 @@ public void Constructor_WithMissingDependantsVersionMin_Throws(string ver, strin
{
new RelationshipDescriptor {name = dependant.identifier, min_version = new Version(dep_min)}
});
list.Add(depender.identifier);
list.Add(depender.identifier);
AddToRegistry(depender, dependant);

Assert.Throws<ModuleNotFoundKraken>(() => new RelationshipResolver(
Assert.Throws<DependencyNotSatisfiedKraken>(() => new RelationshipResolver(
list,
options,
registry,
Expand Down Expand Up @@ -599,7 +599,7 @@ public void Constructor_WithDependantVersion_ChooseCorrectly(string ver, string
new RelationshipDescriptor {name = dependant.identifier, version = new Version(dep)}
});

list.Add(depender.identifier);
list.Add(depender.identifier);
AddToRegistry(depender, dependant, other_dependant);

var relationship_resolver = new RelationshipResolver(list, options, registry, null);
Expand All @@ -608,7 +608,7 @@ public void Constructor_WithDependantVersion_ChooseCorrectly(string ver, string
dependant,
depender
});

}

[Test]
Expand Down Expand Up @@ -721,16 +721,16 @@ public void ReasonFor_WithModsNotInList_ThrowsArgumentException()
var relationship_resolver = new RelationshipResolver(list, options, registry, null);

var mod_not_in_resolver_list = generator.GeneratorRandomModule();
CollectionAssert.DoesNotContain(relationship_resolver.ModList(),mod_not_in_resolver_list);
CollectionAssert.DoesNotContain(relationship_resolver.ModList(),mod_not_in_resolver_list);
Assert.Throws<ArgumentException>(() => relationship_resolver.ReasonFor(mod_not_in_resolver_list));

}

[Test]
public void ReasonFor_WithUserAddedMods_GivesReasonUserAdded()
{
var list = new List<string>();
var mod = generator.GeneratorRandomModule();
var mod = generator.GeneratorRandomModule();
list.Add(mod.identifier);
registry.AddAvailable(mod);
AddToRegistry(mod);
Expand All @@ -748,7 +748,7 @@ public void ReasonFor_WithSugestedMods_GivesCorrectParent()
var mod =
generator.GeneratorRandomModule(sugests:
new List<RelationshipDescriptor> {new RelationshipDescriptor {name = sugested.identifier}});
list.Add(mod.identifier);
list.Add(mod.identifier);
AddToRegistry(mod, sugested);

options.with_all_suggests = true;
Expand All @@ -762,7 +762,7 @@ public void ReasonFor_WithSugestedMods_GivesCorrectParent()
[Test]
public void ReasonFor_WithTreeOfMods_GivesCorrectParents()
{
var list = new List<string>();
var list = new List<string>();
var sugested = generator.GeneratorRandomModule();
var recommendedA = generator.GeneratorRandomModule();
var recommendedB = generator.GeneratorRandomModule();
Expand Down

0 comments on commit 28c981e

Please sign in to comment.