-
Notifications
You must be signed in to change notification settings - Fork 84
fix: Handle uncaught exception in create-amplify #2828
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'create-amplify': patch | ||
'@aws-amplify/cli-core': patch | ||
'@aws-amplify/backend-cli': patch | ||
--- | ||
|
||
Handle uncaught exception in create-amplify and refactor the error handler to cli-core |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,37 +8,41 @@ | |
*/ | ||
|
||
import { | ||
LogLevel, | ||
PackageManagerControllerFactory, | ||
attachUnhandledExceptionListeners, | ||
format, | ||
printer, | ||
generateCommandFailureHandler, | ||
} from '@aws-amplify/cli-core'; | ||
import { ProjectRootValidator } from './project_root_validator.js'; | ||
import { AmplifyProjectCreator } from './amplify_project_creator.js'; | ||
import { getProjectRoot } from './get_project_root.js'; | ||
import { GitIgnoreInitializer } from './gitignore_initializer.js'; | ||
import { InitialProjectFileGenerator } from './initial_project_file_generator.js'; | ||
|
||
const projectRoot = await getProjectRoot(); | ||
attachUnhandledExceptionListeners(); | ||
const errorHandler = generateCommandFailureHandler(); | ||
|
||
const packageManagerControllerFactory = new PackageManagerControllerFactory( | ||
projectRoot, | ||
); | ||
try { | ||
const projectRoot = await getProjectRoot(); | ||
|
||
const packageManagerController = | ||
packageManagerControllerFactory.getPackageManagerController(); | ||
const packageManagerControllerFactory = new PackageManagerControllerFactory( | ||
projectRoot, | ||
); | ||
|
||
const amplifyProjectCreator = new AmplifyProjectCreator( | ||
projectRoot, | ||
packageManagerController, | ||
new ProjectRootValidator(projectRoot), | ||
new GitIgnoreInitializer(projectRoot), | ||
new InitialProjectFileGenerator(projectRoot, packageManagerController), | ||
); | ||
const packageManagerController = | ||
packageManagerControllerFactory.getPackageManagerController(); | ||
|
||
const amplifyProjectCreator = new AmplifyProjectCreator( | ||
projectRoot, | ||
packageManagerController, | ||
new ProjectRootValidator(projectRoot), | ||
new GitIgnoreInitializer(projectRoot), | ||
new InitialProjectFileGenerator(projectRoot, packageManagerController), | ||
); | ||
|
||
try { | ||
await amplifyProjectCreator.create(); | ||
} catch (err) { | ||
printer.log(format.error(err), LogLevel.ERROR); | ||
process.exitCode = 1; | ||
if (err instanceof Error) { | ||
await errorHandler(format.error(err), err); | ||
} | ||
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this implementation we'll be blind to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgive my ignorance as I'm new to the code base, but isn't that handled by the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. once You can assert this by adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha, I see that now thanks! I took a look around and it looks like largely, the downstream instances will wrap the non- So I could keep the original code that was here alongisde the handling of Error like so:
which shows up like so:
Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do wonder if we can just remove the try-catch from here and just let it bubble up to "UnhandledExceptionListener" that we also introduce in this PR. It's implementation seems to be dealing with non-Errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Amplifiyer might have some ideas here as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it looks like removing the try-catch and solely using the UnhandledExceptionListener doesn't work the same as what you wanted for the
Becase it's a non- |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some of these are incorrect if we're touching public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be more accurate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the right mix.