Skip to content

Smithy generates client/server models/index.ts which imports a non-existing model file #802

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

Closed
jhecking opened this issue Jun 30, 2023 · 1 comment

Comments

@jhecking
Copy link
Contributor

We seem to have reach some sort of breakpoint with our Smithy models today, where if we try to add any new structure shape to the models, Smithy generates invalid client/server Typescript code. The problem is that it generates a src/models/index.ts file that imports two ./models_0 and ./models_1 files, but only ./models_0 exists.

As best as I can tell it seems to be some issue with the chunking logic in the SymbolVisitor::ModuleNameDelegator‎ class. Somehow, when we add just one more structure to our models, the writeModelIndex function generates a index file that includes two "namespaces" (models_0 and models_1), whereas the code that actually writes the model files only generates a models_0 file.

codegen output – without the extra structure added to one of the models:

$ yarn codegen
yarn run v1.22.19
$ rm -rf smithy/codegen/build && gradle -p smithy/codegen build
(detected Smithy CLI version 1.27.2)
Found an old version of Smithy CLI that does not support Cli#setStdout
No `aws.api#service` trait found on `borneo#Borneo`
SUCCESS: Validated 2413 shapes (NOTE: 8)
[WARNING] No `aws.api#service` trait found on `borneo#Borneo`
No `aws.api#service` trait found on `borneo#Borneo`
[WARNING] No `aws.api#service` trait found on `borneo#Borneo`
No `aws.api#service` trait found on `borneo#Borneo`
[WARNING] No `aws.api#service` trait found on `borneo#Borneo`
No `aws.api#service` trait found on `borneo#Borneo`
[WARNING] No `aws.api#service` trait found on `borneo#Borneo`
No `aws.api#service` trait found on `borneo#Borneo`
[WARNING] No `aws.api#service` trait found on `borneo#Borneo`
By setting the required member mode to 'strict', a member that has the '@required' trait applied CANNOT be 'undefined'. It will be considered a BACKWARDS INCOMPATIBLE change for Smithy services even when the required constraint is dropped from a member.
[WARNING] By setting the required member mode to 'strict', a member that has the '@required' trait applied CANNOT be 'undefined'. It will be considered a BACKWARDS INCOMPATIBLE change for Smithy services even when the required constraint is dropped from a member.
Model contained SSDK-specific validation events:

Completed projection source (2413 shapes): /path/to/project/smithy/codegen/build/smithyprojections/codegen/source
Smithy built 1 projection(s), 5 plugin(s), and 236 artifacts

> Task :smithyBuildJar
Running smithy build

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
✨  Done in 2.19s.

The only thing that changes in this output is the number of shapes increases from 2413 to 2421.

Trying to build the generated client & server SDKs leads to the same error:

$ yarn --cwd borneo-server build
yarn run v1.22.19
$ concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'
$ tsc -p tsconfig.es.json
$ tsc -p tsconfig.types.json
$ tsc -p tsconfig.cjs.json
[build:types] src/models/index.ts(3,15): error TS2307: Cannot find module './models_1' or its corresponding type declarations.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[build:types] yarn run build:types exited with code 2
[build:es] src/models/index.ts(3,15): error TS2307: Cannot find module './models_1' or its corresponding type declarations.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[build:es] yarn run build:es exited with code 2
[build:cjs] src/models/index.ts(3,15): error TS2307: Cannot find module './models_1' or its corresponding type declarations.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[build:cjs] yarn run build:cjs exited with code 2
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

$ yarn --cwd borneo-client build
yarn run v1.22.19
$ concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'
$ tsc -p tsconfig.cjs.json
$ tsc -p tsconfig.es.json
$ tsc -p tsconfig.types.json
[build:types] src/models/index.ts(3,15): error TS2307: Cannot find module './models_1' or its corresponding type declarations.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[build:types] yarn run build:types exited with code 1
[build:es] src/models/index.ts(3,15): error TS2307: Cannot find module './models_1' or its corresponding type declarations.
[build:cjs] src/models/index.ts(3,15): error TS2307: Cannot find module './models_1' or its corresponding type declarations.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[build:es] yarn run build:es exited with code 2
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[build:cjs] yarn run build:cjs exited with code 2
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Generated code:

$ ls borneo-server/src/models/
index.ts    models_0.ts

$ cat borneo-server/src/models/index.ts
// smithy-typescript generated code
export * from "./models_0";
export * from "./models_1";

Smithy versions used:

$ cat smithy/codegen/gradle.properties
smithyVersion=1.27.2
smithyTypeScriptVersion=0.14.0
smithyGradleVersion=0.6.0

modelsDir=../models
@jhecking
Copy link
Contributor Author

Sorry, please ignore. Seems this has already been addressed in #714 and the fix was included in Smithy Typescript 0.15.0, whereas we are still on version 0.14.0. Should have checked that earlier, before reporting this issue. 🤦‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant