control: add more friendly error message to Switch
This commit is contained in:
parent
2fdec1b697
commit
90ed8f1583
|
@ -25,8 +25,10 @@ class Switch(G[T, V], Type[T]):
|
|||
selector = context.peek(self.default_key) if peek else context.get(self.default_key)
|
||||
else:
|
||||
return to_type(default)
|
||||
if selector not in options and default:
|
||||
return to_type(default)
|
||||
if selector not in options:
|
||||
if default:
|
||||
return to_type(default)
|
||||
raise ValueError(f'selector {selector} not any in options {", ".join(str(o) for o in options)}')
|
||||
return to_type(options[selector])
|
||||
|
||||
def parse(self, context: Context, stream: Stream) -> T:
|
||||
|
|
Loading…
Reference in New Issue