diff --git a/packages/trace-viewer/src/ui/errorsTab.tsx b/packages/trace-viewer/src/ui/errorsTab.tsx index 427e27a623..c573b4e9b1 100644 --- a/packages/trace-viewer/src/ui/errorsTab.tsx +++ b/packages/trace-viewer/src/ui/errorsTab.tsx @@ -97,6 +97,49 @@ export function useErrorsTabModel(model: modelUtil.MultiTraceModel | undefined): }, [model]); } +function Error({ message, error, wallTime, sdkLanguage, pageSnapshot, revealInSource }: { message: string, error: ErrorDescription, wallTime: number, sdkLanguage: Language, pageSnapshot?: string, revealInSource: (error: ErrorDescription) => void }) { + const [showLLM, setShowLLM] = React.useState(false); + const llmAvailable = !!useLLMChat(); + const gitCommitInfo = useGitCommitInfo(); + const diff = gitCommitInfo?.['pull.diff'] ?? gitCommitInfo?.['revision.diff']; + + let location: string | undefined; + let longLocation: string | undefined; + const stackFrame = error.stack?.[0]; + if (stackFrame) { + const file = stackFrame.file.replace(/.*[/\\](.*)/, '$1'); + location = file + ':' + stackFrame.line; + longLocation = stackFrame.file + ':' + stackFrame.line; + } + + const errorId = `error-${wallTime}-${longLocation}`; + + return
+
+ {error.action && renderAction(error.action, { sdkLanguage })} + {location &&
+ @ revealInSource(error)}>{location} +
} + + {llmAvailable + ? setShowLLM(v => !v)} title="Fix with AI" className='copy-to-clipboard-text-button'>Fix with AI + : } + +
+ + + + {showLLM && } +
; +} + export const ErrorsTab: React.FunctionComponent<{ errorsModel: ErrorsTabModel, actions: modelUtil.ActionTraceEventInContext[], @@ -104,53 +147,13 @@ export const ErrorsTab: React.FunctionComponent<{ sdkLanguage: Language, revealInSource: (error: ErrorDescription) => void, }> = ({ errorsModel, sdkLanguage, revealInSource, actions, wallTime }) => { - const [showLLM, setShowLLM] = React.useState(false); - const llmAvailable = !!useLLMChat(); const pageSnapshot = usePageSnapshot(actions); - const gitCommitInfo = useGitCommitInfo(); - const diff = gitCommitInfo?.['pull.diff'] ?? gitCommitInfo?.['revision.diff']; + if (!errorsModel.errors.size) return ; - return
- {[...errorsModel.errors.entries()].map(([message, error]) => { - let location: string | undefined; - let longLocation: string | undefined; - const stackFrame = error.stack?.[0]; - if (stackFrame) { - const file = stackFrame.file.replace(/.*[/\\](.*)/, '$1'); - location = file + ':' + stackFrame.line; - longLocation = stackFrame.file + ':' + stackFrame.line; - } - - const errorId = `error-${wallTime}-${longLocation}`; - - return
-
- {error.action && renderAction(error.action, { sdkLanguage })} - {location &&
- @ revealInSource(error)}>{location} -
} - - {llmAvailable - ? setShowLLM(v => !v)} title="Fix with AI" className='copy-to-clipboard-text-button'>Fix with AI - : } - -
- - - - {showLLM && } -
; - })} + {[...errorsModel.errors.entries()].map(([message, error]) => )}
; };