Skip to content

fix: improve error handling in init command for filesystem operations#741

Open
Nikhil2510192 wants to merge 2 commits into
hyperledger-labs:mainfrom
Nikhil2510192:fix/init-command-unhandled-fs-errors
Open

fix: improve error handling in init command for filesystem operations#741
Nikhil2510192 wants to merge 2 commits into
hyperledger-labs:mainfrom
Nikhil2510192:fix/init-command-unhandled-fs-errors

Conversation

@Nikhil2510192
Copy link
Copy Markdown

@Nikhil2510192 Nikhil2510192 commented May 5, 2026

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

Copilot AI review requested due to automatic review settings May 5, 2026 19:47
Wrap file system operations in try/catch blocks to provide clearer error messages instead of unhandled exceptions.

Signed-off-by: jiel <nikhilpagadala2006@gmail.com>
@Nikhil2510192 Nikhil2510192 force-pushed the fix/init-command-unhandled-fs-errors branch from 8e9969b to 0f058a7 Compare May 5, 2026 19:50
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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/catch and surfaced failures via this.error(...).
  • Wrapped fablo-config.json generation write in try/catch to 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.

Comment thread src/commands/init/index.ts Outdated
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}`
);
}
Comment thread src/commands/init/index.ts Outdated
fs.copySync(source, destination);
} catch (err) {
this.error(
`Failed to copy Node.js chaincode sample: ${(err as Error).message}`
Comment thread src/commands/init/index.ts Outdated
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>
@Nikhil2510192 Nikhil2510192 force-pushed the fix/init-command-unhandled-fs-errors branch from e716925 to b9e8210 Compare May 5, 2026 20:04
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

Successfully merging this pull request may close these issues.

Bug: fablo init crashes with unhandled exception on file system errors

2 participants