Add JobException to avoid printing needless stack traces for normal operation errors

This commit is contained in:
Jordan Brown
2018-08-18 14:01:44 -04:00
parent e4e8a78c33
commit 4d1c29c1cb
8 changed files with 50 additions and 18 deletions
@@ -134,7 +134,7 @@ namespace Tgstation.Server.Host.Components.Byond
cancellationToken.ThrowIfCancellationRequested();
if (exitCode != 0)
throw new Exception(String.Format(CultureInfo.InvariantCulture, "Failed to install included DirectX! Exit code: {0}", exitCode));
throw new JobException(String.Format(CultureInfo.InvariantCulture, "Failed to install included DirectX! Exit code: {0}", exitCode));
installedDirectX = true;
}
}
@@ -263,7 +263,7 @@ namespace Tgstation.Server.Host.Components.Compiler
lock (this)
{
if (Status != CompilerStatus.Idle)
throw new Exception("There is already a compile in progress!");
throw new JobException("There is already a compile in progress!");
Status = CompilerStatus.Copying;
}
@@ -336,7 +336,7 @@ namespace Tgstation.Server.Host.Components.Compiler
logger.LogTrace("Searching for available .dmes...");
var path = (await ioManager.GetFilesWithExtension(dirA, DmeExtension, cancellationToken).ConfigureAwait(false)).FirstOrDefault();
if (path == default)
throw new Exception("Unable to find any .dme!");
throw new JobException("Unable to find any .dme!");
var dmeWithExtension = ioManager.GetFileName(path);
job.DmeName = dmeWithExtension.Substring(0, dmeWithExtension.Length - DmeExtension.Length - 1);
}
@@ -364,7 +364,7 @@ namespace Tgstation.Server.Host.Components.Compiler
{
//server never validated or compile failed
await eventConsumer.HandleEvent(EventType.CompileFailure, new List<string> { resolvedGameDirectory, exitCode == 0 ? "1" : "0" }, cancellationToken).ConfigureAwait(false);
throw new Exception(exitCode == 0 ? "Validation of the TGS api failed!" : String.Format(CultureInfo.InvariantCulture, "DM exited with a non-zero code: {0}{1}", exitCode, job.Output));
throw new JobException(exitCode == 0 ? "Validation of the TGS api failed!" : String.Format(CultureInfo.InvariantCulture, "DM exited with a non-zero code: {0}{1}", exitCode, job.Output));
}
logger.LogTrace("Running post compile event...");
@@ -35,7 +35,7 @@ namespace Tgstation.Server.Host.Components.Repository
public string GitHubRepoName { get; }
/// <inheritdoc />
public bool Tracking => repository.Head.IsTracking;
public bool Tracking => Reference != null && repository.Head.IsTracking;
/// <inheritdoc />
public string Head => repository.Head.Tip.Sha;
@@ -320,7 +320,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
if (dmbBackup == null) //NANI!?
//just give up, if THAT compile job is failing then the ActiveServer is gonna crash soon too or already has
throw new Exception("Creating backup DMB provider failed!");
throw new JobException("Creating backup DMB provider failed!");
monitorState.InactiveServer = await sessionControllerFactory.LaunchNew(ActiveLaunchParameters, dmbBackup, null, false, !monitorState.ActiveServer.IsPrimary, false, cancellationToken).ConfigureAwait(false);
usedMostRecentDmb = false;
@@ -687,9 +687,9 @@ namespace Tgstation.Server.Host.Components.Watchdog
var launch = await controller.LaunchResult.ConfigureAwait(false);
if (launch.ExitCode.HasValue)
//you killed us ray...
throw new Exception(String.Format(CultureInfo.InvariantCulture, "{1} server failed to start: {0}", launch.ToString(), serverName));
throw new JobException(String.Format(CultureInfo.InvariantCulture, "{1} server failed to start: {0}", launch.ToString(), serverName));
if (!launch.StartupTime.HasValue)
throw new Exception(String.Format(CultureInfo.InvariantCulture, "{1} server timed out on startup: {0}s", launch.ToString(), ActiveLaunchParameters.StartupTimeout.Value));
throw new JobException(String.Format(CultureInfo.InvariantCulture, "{1} server timed out on startup: {0}s", launch.ToString(), ActiveLaunchParameters.StartupTimeout.Value));
return launch;
}
@@ -162,7 +162,7 @@ namespace Tgstation.Server.Host.Controllers
using (var repos = await repoManager.CloneRepository(new Uri(origin), cloneBranch, currentModel.AccessUser, currentModel.AccessToken, progressReporter, cancellationToken).ConfigureAwait(false))
{
if (repos == null)
throw new Exception("Filesystem conflict while cloning repository!");
throw new JobException("Filesystem conflict while cloning repository!");
var db = serviceProvider.GetRequiredService<IDatabaseContext>();
if (await PopulateApi(api, repos, db, Instance, null, null, cancellationToken).ConfigureAwait(false))
await db.Save(cancellationToken).ConfigureAwait(false);
@@ -315,7 +315,7 @@ namespace Tgstation.Server.Host.Controllers
using (var repo = await instanceManager.GetInstance(Instance).RepositoryManager.LoadRepository(ct).ConfigureAwait(false))
{
if (repo == null)
throw new InvalidOperationException("Repository could not be loaded!");
throw new JobException("Repository could not be loaded!");
var modelHasShaOrReference = model.CheckoutSha != null || model.Reference != null;
@@ -323,7 +323,7 @@ namespace Tgstation.Server.Host.Controllers
var startSha = repo.Head;
if (newTestMerges && !repo.IsGitHubRepository)
throw new InvalidOperationException("Cannot test merge on a non GitHub based repository!");
throw new JobException("Cannot test merge on a non GitHub based repository!");
var committerName = currentModel.ShowTestMergeCommitters.Value ? AuthenticationContext.User.Name : currentModel.CommitterName;
@@ -357,15 +357,15 @@ namespace Tgstation.Server.Host.Controllers
//fetch/pull
if (model.UpdateFromOrigin == true)
{
if (!repo.Tracking && model.Reference == null)
throw new InvalidOperationException("Not on an updatable reference!");
if (!repo.Tracking)
throw new JobException("Not on an updatable reference!");
await repo.FetchOrigin(currentModel.AccessUser, currentModel.AccessToken, x => progressReporter(x / numFetches), ct).ConfigureAwait(false);
doneFetches = 1;
if (!modelHasShaOrReference)
{
var fastForward = await repo.MergeOrigin(committerName, currentModel.CommitterEmail, ct).ConfigureAwait(false);
if (!fastForward.HasValue)
throw new InvalidOperationException("Merge conflict occurred during origin update!");
throw new JobException("Merge conflict occurred during origin update!");
await UpdateRevInfo().ConfigureAwait(false);
if (fastForward.Value)
{
@@ -388,7 +388,7 @@ namespace Tgstation.Server.Host.Controllers
if (model.UpdateFromOrigin == true && model.Reference != null)
{
if (!repo.Tracking)
throw new InvalidOperationException("Checked out reference does not track a remote object!");
throw new JobException("Checked out reference does not track a remote object!");
await repo.ResetToOrigin(ct).ConfigureAwait(false);
await repo.Sychronize(currentModel.AccessUser, currentModel.AccessToken, true, ct).ConfigureAwait(false);
await LoadRevisionInformation(repo, databaseContext, attachedInstance, null, x => lastRevisionInfo = x, ct).ConfigureAwait(false);
@@ -0,0 +1,34 @@
using System;
namespace Tgstation.Server.Host
{
/// <summary>
/// Operation exceptions thrown from the context of a <see cref="Models.Job"/>
/// </summary>
public sealed class JobException : Exception
{
/// <summary>
/// Construct a <see cref="JobException"/>
/// </summary>
public JobException()
{
}
/// <summary>
/// Construct a <see cref="JobException"/> with a <paramref name="message"/>
/// </summary>
/// <param name="message">The message for the <see cref="Exception"/></param>
public JobException(string message) : base(message)
{
}
/// <summary>
/// Construct a <see cref="JobException"/> with a <paramref name="message"/> and <paramref name="innerException"/>
/// </summary>
/// <param name="message">The message for the <see cref="Exception"/></param>
/// <param name="innerException">The inner <see cref="Exception"/> for the nase <see cref="Exception"/></param>
public JobException(string message, Exception innerException) : base(message, innerException)
{
}
}
}
+1 -1
View File
@@ -95,7 +95,7 @@ namespace Tgstation.Server.Host.Core
catch (Exception e)
{
logger.LogDebug("Job {0} exited with error! Exception: {1}", job.Id, e);
job.ExceptionDetails = e.ToString();
job.ExceptionDetails = e is JobException ? e.Message : e.ToString();
}
job.StoppedAt = DateTimeOffset.Now;
await databaseContext.Save(default).ConfigureAwait(false);
-2
View File
@@ -1,5 +1,3 @@
Verify the byond cache folder location on linux
Test watchdog
Add a JobException type that the job manager will just print the message of. Replace throw new Exception()s with it