Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions source/Calamari.Common/Features/Substitutions/FileSubstituter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Text;
using Calamari.Common.Commands;
using Calamari.Common.Plumbing.FileSystem;
using Calamari.Common.Plumbing.Logging;
using Calamari.Common.Plumbing.Variables;
Expand All @@ -22,7 +23,7 @@ public FileSubstituter(ILog log, ICalamariFileSystem fileSystem, IVariables vari
public void PerformSubstitution(string sourceFile)
=> PerformSubstitution(sourceFile, sourceFile);

public void PerformSubstitution(string sourceFile, string targetFile)
public void PerformSubstitution(string sourceFile, string targetFile)
=> PerformSubstitutionAndUpdateFile(sourceFile, targetFile, variables.GetFlag(KnownVariables.ShouldFailDeploymentOnSubstitutionFails));

protected virtual void PerformSubstitutionAndUpdateFile(string sourceFile, string targetFile, bool throwOnError, bool throwPlainOctostacheError = false)
Expand All @@ -36,15 +37,14 @@ protected virtual void PerformSubstitutionAndUpdateFile(string sourceFile, strin

if (!string.IsNullOrEmpty(error))
{
var errorMessage = $"Parsing file '{sourceFile}' with Octostache returned the following error: `{error}`";
if (throwOnError)
{
var message = !throwPlainOctostacheError
? $"Parsing file '{sourceFile}' with Octostache returned the following error: `{error}`"
: error;
throw new InvalidOperationException(message);
var message = throwPlainOctostacheError ? error : errorMessage;
throw new CommandException(message);
}

log.VerboseFormat("Parsing file '{0}' with Octostache returned the following error: `{1}`", sourceFile, error);
log.Verbose(errorMessage);
}

fileSystem.OverwriteFile(targetFile, result, encoding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected override void PerformSubstitutionAndUpdateFile(string sourceFile, stri
//We always want to throw when substitution fails
base.PerformSubstitutionAndUpdateFile(sourceFile, targetFile, true, true);
}
catch (InvalidOperationException e)
catch (CommandException e)
{
throw new CommandException($"{e.Message}. This may be due to missing or sensitive variables.");
}
Expand Down