( _program: Command )
| 38 | } |
| 39 | |
| 40 | export function createValidateAction( |
| 41 | _program: Command |
| 42 | ): (path: string | undefined, options: ValidateOptions) => Promise<void> { |
| 43 | return async (path, options) => { |
| 44 | try { |
| 45 | debug(`Validating file: ${path}`) |
| 46 | debug(`Options: ${JSON.stringify(options)}`) |
| 47 | await validateDeepnoteFile(path, options) |
| 48 | } catch (error) { |
| 49 | // If validation was already handled (output already produced), just exit |
| 50 | if (error instanceof ValidationHandledError) { |
| 51 | process.exit(error.exitCode) |
| 52 | } |
| 53 | const message = error instanceof Error ? error.message : String(error) |
| 54 | // Use InvalidUsage for file resolution and parse errors (user input), Error for runtime failures |
| 55 | const exitCode = |
| 56 | error instanceof FileResolutionError || error instanceof ParseError ? ExitCode.InvalidUsage : ExitCode.Error |
| 57 | if (options.output === 'json') { |
| 58 | outputJson({ success: false, error: message } satisfies ValidationError) |
| 59 | } else { |
| 60 | logError(message) |
| 61 | } |
| 62 | process.exit(exitCode) |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | async function validateDeepnoteFile(path: string | undefined, options: ValidateOptions): Promise<void> { |
| 68 | const { absolutePath } = await resolvePathToDeepnoteFile(path) |
no test coverage detected