Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CDK errors not being logged #211

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/alb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
"constructs": "10.3.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/api-websocket-lambda-dynamodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@aws-sdk/client-dynamodb": "^3.632.0",
"@aws-sdk/lib-dynamodb": "^3.632.0",
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/apprunner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
"constructs": "10.3.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/appsvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
"constructs": "10.3.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/cloudfront-lambda-urls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"@types/aws-lambda": "^8.10.145",
Expand Down
2 changes: 1 addition & 1 deletion examples/cron-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
"constructs": "10.3.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/ec2-instance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
"constructs": "10.3.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/ecscluster/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
"constructs": "10.3.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/eventbridge-atm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@aws-sdk/client-eventbridge": "^3.678.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"@types/aws-lambda": "^8.10.145",
Expand Down
2 changes: 1 addition & 1 deletion examples/eventbridge-sns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@aws-sdk/client-eventbridge": "^3.678.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/fargate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
"constructs": "10.3.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/lookups/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"@types/node": "^10.0.0"
},
"dependencies": {
"@pulumi/aws-native": "^1.0.2",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/aws": "^6.0.0",
"@pulumi/cdk": "^0.5.0",
"aws-cdk-lib": "2.156.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/s3-object-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/cdk": "^0.5.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
"constructs": "10.3.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/scalable-webhook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@aws-sdk/client-dynamodb": "^3.679.0",
"@aws-sdk/client-eventbridge": "^3.678.0",
"@aws-sdk/client-sqs": "^3.679.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"@types/aws-lambda": "^8.10.145",
Expand Down
2 changes: 1 addition & 1 deletion examples/the-big-fan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
Expand Down
2 changes: 1 addition & 1 deletion integration/apigateway-domain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
Expand Down
2 changes: 1 addition & 1 deletion integration/apigateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
Expand Down
2 changes: 1 addition & 1 deletion integration/cloudfront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.5.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
Expand Down
2 changes: 1 addition & 1 deletion integration/ec2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.6.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
Expand Down
3 changes: 3 additions & 0 deletions integration/errors-test/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: pulumi-aws-errors
runtime: nodejs
description: errors integration test
23 changes: 23 additions & 0 deletions integration/errors-test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as aws from '@pulumi/aws';
import * as iam from 'aws-cdk-lib/aws-iam';
import * as events from 'aws-cdk-lib/aws-events';
import * as pulumicdk from '@pulumi/cdk';

class ErrorsStack extends pulumicdk.Stack {
constructor(app: pulumicdk.App, id: string, options?: pulumicdk.StackOptions) {
super(app, id, options);
const eventBus = new events.EventBus(this, 'testbus');
// This will fail because the `sid` property is required
eventBus.addToResourcePolicy(
new iam.PolicyStatement({
actions: ['events:PutEvents'],
principals: [new iam.AccountRootPrincipal()],
resources: [eventBus.eventBusArn],
}),
);
}
}

new pulumicdk.App('app', (scope: pulumicdk.App) => {
new ErrorsStack(scope, 'teststack');
});
15 changes: 15 additions & 0 deletions integration/errors-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "pulumi-aws-cdk",
"devDependencies": {
"@types/node": "^10.0.0"
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.149.0",
"constructs": "10.3.0",
"esbuild": "^0.24.0"
}
}
18 changes: 18 additions & 0 deletions integration/errors-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"strict": true,
"outDir": "bin",
"target": "es2019",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"./*.ts"
]
}
14 changes: 14 additions & 0 deletions integration/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package examples

import (
"bytes"
"path/filepath"
"testing"

Expand Down Expand Up @@ -118,6 +119,19 @@ func TestCloudFront(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestErrors(t *testing.T) {
var buf bytes.Buffer
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: filepath.Join(getCwd(t), "errors-test"),
Stderr: &buf,
ExpectFailure: true,
})

integration.ProgramTest(t, &test)
assert.Containsf(t, buf.String(), "Error: Event Bus policy statements must have a sid", "Expected error message not found in pulumi up output")
}

func getJSBaseOptions(t *testing.T) integration.ProgramTestOptions {
base := getBaseOptions(t)
baseJS := base.With(integration.ProgramTestOptions{
Expand Down
2 changes: 1 addition & 1 deletion integration/kms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.5.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
Expand Down
2 changes: 1 addition & 1 deletion integration/logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.5.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.149.0",
Expand Down
2 changes: 1 addition & 1 deletion integration/misc-services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.5.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.149.0",
Expand Down
2 changes: 1 addition & 1 deletion integration/route53/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.0.0",
"@pulumi/aws-native": "^1.5.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.156.0",
Expand Down
2 changes: 1 addition & 1 deletion integration/secretsmanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@pulumi/aws": "^6.56.0",
"@pulumi/aws-native": "^1.5.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/cdk": "^0.5.0",
"@pulumi/pulumi": "^3.0.0",
"aws-cdk-lib": "2.149.0",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@aws-cdk/aws-apprunner-alpha": "2.20.0-alpha.0",
"@pulumi/aws": "^6.56.0",
"@pulumi/aws-native": "^1.6.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/docker": "^4.5.0",
"@pulumi/pulumi": "3.136.0",
"@types/archiver": "^6.0.2",
Expand All @@ -51,7 +51,7 @@
},
"peerDependencies": {
"@pulumi/aws": "^6.56.0",
"@pulumi/aws-native": "^1.6.0",
"@pulumi/aws-native": "^1.7.0",
"@pulumi/docker": "^4.5.0",
"@pulumi/pulumi": "^3.136.0",
"aws-cdk-lib": "^2.20.0",
Expand Down
7 changes: 2 additions & 5 deletions src/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { AppComponent, AppOptions, AppResourceOptions } from './types';
import { AppConverter, StackConverter } from './converters/app-converter';
import { PulumiSynthesizer, PulumiSynthesizerBase } from './synthesizer';
import { AwsCdkCli, ICloudAssemblyDirectoryProducer } from '@aws-cdk/cli-lib-alpha';
import { error } from '@pulumi/pulumi/log';
import { CdkConstruct } from './interop';

export type AppOutputs = { [outputId: string]: pulumi.Output<any> };
Expand Down Expand Up @@ -152,15 +151,13 @@ export class App
const message = e.message as string;
const messageParts = message.split('Context lookups have been disabled. ');
const missingParts = messageParts[1].split('Missing context keys: ');
error(
throw new Error(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a control flow difference between before vs after. Before, the error command did not terminate the control flow. After, throw terminates the control flow. Which one we want here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to throw. These errors that are thrown by CDK are fatal errors that prevent synthesis from completing. If we don't terminate here we end up with a very unhelpful error about not being able to read the cloud assembly.

'Context lookups have been disabled. Make sure all necessary context is already in "cdk.context.json". \n' +
'Missing context keys: ' +
missingParts[1],
this,
);
} else {
error(e, this);
}
throw e;
}

const converter = new AppConverter(this);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1037,10 +1037,10 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==

"@pulumi/aws-native@^1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@pulumi/aws-native/-/aws-native-1.6.0.tgz#8947829fb7fdcef8ce62fe43082b668068281101"
integrity sha512-7b6CVr8XoprdQCWCnmPDhHe+BGHN2LSk+qpeELp8M2YjcwEu2XkFhI7bAj2UjQLcD84HwPM07baM5f2uryrZxA==
"@pulumi/aws-native@^1.7.0":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@pulumi/aws-native/-/aws-native-1.7.0.tgz#50f2dec9f97780c22781b1ff419e394b6fffbbb6"
integrity sha512-UDz/TSJPCaez955LoVtCtS3PRfWK4rmUav/Mel697aHPWNSU7u+OnCSyzXsK92gm/wem9ZuncuG57XzhwNUWiA==
dependencies:
"@pulumi/pulumi" "^3.136.0"

Expand Down
Loading