88} from '../modules/cli-output' ;
99import { DefaultLogger } from '../utils/logger/logger' ;
1010
11- import type { Config , RuleSeverity } from '@redocly/openapi-core' ;
11+ import type { Config } from '@redocly/openapi-core' ;
1212import type { CollectFn } from '@redocly/openapi-core/src/utils' ;
1313import type { RunArgv } from '../types' ;
1414
@@ -33,20 +33,18 @@ export type RespectOptions = {
3333 'client-key' ?: string ;
3434 'ca-cert' ?: string ;
3535 severity ?: string ;
36- config ?: string ;
37- 'lint-config' ?: RuleSeverity ;
3836} ;
3937
4038const logger = DefaultLogger . getInstance ( ) ;
4139export async function handleRun ( { argv, collectSpecData } : CommandArgs < RespectOptions > ) {
4240 const harOutputFile = argv [ 'har-output' ] ;
4341 if ( harOutputFile && ! harOutputFile . endsWith ( '.har' ) ) {
44- exitWithError ( 'File for HAR logs should be in .har format' ) ;
42+ throw new Error ( 'File for HAR logs should be in .har format' ) ;
4543 }
4644
4745 const jsonOutputFile = argv [ 'json-output' ] ;
4846 if ( jsonOutputFile && ! jsonOutputFile . endsWith ( '.json' ) ) {
49- exitWithError ( 'File for JSON logs should be in .json format' ) ;
47+ throw new Error ( 'File for JSON logs should be in .json format' ) ;
5048 }
5149
5250 const { skip, workflow } = argv ;
@@ -57,38 +55,42 @@ export async function handleRun({ argv, collectSpecData }: CommandArgs<RespectOp
5755 return ;
5856 }
5957
60- const startedAt = performance . now ( ) ;
61- const testsRunProblemsStatus : boolean [ ] = [ ] ;
62- const { files } = argv ;
63- const runAllFilesResult = [ ] ;
58+ try {
59+ const startedAt = performance . now ( ) ;
60+ const testsRunProblemsStatus : boolean [ ] = [ ] ;
61+ const { files } = argv ;
62+ const runAllFilesResult = [ ] ;
63+
64+ if ( files . length > 1 && ( jsonOutputFile || harOutputFile ) ) {
65+ // TODO: implement multiple run files logs output
66+ throw new Error (
67+ 'Currently only a single file can be run with --har-output or --json-output. Please run a single file at a time.'
68+ ) ;
69+ }
70+
71+ for ( const path of files ) {
72+ const result = await runFile (
73+ { ...argv , file : path } ,
74+ startedAt ,
75+ {
76+ harFile : harOutputFile ,
77+ jsonFile : jsonOutputFile ,
78+ } ,
79+ collectSpecData
80+ ) ;
81+ testsRunProblemsStatus . push ( result . hasProblems ) ;
82+ runAllFilesResult . push ( result ) ;
83+ }
6484
65- if ( files . length > 1 && ( jsonOutputFile || harOutputFile ) ) {
66- // TODO: implement multiple run files logs output
67- exitWithError (
68- 'Currently only a single file can be run with --har-output or --json-output. Please run a single file at a time.'
69- ) ;
70- }
71-
72- for ( const path of files ) {
73- const result = await runFile (
74- { ...argv , file : path } ,
75- startedAt ,
76- {
77- harFile : harOutputFile ,
78- jsonFile : jsonOutputFile ,
79- } ,
80- collectSpecData
81- ) ;
82- testsRunProblemsStatus . push ( result . hasProblems ) ;
83- runAllFilesResult . push ( result ) ;
84- }
85-
86- logger . printNewLine ( ) ;
87- displayFilesSummaryTable ( runAllFilesResult ) ;
88- logger . printNewLine ( ) ;
85+ logger . printNewLine ( ) ;
86+ displayFilesSummaryTable ( runAllFilesResult ) ;
87+ logger . printNewLine ( ) ;
8988
90- if ( testsRunProblemsStatus . some ( ( problems ) => problems ) ) {
91- exitWithError ( ' Tests exited with error ' ) ;
89+ if ( testsRunProblemsStatus . some ( ( problems ) => problems ) ) {
90+ throw new Error ( ' Tests exited with error ' ) ;
91+ }
92+ } catch ( err ) {
93+ exitWithError ( ( err as Error ) ?. message ?? err ) ;
9294 }
9395}
9496
0 commit comments