fix(runtime): reduce diagnostic prefix regex complexity
This commit is contained in:
parent
26c394674b
commit
61ad4f2d7c
1 changed files with 30 additions and 8 deletions
|
|
@ -147,6 +147,33 @@ const UNKNOWN_CLASSIFICATION: RuntimeDiagnosticClassification = {
|
||||||
generic: true,
|
generic: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function stripLatestAssistantFailurePrefix(message: string): string {
|
||||||
|
const marker = ' failed with ';
|
||||||
|
const lowerMessage = message.toLowerCase();
|
||||||
|
const markerIndex = lowerMessage.indexOf(marker);
|
||||||
|
if (!lowerMessage.startsWith('latest assistant message ') || markerIndex < 0) {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
const errorNameStart = markerIndex + marker.length;
|
||||||
|
const dashIndex = message.indexOf('-', errorNameStart);
|
||||||
|
const colonIndex = message.indexOf(':', errorNameStart);
|
||||||
|
const separatorIndexes = [dashIndex, colonIndex]
|
||||||
|
.filter((index) => index >= 0)
|
||||||
|
.sort((left, right) => left - right);
|
||||||
|
if (separatorIndexes.length === 0) {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
const separatorIndex = separatorIndexes[0];
|
||||||
|
const errorName = message.slice(errorNameStart, separatorIndex).trim();
|
||||||
|
if (!/^[A-Za-z][A-Za-z0-9_.]*Error$/.test(errorName)) {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return message.slice(separatorIndex + 1).trimStart();
|
||||||
|
}
|
||||||
|
|
||||||
export function normalizeRuntimeDiagnosticMessage(
|
export function normalizeRuntimeDiagnosticMessage(
|
||||||
message: string | null | undefined
|
message: string | null | undefined
|
||||||
): string | null {
|
): string | null {
|
||||||
|
|
@ -154,14 +181,9 @@ export function normalizeRuntimeDiagnosticMessage(
|
||||||
(current, pattern) => current.replace(pattern, '[redacted]'),
|
(current, pattern) => current.replace(pattern, '[redacted]'),
|
||||||
message ?? ''
|
message ?? ''
|
||||||
);
|
);
|
||||||
const normalized = scrubbed
|
const normalized = stripLatestAssistantFailurePrefix(
|
||||||
.replace(/\s+/g, ' ')
|
scrubbed.replace(/\s+/g, ' ').trim()
|
||||||
.trim()
|
).replace(/^APIError\s*[-:]\s*/i, '');
|
||||||
.replace(
|
|
||||||
/^Latest assistant message(?:\s+\S+|\s+for\s+opencode\s+session\s+\S+)?\s+failed with\s+[^-:]+Error\s*[-:]\s*/i,
|
|
||||||
''
|
|
||||||
)
|
|
||||||
.replace(/^APIError\s*[-:]\s*/i, '');
|
|
||||||
return normalized.length > 0 ? normalized : null;
|
return normalized.length > 0 ? normalized : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue