Skip to content

Commit

Permalink
azp: context filetable / wip improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX authored Nov 2, 2023
1 parent 1426788 commit f0ecebb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Sdk/AzurePipelines/AzureDevops.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,20 @@ public static string RelativeTo(string cwd, string filename) {

public static async Task<MappingToken> ReadTemplate(Runner.Server.Azure.Devops.Context context, string filenameAndRef, Dictionary<string, TemplateToken> cparameters = null, string schemaName = null) {
var variables = context.VariablesProvider?.GetVariablesForEnvironment("");
var templateContext = AzureDevops.CreateTemplateContext(context.TraceWriter ?? new EmptyTraceWriter(), new List<string>(), context.Flags);
var afilenameAndRef = filenameAndRef.Split("@", 2);
var filename = afilenameAndRef[0];
var fileId = templateContext.GetFileId(filename);
// Read the file
var finalRepository = afilenameAndRef.Length == 1 ? context.RepositoryAndRef : string.Equals(afilenameAndRef[1], "self", StringComparison.OrdinalIgnoreCase) ? null : (context.Repositories?.TryGetValue(afilenameAndRef[1], out var ralias) ?? false) ? ralias : throw new Exception($"Couldn't find repository with alias {afilenameAndRef[1]} in repository resources");
var finalFileName = context.RepositoryAndRef == finalRepository ? RelativeTo(context.CWD ?? ".", filename) : filename;
if(finalFileName == null) {
throw new Exception($"Couldn't find template location {filenameAndRef}");
}

context.FileTable ??= new List<string>();
context.FileTable.Add(finalFileName);
var templateContext = AzureDevops.CreateTemplateContext(context.TraceWriter ?? new EmptyTraceWriter(), context.FileTable, context.Flags);
var fileId = templateContext.GetFileId(finalFileName);

var fileContent = await context.FileProvider.ReadFile(finalRepository, finalFileName);
if(fileContent == null) {
throw new Exception($"Couldn't read template {filenameAndRef} resolved to {finalFileName} ({finalRepository ?? "self"})");
Expand Down
1 change: 1 addition & 0 deletions src/Sdk/AzurePipelines/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Context {

public ITaskByNameAndVersionProvider TaskByNameAndVersion { get; set; }
public IRequiredParametersProvider RequiredParametersProvider { get; set; }
public List<string> FileTable { get; set; } = new List<string>();

public Context Clone() {
return MemberwiseClone() as Context;
Expand Down

0 comments on commit f0ecebb

Please sign in to comment.