WebAssembly / WebAssembly/component-model

Variant extensions

Open
#136 2 comments 0 reactions 0 assignees View on GitHub

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

  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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.