{"id":13532846,"url":"https://github.com/vivek12345/async-await-codemod","last_synced_at":"2025-07-17T17:33:22.885Z","repository":{"id":71399904,"uuid":"168506808","full_name":"vivek12345/async-await-codemod","owner":"vivek12345","description":"Codemod to add try catch to all the async await statements","archived":false,"fork":false,"pushed_at":"2019-02-16T23:08:36.000Z","size":98,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-28T16:04:12.654Z","etag":null,"topics":["async-await","codemod","jscodeshift","recast"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vivek12345.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-31T10:29:14.000Z","updated_at":"2021-10-29T03:52:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"7bfca3fc-c15b-45e2-8ef5-169b3e6cb71f","html_url":"https://github.com/vivek12345/async-await-codemod","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vivek12345/async-await-codemod","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vivek12345%2Fasync-await-codemod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vivek12345%2Fasync-await-codemod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vivek12345%2Fasync-await-codemod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vivek12345%2Fasync-await-codemod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vivek12345","download_url":"https://codeload.github.com/vivek12345/async-await-codemod/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vivek12345%2Fasync-await-codemod/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265636857,"owners_count":23802575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async-await","codemod","jscodeshift","recast"],"created_at":"2024-08-01T07:01:14.233Z","updated_at":"2025-07-17T17:33:22.832Z","avatar_url":"https://github.com/vivek12345.png","language":"JavaScript","funding_links":[],"categories":["ESNext"],"sub_categories":[],"readme":"## ✨ async-await-codemod [![Build Status](https://travis-ci.org/vivek12345/async-await-codemod.svg)](https://travis-ci.org/vivek12345/async-await-codemod)\n\nThis repository contains a codemod script for use with\n[JSCodeshift](https://github.com/facebook/jscodeshift) that help add try catch statements to asyc await calls.\n\n### 🚚 Setup \u0026 Run\n\n1. `yarn global add jscodeshift`\n1. `git clone https://github.com/vivek12345/async-await-codemod.git`\n1. Run `yarn install` in the async-await-codemod directory\n1. `jscodeshift -t \u003ccodemod-script\u003e \u003cpath\u003e`\n   * `codemod-script` - path to the transform file, see available scripts below;\n   * `path` - files or directory to transform;\n   * use the `-d` option for a dry-run and use `-p` to print the output for comparison;\n   * use the `--extensions` option if your files have different extensions than `.js` (for example, `--extensions js,jsx`);\n   * see all available [jscodeshift options](https://github.com/facebook/jscodeshift#usage-cli).\n\n### 📒 Included Script\n\n#### `async-await-with-try-catch`\n\nConverts async await functions like below:-\n\n```javascript\nasync function completeApplicationFlow() {\n  // wait for get session status api to check the status\n  let response;\n  response = await getSessionStatusApi();\n  // wait for getting next set of questions api\n  response = await getNextQuestionsApi();\n  // finally submit application\n  response = await submitApplication();\n}\n\n```\n\nTo the following with try catch statements:-\n\n```javascript\nasync function completeApplicationFlow() {\n  // wait for get session status api to check the status\n  let response;\n  try {\n    response = await getSessionStatusApi();\n  } catch(e) {\n    console.log(e);\n  }\n  // wait for getting next set of questions api\n  try {\n    response = await getNextQuestionsApi();\n  } catch(e) {\n    console.log(e);\n  }\n  // finally submit application\n  try {\n    response = await submitApplication();\n  } catch(e) {\n    console.log(e);\n  }\n}\n\n```\n\n## ⭐ Usage\n\n```sh\njscodeshift -t transforms/async-await-with-try-catch.js \u003cpath\u003e\n```\n\nIf you want to replace the default `console.log(e)` with your custom function call for example `error.handleError(e)`,\nyou can pass that as an option `--catchBlock`\n\n```sh\njscodeshift -t transforms/async-await-with-try-catch.js \u003cpath\u003e --catchBlock=\"error.handleError(e)\"\n```\n\nThis will transform your code to:-\n\n```javascript\nasync function completeApplicationFlow() {\n  // wait for get session status api to check the status\n  let response;\n  try {\n    response = await getSessionStatusApi();\n  } catch(e) {\n    error.handleError(e)\n  }\n  // wait for getting next set of questions api\n  try {\n    response = await getNextQuestionsApi();\n  } catch(e) {\n    error.handleError(e)\n  }\n  // finally submit application\n  try {\n    response = await submitApplication();\n  } catch(e) {\n    error.handleError(e)\n  }\n}\n\n```\n\n\n### Recast Options\n\nOptions to [recast](https://github.com/benjamn/recast)'s printer can be provided\nthrough the `printOptions` command line argument\n\n```sh\njscodeshift -t transform.js \u003cpath\u003e --printOptions='{\"quote\":\"double\"}'\n```\n\n## 👍 Contribute\n\nShow your ❤️ and support by giving a ⭐. Any suggestions and pull request are welcome !\n\n### 📝 License\n\nMIT © [viveknayyar](https://github.com/vivek12345)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvivek12345%2Fasync-await-codemod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvivek12345%2Fasync-await-codemod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvivek12345%2Fasync-await-codemod/lists"}