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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Support file scoped namespace declarations when generating code (#140)
* Improved handling of scope tag expressions, hook and scope errors (#150)
* Improved logging for binding discovery (#154)
* Report generic binding errors and log type load errors of binding discovery (#157)

## Bug fixes:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public static DiscoveryResult Execute(DiscoveryOptions options,
Hooks = discoveryResult.Hooks,
SourceFiles = new Dictionary<string, string>(discoveryResult.SourceFiles),
TypeNames = new Dictionary<string, string>(discoveryResult.TypeNames),
GenericBindingErrors = discoveryResult.GenericBindingErrors,
LogMessages = discoveryResult.TypeLoadErrors.Select(e => $"Type or method has been skipped: {e}").ToArray(),
AnalyticsProperties = analytics.ToDictionary()
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public InternalDiscoveryResult Transform(BindingData bindingData, ISourceLocatio
.OrderBy(sd => sd.SourceLocation)
.ToArray();

string[] GetErrorsWithPrefix(string prefix) =>
bindingData.Errors?
.Where(e => e.StartsWith(prefix))
.Select(e => e.Substring(prefix.Length).Trim())
.ToArray() ?? Array.Empty<string>();

var typeLoadErrors = GetErrorsWithPrefix("TypeLoadError:");
var genericBindingErrors = GetErrorsWithPrefix("BindingError:");

analytics.AddAnalyticsProperty("TypeNames", typeNamesToKey.Count.ToString());
analytics.AddAnalyticsProperty("SourcePaths", sourceFilesToKey.Count.ToString());
Expand All @@ -46,7 +54,9 @@ public InternalDiscoveryResult Transform(BindingData bindingData, ISourceLocatio
stepDefinitions,
hooks,
ReverseDictionary(sourceFilesToKey),
ReverseDictionary(typeNamesToKey)
ReverseDictionary(typeNamesToKey),
genericBindingErrors,
typeLoadErrors
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ public record InternalDiscoveryResult(
Reqnroll.VisualStudio.ReqnrollConnector.Models.StepDefinition[] StepDefinitions,
Reqnroll.VisualStudio.ReqnrollConnector.Models.Hook[] Hooks,
IDictionary<string, string> SourceFiles,
IDictionary<string, string> TypeNames
IDictionary<string, string> TypeNames,
string[] GenericBindingErrors,
string[] TypeLoadErrors
);
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public abstract class ConnectorResult
public string ReqnrollVersion { get; set; }
public string ErrorMessage { get; set; }
public bool IsFailed => !string.IsNullOrWhiteSpace(ErrorMessage);
public string[] LogMessages { get; set; }
public string[] Warnings { get; set; }
public Dictionary<string, object> AnalyticsProperties { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public class DiscoveryResult : ConnectorResult
public Hook[] Hooks { get; set; } = Array.Empty<Hook>();
public Dictionary<string, string> SourceFiles { get; set; }
public Dictionary<string, string> TypeNames { get; set; }
public string[] GenericBindingErrors { get; set; }
}
50 changes: 50 additions & 0 deletions Reqnroll.VisualStudio/Discovery/DiscoveryInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,36 @@ public IDiscovery AndDiscoveryProviderSucceed(IDiscoveryResultProvider discovery
_discoveryResult = discoveryResultProvider.RunDiscovery(_testAssemblySource.FilePath,
_projectSettings.ReqnrollConfigFilePath, _projectSettings);

if (_discoveryResult.LogMessages is { Length: > 0 })
{
foreach (var logMessage in _discoveryResult.LogMessages)
{
var lines = logMessage.Trim().Split(new[] {'\n', '\r'}, StringSplitOptions.RemoveEmptyEntries);
_logger.LogInfo(lines[0]);
if (lines.Length > 1)
{
_logger.LogVerbose($"Additional details:{Environment.NewLine}{string.Join(Environment.NewLine, lines.Skip(1))}");
}
}
}

if (_discoveryResult.Warnings is { Length: > 0 })
{
foreach (string warning in _discoveryResult.Warnings)
{
_logger.LogWarning(warning);
_errorListServices.AddErrors(new[]
{
new DeveroomUserError
{
Category = DeveroomUserErrorCategory.Discovery,
Message = warning,
Type = TaskErrorCategory.Warning
}
});
}
}

if (!_discoveryResult.IsFailed)
return this;

Expand Down Expand Up @@ -142,12 +172,32 @@ public IDiscovery ThenImportBindings(string projectName)
_logger.LogInfo(
$"{_stepDefinitions.Length} step definitions and {_hooks.Length} hooks discovered for project {projectName}");

ReportGenericBindingErrors();
ReportInvalidStepDefinitions();
ReportInvalidHooks();

return this;
}

private void ReportGenericBindingErrors()
{
if (_discoveryResult.GenericBindingErrors == null || !_discoveryResult.GenericBindingErrors.Any())
return;

_logger.LogWarning($"Generic binding errors found: {Environment.NewLine}" +
string.Join(Environment.NewLine, _discoveryResult.GenericBindingErrors));

_errorListServices.AddErrors(
_discoveryResult.GenericBindingErrors
.Select(errorMessage => new DeveroomUserError
{
Category = DeveroomUserErrorCategory.Discovery,
Message = errorMessage,
Type = TaskErrorCategory.Error
})
);
}

public ProjectBindingRegistry AndCreateBindingRegistry(IMonitoringService monitoringService)
{
monitoringService.MonitorReqnrollDiscovery(_discoveryResult.IsFailed, _discoveryResult.ErrorMessage,
Expand Down