hyperledger-labs / hyperledger-labs/fablo

fix: incorrect error messages and exit codes across CLI and generated scripts

Open
#758 3 comments 0 reactions 0 assignees View on GitHub
agent
Dominant language
Shell
Stars
238
Forks
113
Avg merge
3d 20h
Merged PRs (30d)
10

Description

## Summary

Found a few places in Fablo where the error output is either misleading or outright wrong. All small fixes, grouping them here to avoid noise.

## Findings

### 1. Raft validation error prints raw function source code

**File:** `src/commands/validate/index.ts` line 325

`config.versionsSupportingRaft` is a `(v: string) => boolean` function. String interpolation prints its source code directly instead of a human-readable version string.

**Before:**
```
Fabric's 1.4.0 does not support Raft consensus type. Supporting versions are: (v) => version(v).isGreaterOrEqual("1.4.3")
```

**After:**
```
Fabric's 1.4.0 does not support Raft consensus type. Raft is supported from Fabric 1.4.3 and above.
```

---

### 2. Parse errors discard position details

**File:** `src/utils/parseFabloConfig.ts` line 12

When a config file has a syntax error, the original JSON/YAML error containing the line number and position is discarded and replaced with a generic message. Users get no guidance on where the error is.

**Before:**
```
Cannot parse file neither as JSON nor YAML file.
```

**After:**
```
Cannot parse config file.
JSON error: Unexpected token } in JSON at position 42
YAML error: unexpected end of the stream within a flow collection at line 3
```

---

### 3. Chaincode invoke error says "chaincode list"

**File:** `src/setup-docker/templates/fabric-docker/chaincode-scripts.sh` line 30

Copy-paste error from the `chaincodeList` function above it.

**Before:**
```
Expected 4 or 5 parameters for chaincode list, but got: $*
```

**After:**
```
Expected 4 or 5 parameters for chaincode invoke, but got: $*
```

---

### 4. Unknown command exits with code 0

**File:** `src/setup-docker/templates/fabric-docker.sh` lines 62–68

When an unknown command is passed, Fablo prints a help message but exits with code 0. This means CI/CD pipelines cannot detect invalid commands via exit code.

**Before:**
```bash
else
echo "No command specified"
echo "Basic commands are: up, down, start, stop, reset"
echo "To list channel query helper commands type: 'fablo channel --help'"
echo "Also check: 'chaincode install'"
echo "Use 'help' or '--help' for more information"
fi
```

**After:**
```bash
else
echo "No command specified"
echo "Basic commands are: up, down, start, stop, reset"
echo "To list channel query helper commands type: 'fablo channel --help'"
echo "Also check: 'chaincode install'"
echo "Use 'help' or '--help' for more information"
exit 1
fi
```

## Fix Complexity

All four are low complexity, one or two line changes each.

Happy to open a PR for these if it looks good.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.