Skip to content

Commit 5cd07fd

Browse files
committed
refactor: remove extra function
1 parent b733b88 commit 5cd07fd

File tree

2 files changed

+4
-40
lines changed

2 files changed

+4
-40
lines changed

src/components/queue/job/useJobErrorReporting.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@ export type JobErrorDialogService = {
1515
) => void
1616
}
1717

18-
/**
19-
* Extracts error message from a task.
20-
* Returns the simple error_message string from the jobs API.
21-
*
22-
* Note: Detailed execution errors (with traceback, node info, etc.) are only
23-
* available via WebSocket during live execution. Historical job errors only
24-
* have the simple error_message string.
25-
*/
26-
export const extractErrorMessage = (task: TaskItemImpl | null): string | null =>
27-
task?.errorMessage ?? null
28-
2918
type UseJobErrorReportingOptions = {
3019
taskForJob: ComputedRef<TaskItemImpl | null>
3120
copyToClipboard: CopyHandler
@@ -37,9 +26,7 @@ export const useJobErrorReporting = ({
3726
copyToClipboard,
3827
dialog
3928
}: UseJobErrorReportingOptions) => {
40-
const errorMessageValue = computed(
41-
() => extractErrorMessage(taskForJob.value) ?? ''
42-
)
29+
const errorMessageValue = computed(() => taskForJob.value?.errorMessage ?? '')
4330

4431
const copyErrorMessage = () => {
4532
if (errorMessageValue.value) {

tests-ui/tests/components/queue/useJobErrorReporting.test.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,26 @@ import type { ComputedRef } from 'vue'
44

55
import type { TaskItemImpl } from '@/stores/queueStore'
66
import type { JobErrorDialogService } from '@/components/queue/job/useJobErrorReporting'
7-
import * as jobErrorReporting from '@/components/queue/job/useJobErrorReporting'
7+
import { useJobErrorReporting } from '@/components/queue/job/useJobErrorReporting'
88

9-
/**
10-
* Creates a mock TaskItemImpl with an error message.
11-
*/
129
const createTaskWithError = (errorMessage?: string): TaskItemImpl =>
1310
({ errorMessage }) as unknown as TaskItemImpl
1411

15-
describe('extractErrorMessage', () => {
16-
it('returns null when task is null', () => {
17-
expect(jobErrorReporting.extractErrorMessage(null)).toBeNull()
18-
})
19-
20-
it('returns null when errorMessage is undefined', () => {
21-
expect(
22-
jobErrorReporting.extractErrorMessage(createTaskWithError())
23-
).toBeNull()
24-
})
25-
26-
it('returns the error message when present', () => {
27-
expect(
28-
jobErrorReporting.extractErrorMessage(
29-
createTaskWithError('Something failed')
30-
)
31-
).toBe('Something failed')
32-
})
33-
})
34-
3512
describe('useJobErrorReporting', () => {
3613
let taskState = ref<TaskItemImpl | null>(null)
3714
let taskForJob: ComputedRef<TaskItemImpl | null>
3815
let copyToClipboard: ReturnType<typeof vi.fn>
3916
let showErrorDialog: ReturnType<typeof vi.fn>
4017
let dialog: JobErrorDialogService
41-
let composable: ReturnType<typeof jobErrorReporting.useJobErrorReporting>
18+
let composable: ReturnType<typeof useJobErrorReporting>
4219

4320
beforeEach(() => {
4421
taskState = ref<TaskItemImpl | null>(null)
4522
taskForJob = computed(() => taskState.value)
4623
copyToClipboard = vi.fn()
4724
showErrorDialog = vi.fn()
4825
dialog = { showErrorDialog }
49-
composable = jobErrorReporting.useJobErrorReporting({
26+
composable = useJobErrorReporting({
5027
taskForJob,
5128
copyToClipboard,
5229
dialog

0 commit comments

Comments
 (0)