canopy-network/canopy · error · ValueError
Invalid chain_id: {self.chain_id}
Error message
Invalid chain_id: {self.chain_id} What it means
The plugin Config dataclass validates itself in __post_init__: chain_id must be an int >= 1 and data_dir_path a non-empty string. If chain_id is not an int or is less than 1, Config construction raises ValueError(f"Invalid chain_id: {self.chain_id}"), preventing the plugin from starting with an invalid chain identity.
Source
Thrown at plugin/python/contract/plugin.py:61
# Socket path name (matching Go)
SOCKET_PATH = "plugin.sock"
# PLUGIN_BUILD is a human-readable build marker logged at startup so operators can confirm, via
# `tail -f /tmp/plugin/python-plugin.log`, that the running binary includes the expected features.
PLUGIN_BUILD = "python-plugin v1 (base SDK + detached custom RPC query path)"
@dataclass
class Config:
"""Plugin configuration matching Go's Config struct."""
chain_id: int = 1
data_dir_path: str = "/tmp/plugin/"
# rpc_address is the listen address for the plugin's own HTTP server that exposes custom RPC endpoints
rpc_address: str = "0.0.0.0:50010"
def __post_init__(self) -> None:
if not isinstance(self.chain_id, int) or self.chain_id < 1:
raise ValueError(f"Invalid chain_id: {self.chain_id}")
if not isinstance(self.data_dir_path, str) or not self.data_dir_path.strip():
raise ValueError(f"Invalid data_dir_path: {self.data_dir_path}")
def default_config() -> Config:
"""Return the default configuration (matching Go's DefaultConfig)."""
return Config(chain_id=1, data_dir_path="/tmp/plugin/", rpc_address="0.0.0.0:50010")
def new_config_from_file(filepath: str) -> Config:
"""Load configuration from JSON file (matching Go's NewConfigFromFile)."""
try:
config_data = json.loads(Path(filepath).read_text(encoding="utf-8"))
return Config(
chain_id=config_data.get("chainId", 1),
data_dir_path=config_data.get("dataDirPath", "/tmp/plugin/"),
rpc_address=config_data.get("rpcAddress", "0.0.0.0:50010"),
)View on GitHub (pinned to ee8197d91d)
Solutions
- Set ChainId to a positive integer (>= 1) in chain.json / the Config constructor, and restart the plugin.
- If your config layer yields strings, convert with int(raw) before constructing Config, and handle non-numeric input explicitly.
- Check the config-loading code for a missing-field default that injects None/0, and make ChainId required at parse time.
- Add a pre-flight check of parsed config values (isinstance int, >= 1) with a clear message before starting the plugin.
Example fix
// before Config(chain_id=str(cfg['ChainId'])) # ValueError // after Config(chain_id=int(cfg['ChainId'])) # e.g. 1
Defensive patterns
Strategy: validation
Validate before calling
raw = cfg.get('ChainId')
chain_id = int(raw) if isinstance(raw, str) and raw.isdigit() else raw
if not isinstance(chain_id, int) or chain_id < 1:
raise ValueError(f'ChainId must be a positive integer, got: {raw!r}')
config = Config(chain_id=chain_id) Type guard
def is_valid_chain_id(v) -> bool:
return isinstance(v, int) and not isinstance(v, bool) and v >= 1 Try / catch
try:
config = Config(chain_id=cfg['ChainId'], data_dir_path=cfg['DataDirPath'])
except ValueError as e:
logger.error('invalid plugin config: %s', e)
sys.exit(1) Prevention
- Always set ChainId as a positive integer in chain.json.
- Convert string config values to int at parse time.
- Validate the whole parsed config before constructing Config.
- Cover Config validation with unit tests for 0, negative, string, and None values.
When it happens
Trigger: Constructing Config(chain_id=0), a negative value, a string like '1' from parsed JSON config, or None when chain.json's ChainId field is missing or of the wrong type.
Common situations: chain.json missing the ChainId field so it defaults/parse to None; a config loader passing strings without conversion; hand-editing chain.json and setting ChainId to 0 or a quoted value.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Item too long: {len(item)} bytes (max 255)
- Invalid uint64 value: {value}
- Message does not support serialization
- Message type does not support deserialization
- 1
AI-assisted analysis of canopy-network/canopy@ee8197d91d (2026-09-06).
Data as JSON: /api/errors/ce312bb532714ba7.
Report an issue: GitHub.