refactor: remove extra function

This commit is contained in:
Richard Yu
2025-12-03 14:55:04 -08:00
parent b733b88628
commit 5cd07fd91b
2 changed files with 4 additions and 40 deletions

View File

@@ -15,17 +15,6 @@ export type JobErrorDialogService = {
) => void
}
/**
* Extracts error message from a task.
* Returns the simple error_message string from the jobs API.
*
* Note: Detailed execution errors (with traceback, node info, etc.) are only
* available via WebSocket during live execution. Historical job errors only
* have the simple error_message string.
*/
export const extractErrorMessage = (task: TaskItemImpl | null): string | null =>
task?.errorMessage ?? null
type UseJobErrorReportingOptions = {
taskForJob: ComputedRef<TaskItemImpl | null>
copyToClipboard: CopyHandler
@@ -37,9 +26,7 @@ export const useJobErrorReporting = ({
copyToClipboard,
dialog
}: UseJobErrorReportingOptions) => {
const errorMessageValue = computed(
() => extractErrorMessage(taskForJob.value) ?? ''
)
const errorMessageValue = computed(() => taskForJob.value?.errorMessage ?? '')
const copyErrorMessage = () => {
if (errorMessageValue.value) {

View File

@@ -4,41 +4,18 @@ import type { ComputedRef } from 'vue'
import type { TaskItemImpl } from '@/stores/queueStore'
import type { JobErrorDialogService } from '@/components/queue/job/useJobErrorReporting'
import * as jobErrorReporting from '@/components/queue/job/useJobErrorReporting'
import { useJobErrorReporting } from '@/components/queue/job/useJobErrorReporting'
/**
* Creates a mock TaskItemImpl with an error message.
*/
const createTaskWithError = (errorMessage?: string): TaskItemImpl =>
({ errorMessage }) as unknown as TaskItemImpl
describe('extractErrorMessage', () => {
it('returns null when task is null', () => {
expect(jobErrorReporting.extractErrorMessage(null)).toBeNull()
})
it('returns null when errorMessage is undefined', () => {
expect(
jobErrorReporting.extractErrorMessage(createTaskWithError())
).toBeNull()
})
it('returns the error message when present', () => {
expect(
jobErrorReporting.extractErrorMessage(
createTaskWithError('Something failed')
)
).toBe('Something failed')
})
})
describe('useJobErrorReporting', () => {
let taskState = ref<TaskItemImpl | null>(null)
let taskForJob: ComputedRef<TaskItemImpl | null>
let copyToClipboard: ReturnType<typeof vi.fn>
let showErrorDialog: ReturnType<typeof vi.fn>
let dialog: JobErrorDialogService
let composable: ReturnType<typeof jobErrorReporting.useJobErrorReporting>
let composable: ReturnType<typeof useJobErrorReporting>
beforeEach(() => {
taskState = ref<TaskItemImpl | null>(null)
@@ -46,7 +23,7 @@ describe('useJobErrorReporting', () => {
copyToClipboard = vi.fn()
showErrorDialog = vi.fn()
dialog = { showErrorDialog }
composable = jobErrorReporting.useJobErrorReporting({
composable = useJobErrorReporting({
taskForJob,
copyToClipboard,
dialog