Skip to content

Commit 87e783a

Browse files
committed
chore: minor improvements
1 parent f526d89 commit 87e783a

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/__tests__/cli-commands.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ describe('CLI Commands', () => {
527527
// Verify the result
528528
expect(result.success).toBe(true)
529529
expect(result.messages).toHaveLength(5) // 5 messages with details
530-
expect(result.messages[0]).toContain('Workflow executed successfully in 2500 ms')
530+
expect(result.messages[0]).toContain('Workflow executed successfully in 2.50 seconds')
531531
expect(result.messages[1]).toContain('Status: completed')
532532
expect(result.messages[2]).toContain('Started:')
533533
expect(result.messages[3]).toContain('Finished:')
@@ -547,7 +547,7 @@ describe('CLI Commands', () => {
547547
// Verify the result
548548
expect(result.success).toBe(true)
549549
expect(result.messages).toHaveLength(5) // 5 messages with details
550-
expect(result.messages[0]).toContain('Workflow executed unsuccessfully in 2500 ms')
550+
expect(result.messages[0]).toContain('Workflow executed unsuccessfully in 2.50 seconds')
551551
expect(result.messages[1]).toContain('Status: failed')
552552
expect(result.messages[2]).toContain('Started:')
553553
expect(result.messages[3]).toContain('Finished:')

src/cli-commands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ export const executeWorkflow = async (workflowId: string, data: any): Promise<Co
148148
const startTime = new Date(results.started)
149149
const endTime = new Date(results.finished)
150150
const duration = endTime.getTime() - startTime.getTime()
151+
const durationStr = duration < 1000 ? `${duration} ms` : `${(duration / 1000).toFixed(2)} seconds`
151152

152-
messages.push(`Workflow executed ${results.result.success ? 'successfully' : 'unsuccessfully'} in ${duration} ms`)
153+
messages.push(`Workflow executed ${results.result.success ? 'successfully' : 'unsuccessfully'} in ${durationStr}`)
153154
messages.push(`- Status: ${results.status}`)
154155
messages.push(`- Started: ${startTime}`)
155156
messages.push(`- Finished: ${endTime}`)

src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,18 @@ workflow
5656
}
5757
// Check if workflow requires additional data and if it is provided or requires collection
5858
if (workflow.isRequiredAdditionalData && (!options.data && !options.file)) {
59-
throw new Error('Workflow does not require additional data. Please remove -d or -f options')
59+
throw new Error('Workflow requires additional data. Please provide data using -d or -f option')
6060
} else if (options.data && options.file) {
6161
throw new Error('Please provide either -d or -f, not both')
6262
} else if (options.data) {
6363
data = options.data
6464
} else if (options.file) {
65-
data = JSON.parse(fs.readFileSync(options.file, 'utf-8'))
65+
try {
66+
const fileContent = fs.readFileSync(options.file, 'utf-8')
67+
data = JSON.parse(fileContent)
68+
} catch (error) {
69+
throw new Error(`Failed to read or parse file: ${error instanceof Error ? error.message : 'Unknown error'}`)
70+
}
6671
}
6772

6873
// If data is provided, validate against JSON Schema

0 commit comments

Comments
 (0)