Skip to content

Commit

Permalink
Don't log errors when MaintenanceSteps fail due to the repo being del…
Browse files Browse the repository at this point in the history
…eted
  • Loading branch information
wilbaker committed Aug 14, 2019
1 parent 3867bf3 commit 6f5f4d8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Scalar.Common/Git/LibGit2Repo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public LibGit2Repo(ITracer tracer, string repoPath)
{
string reason = Native.GetLastError();
string message = "Couldn't open repo at " + repoPath + ": " + reason;
tracer.RelatedError(message);
tracer.RelatedWarning(message);

Native.Shutdown();
throw new InvalidDataException(message);
Expand Down
13 changes: 1 addition & 12 deletions Scalar.Common/Maintenance/GitMaintenanceQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,7 @@ public void Stop()
/// </summary>
public bool EnlistmentRootReady()
{
// If a user locks their drive or disconnects an external drive while the mount process
// is running, then it will appear as if the directories below do not exist or throw
// a "Device is not ready" error.
try
{
return this.context.FileSystem.DirectoryExists(this.context.Enlistment.EnlistmentRoot)
&& this.context.FileSystem.DirectoryExists(this.context.Enlistment.GitObjectsRoot);
}
catch (IOException)
{
return false;
}
return GitMaintenanceStep.EnlistmentRootReady(this.context);
}

private void RunQueue()
Expand Down
39 changes: 35 additions & 4 deletions Scalar.Common/Maintenance/GitMaintenanceStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ public GitMaintenanceStep(ScalarContext context, bool requireObjectCacheLock, Gi
protected bool RequireObjectCacheLock { get; }
protected GitProcessChecker GitProcessChecker { get; }

public static bool EnlistmentRootReady(ScalarContext context)
{
// If a user locks their drive or disconnects an external drive while the mount process
// is running, then it will appear as if the directories below do not exist or throw
// a "Device is not ready" error.
try
{
return context.FileSystem.DirectoryExists(context.Enlistment.EnlistmentRoot)
&& context.FileSystem.DirectoryExists(context.Enlistment.GitObjectsRoot);
}
catch (IOException)
{
return false;
}
}

public bool EnlistmentRootReady()
{
return EnlistmentRootReady(this.Context);
}

public void Execute()
{
try
Expand Down Expand Up @@ -62,10 +83,20 @@ public void Execute()
}
catch (Exception e)
{
this.Context.Tracer.RelatedError(
metadata: this.CreateEventMetadata(e),
message: "Exception while running action: " + e.Message,
keywords: Keywords.Telemetry);
if (this.EnlistmentRootReady())
{
this.Context.Tracer.RelatedError(
metadata: this.CreateEventMetadata(e),
message: "Exception while running action: " + e.Message,
keywords: Keywords.Telemetry);
}
else
{
this.Context.Tracer.RelatedWarning(
metadata: this.CreateEventMetadata(e),
message: "Exception while running action inside a repo that's not ready: " + e.Message);
}

Environment.Exit((int)ReturnCode.GenericError);
}
}
Expand Down

0 comments on commit 6f5f4d8

Please sign in to comment.