Skip to content

Command update [year/day] fails if no year folder exists in root #8

@xKirtle

Description

@xKirtle

I was trying to make use of this AOC framework to solve AOC challenges myself, but it seems to break if no year folder exists

execute, for example, dotnet run update 2021/1

Updating https://adventofcode.com/2021/day/1
Unhandled exception. System.AggregateException: One or more errors occurred. (Sequence contains no elements)
 ---> System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.MinInteger[T](IEnumerable`1 source)
   at AdventOfCode.Updater.Update(Int32 year, Int32 day) in ...RepoPath...\Lib\Updater.cs:line 52
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at Program.<>c__DisplayClass0_1.<<Main>$>b__16() in ...RepoPath...\App.cs:line 17
   at Program.<Main>$(String[] args) in ...RepoPath...\App.cs:line 111

In Updater.Update():

...
var years = Assembly.GetEntryAssembly().GetTypes()
    .Where(t => t.GetTypeInfo().IsClass && typeof(Solver).IsAssignableFrom(t))
    .Select(tsolver => SolverExtensions.Year(tsolver));

UpdateProjectReadme(years.Min(), years.Max());
...

the Enumerable years variable seems to be empty and it breaks when attempting to get the Min() and Max() of the collection.

I think something like this would solve the issue:

...
var years = Assembly.GetEntryAssembly().GetTypes()
    .Where(t => t.GetTypeInfo().IsClass && typeof(Solver).IsAssignableFrom(t))
    .Select(tsolver => SolverExtensions.Year(tsolver));

if (years.Count() == 0) {
    years = new int[] { year };
}

UpdateProjectReadme(years.Min(), years.Max());
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions