oasisprotocol / oasisprotocol/oasis-core

tiny nit: default case for an exhaustive switch should generate a severe log entry (and possibly panic on non-production builds)

Open
#2,162 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
369
Forks
151
Avg merge
1d 3h
Merged PRs (30d)
6

Description

Description of the bug

tiny nit re making it harder to introduce errors later.

default case for a switch that is intended to be exhaustive should log and/or panic. i.e., emulate C/C++ -Wswitch -Wswitch-enum behavior

https://github.com/oasislabs/ekiden/blob/221f43394d4469bd71ab72302feec15f67c0944e/go/tendermint/api/api.go#L59

Steps to reproduce

Expected behavior

If a future code change introduces a new enum (what the const CodeXXX is emulating) but forgets to update the String() method for Code values, we would detect it quickly in tests (where hopefully a new high-severity log entry would be noticed) or in a dev environment (panics). Not sure if golang builds permit prod vs debug builds, so panics might be too scary.

Environment

  • OS:
  • Versions of relevant software and tools:

Additional information
Anything else you think would be useful; including context and suggested fixes.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at go/tendermint/api/api.go around line 59 and inspect the switch used by Code.String(). Determine how exhaustive enum handling should report an unexpected value, including whether production and non-production builds need different behavior. Done means future unmapped Code values produce the agreed severe log entry or panic behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.