fix: improve error handling in init command for filesystem operations#741
Open
Nikhil2510192 wants to merge 2 commits into
Open
fix: improve error handling in init command for filesystem operations#741Nikhil2510192 wants to merge 2 commits into
Nikhil2510192 wants to merge 2 commits into
Conversation
Wrap file system operations in try/catch blocks to provide clearer error messages instead of unhandled exceptions. Signed-off-by: jiel <nikhilpagadala2006@gmail.com>
8e9969b to
0f058a7
Compare
There was a problem hiding this comment.
Pull request overview
Improves the init command’s resilience by handling filesystem failures (copy/write) with explicit error reporting instead of letting exceptions crash the CLI.
Changes:
- Wrapped sample asset copy operations (chaincode + gateway) in
try/catchand surfaced failures viathis.error(...). - Wrapped
fablo-config.jsongeneration write intry/catchto provide a clearer failure message on write errors. - Refactored/reformatted
copySampleConfig()for readability while keeping existing flag-driven behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const destination = path.join(process.cwd(), 'chaincodes/chaincode-kv-node'); | ||
| fs.copySync(source, destination); | ||
| if (flags.node) { | ||
| console.log("Creating sample Node.js chaincode"); |
Comment on lines
+101
to
+107
| async copySampleConfig(): Promise<void> { | ||
| let fabloConfigJson = getDefaultFabloConfig(); | ||
| const parsed = await this.parse(Init); | ||
| const flags = this.getEffectiveFlags({ | ||
| options: (parsed.argv ?? []) as string[] | ||
| }); | ||
|
|
Comment on lines
+143
to
+149
| try { | ||
| fs.copySync(source, destination); | ||
| } catch (err) { | ||
| this.error( | ||
| `Failed to copy Node.js chaincode sample: ${(err as Error).message}` | ||
| ); | ||
| } |
| fs.copySync(source, destination); | ||
| } catch (err) { | ||
| this.error( | ||
| `Failed to copy Node.js chaincode sample: ${(err as Error).message}` |
Comment on lines
+110
to
+113
| this.log(chalk.red( | ||
| "Error: ccaas cannot be used together with dev or node" | ||
| )); | ||
| process.exit(1); |
Signed-off-by: jiel <nikhilpagadala2006@gmail.com>
e716925 to
b9e8210
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improve error handling in the init command by wrapping file system operations in try/catch blocks and providing clearer, user-friendly error messages instead of unhandled exceptions.
This ensures failures such as missing permissions, missing source files, or write errors are reported clearly to the user.
Note:
e2e tests fail locally due to Docker/WSL environment setup. Unit tests pass.
Fixes #740