WebAssembly / WebAssembly/component-model
Variant extensions
Nobody has claimed this yet.
- Dominant language
- WebAssembly
- Stars
- 1.4k
- Forks
- 130
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 15
Description
Another "nice to have" as opposed to being anything particularly crucial. I was considering use of variants as error types, as it seems like the best option to have fine-grained error information as a sort of best practice. Then there might then be some generic base-level errors which are extended by function-specific error handlers.
At a WIT-convenience level it might be useful to support this via variant extensions:
variant base-error {
unknown-error(string),
internal-host-error(string),
validation-error(tuple<string, string>),
rate-limit-error(tuple<u32, string>)
}
variant create-error extends base-error {
invalid-param(tuple<string, string>),
already-exists(string),
no-backend(tuple<string, u32>)
}
func create(param: string) -> result<_, create-error>
variant update-error extends base-error {
update-error(tuple<string, string>)
}
func update(param: string, val: string) -> result<_, update-error>
Similarly, enum extensions might be useful.
Some use cases to think through, just posting as a placeholder for now.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the issue's proposed WIT examples for variant extensions and the related note about enum extensions. Work through how base and function-specific error variants would compose, including result types and error handlers. Done would require a decided design and specified use cases, but this placeholder names no files, tests, or implementation entry point.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- wasm
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100