From fbba9c7a843bc4d69b7adf015f04e548d11f0a3b Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Wed, 30 Mar 2022 15:01:14 -0700 Subject: [PATCH] chore: throw more descriptive error when failing to create output directory (#18296) I passed a `--output` to the CDK that was `/public/something/or/other`, on a system with no `/public`, and then forgot about it. I was presented with the head-scratch-inducing failure message: ``` ENOENT: no such file or directory, mkdir '/public' Error: ENOENT: no such file or directory, mkdir '/public' ``` This should improve the error so that some reference is made to why the CDK expects or desires this path to exist (and remind me that in fact I told it to go there). ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/aws-cdk/lib/api/cxapp/exec.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk/lib/api/cxapp/exec.ts b/packages/aws-cdk/lib/api/cxapp/exec.ts index bcc298deaeea2..34fae3c59c4c6 100644 --- a/packages/aws-cdk/lib/api/cxapp/exec.ts +++ b/packages/aws-cdk/lib/api/cxapp/exec.ts @@ -68,7 +68,11 @@ export async function execProgram(aws: SdkProvider, config: Configuration): Prom if (!outdir) { throw new Error('unexpected: --output is required'); } - await fs.mkdirp(outdir); + try { + await fs.mkdirp(outdir); + } catch (error) { + throw new Error(`Could not create output directory ${outdir} (${error.message})`); + } debug('outdir:', outdir); env[cxapi.OUTDIR_ENV] = outdir;