Skip to content
Open
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
52 changes: 39 additions & 13 deletions CadRevealFbxProvider/Attributes/ScaffoldingAttributeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,45 @@ private static string[] RemoveCsvNonDescriptionHeaderInfo(string[] fileLines)

private static ICsvLine[] ConvertToCsvLines(string[] fileLines)
{
return CsvReader
.ReadFromText(
String.Join(Environment.NewLine, fileLines),
new CsvOptions()
{
HeaderMode = HeaderMode.HeaderPresent,
RowsToSkip = 0,
SkipRow = (ReadOnlyMemory<char> row, int idx) => row.Span.IsEmpty || row.Span[0] == '#' || idx == 2,
TrimData = true,
Separator = ';',
}
)
.ToArray();
const char expectedSeparator = ';';
try
{
return CsvReader
.ReadFromText(
String.Join(Environment.NewLine, fileLines),
new CsvOptions()
{
HeaderMode = HeaderMode.HeaderPresent,
RowsToSkip = 0,
SkipRow = (ReadOnlyMemory<char> row, int idx) =>
row.Span.IsEmpty || row.Span[0] == '#' || idx == 2,
TrimData = true,
Separator = expectedSeparator,
}
)
.ToArray();
}
catch (Exception e)
{
if (e.Message.Contains("Duplicate headers detected in HeaderPresent mode."))
Copy link

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relying on substring matching of the exception message to detect duplicate headers can be fragile. Consider catching a more specific exception type if available or checking a dedicated error code.

Copilot uses AI. Check for mistakes.
{
var headerRow = fileLines.First();
Console.WriteLine(
Copy link

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Console.WriteLine for diagnostics in production code may not be the best choice. Consider using a structured logging framework to improve maintainability and traceability.

Copilot uses AI. Check for mistakes.
"The first row of the CSV file is expected to contain unique headers. Current headers: \n "
+ headerRow
);

var duplicateHeaders = headerRow
.Split(expectedSeparator)
.GroupBy(h => h.Trim())
.Where(g => g.Count() > 1)
.Select(g => g.Key)
.ToList();
Console.WriteLine("Duplicate headers found: " + string.Join(", ", duplicateHeaders));
Console.WriteLine("This should not happen, the scaffolding file is invalid.");
}
throw;
}
}

private static int RetrieveKeyAttributeColumnIndex(ICsvLine[] attributeRawData)
Expand Down
Loading