Skip to content

Commit

Permalink
Merge pull request #96 from Raiden1411/error_sets
Browse files Browse the repository at this point in the history
feat: add explicit error sets across the library
  • Loading branch information
Raiden1411 authored Sep 2, 2024
2 parents 1c8064e + bfb429a commit 6ca5af9
Show file tree
Hide file tree
Showing 125 changed files with 4,169 additions and 1,685 deletions.
3 changes: 2 additions & 1 deletion bench/BenchmarkType.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ pub const BenchmarkResult = struct {
};

fn invoke(comptime func: anytype, args: anytype) void {
const ReturnType = @typeInfo(@TypeOf(func)).@"fn".return_type.?;
const ReturnType = @typeInfo(@TypeOf(func)).@"fn".return_type orelse return;

switch (@typeInfo(ReturnType)) {
.error_union => {
const item = @call(.never_inline, func, args) catch {
Expand Down
48 changes: 29 additions & 19 deletions docs/pages/api/abi/abi.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Abitype

Set of possible abi values according to the abi spec.

### Properties

```zig
Expand All @@ -13,6 +15,14 @@ enum {
}
```

## PrepareErrors

Set of possible errors when running `allocPrepare`

```zig
Allocator.Error || error{NoSpaceLeft}
```

## Function

Solidity Abi function representation.
Expand Down Expand Up @@ -62,7 +72,7 @@ comptime know and you want better typesafety from the compiler
### Signature

```zig
pub fn encode(self: @This(), allocator: Allocator, values: anytype) ![]u8
pub fn encode(self: @This(), allocator: Allocator, values: anytype) EncodeErrors![]u8
```

### EncodeOutputs
Expand All @@ -79,7 +89,7 @@ comptime know and you want better typesafety from the compiler
### Signature

```zig
pub fn encodeOutputs(self: @This(), allocator: Allocator, values: anytype) ![]u8
pub fn encodeOutputs(self: @This(), allocator: Allocator, values: anytype) EncodeErrors![]u8
```

### Decode
Expand All @@ -96,7 +106,7 @@ comptime know and you dont want to provided the return type.
### Signature

```zig
pub fn decode(self: @This(), comptime T: type, allocator: Allocator, encoded: []const u8, options: DecodeOptions) !AbiDecoded(T)
pub fn decode(self: @This(), comptime T: type, allocator: Allocator, encoded: []const u8, options: DecodeOptions) DecodeErrors!AbiDecoded(T)
```

### DecodeOutputs
Expand All @@ -113,7 +123,7 @@ comptime know and you dont want to provided the return type.
### Signature

```zig
pub fn decodeOutputs(self: @This(), comptime T: type, allocator: Allocator, encoded: []const u8, options: DecodeOptions) !AbiDecoded(T)
pub fn decodeOutputs(self: @This(), comptime T: type, allocator: Allocator, encoded: []const u8, options: DecodeOptions) DecodeErrors!AbiDecoded(T)
```

### AllocPrepare
Expand All @@ -125,7 +135,7 @@ Caller owns the memory.
### Signature

```zig
pub fn allocPrepare(self: @This(), allocator: Allocator) ![]u8
pub fn allocPrepare(self: @This(), allocator: Allocator) PrepareErrors![]u8
```

### Prepare
Expand All @@ -135,7 +145,7 @@ Intended to use for hashing purposes.
### Signature

```zig
pub fn prepare(self: @This(), writer: anytype) !void
pub fn prepare(self: @This(), writer: anytype) PrepareErrors!void
```

## Event
Expand Down Expand Up @@ -172,7 +182,7 @@ comptime know and you want better typesafety from the compiler
### Signature

```zig
pub fn encode(self: @This(), allocator: Allocator) !Hash
pub fn encode(self: @This(), allocator: Allocator) EncodeErrors!Hash
```

### EncodeLogTopics
Expand All @@ -185,7 +195,7 @@ Caller owns the memory.
### Signature

```zig
pub fn encodeLogTopics(self: @This(), allocator: Allocator, values: anytype) ![]const ?Hash
pub fn encodeLogTopics(self: @This(), allocator: Allocator, values: anytype) EncodeLogsErrors![]const ?Hash
```

### DecodeLogTopics
Expand All @@ -196,7 +206,7 @@ Caller owns the memory.
### Signature

```zig
pub fn decodeLogTopics(self: @This(), comptime T: type, encoded: []const ?Hash, options: LogDecoderOptions) !T
pub fn decodeLogTopics(self: @This(), comptime T: type, encoded: []const ?Hash, options: LogDecoderOptions) LogsDecoderErrors!T
```

### AllocPrepare
Expand All @@ -208,7 +218,7 @@ Caller owns the memory.
### Signature

```zig
pub fn allocPrepare(self: @This(), allocator: Allocator) ![]u8
pub fn allocPrepare(self: @This(), allocator: Allocator) PrepareErrors![]u8
```

### Prepare
Expand All @@ -218,7 +228,7 @@ Intended to use for hashing purposes.
### Signature

```zig
pub fn prepare(self: @This(), writer: anytype) !void
pub fn prepare(self: @This(), writer: anytype) PrepareErrors!void
```

## Error
Expand All @@ -240,7 +250,7 @@ struct {
### Signature

```zig
pub fn deinit(self: @This(), allocator: std.mem.Allocator) void
pub fn deinit(self: @This(), allocator: Allocator) void
```

### Encode
Expand All @@ -256,7 +266,7 @@ comptime know and you want better typesafety from the compiler
### Signature

```zig
pub fn encode(self: @This(), allocator: Allocator, values: anytype) ![]u8
pub fn encode(self: @This(), allocator: Allocator, values: anytype) EncodeErrors![]u8
```

### Decode
Expand All @@ -273,7 +283,7 @@ comptime know and you dont want to provided the return type.
### Signature

```zig
pub fn decode(self: @This(), comptime T: type, allocator: Allocator, encoded: []const u8, options: DecodeOptions) !AbiDecoded(T)
pub fn decode(self: @This(), comptime T: type, allocator: Allocator, encoded: []const u8, options: DecodeOptions) DecodeErrors!AbiDecoded(T)
```

### AllocPrepare
Expand All @@ -285,7 +295,7 @@ Caller owns the memory.
### Signature

```zig
pub fn allocPrepare(self: @This(), allocator: Allocator) ![]u8
pub fn allocPrepare(self: @This(), allocator: Allocator) PrepareErrors![]u8
```

### Prepare
Expand All @@ -295,7 +305,7 @@ Intended to use for hashing purposes.
### Signature

```zig
pub fn prepare(self: @This(), writer: anytype) !void
pub fn prepare(self: @This(), writer: anytype) PrepareErrors!void
```

## Constructor
Expand All @@ -321,7 +331,7 @@ struct {
### Signature

```zig
pub fn deinit(self: @This(), allocator: std.mem.Allocator) void
pub fn deinit(self: @This(), allocator: Allocator) void
```

### Encode
Expand All @@ -337,7 +347,7 @@ comptime know and you want better typesafety from the compiler
### Signature

```zig
pub fn encode(self: @This(), allocator: Allocator, values: anytype) !AbiEncoded
pub fn encode(self: @This(), allocator: Allocator, values: anytype) EncodeErrors!AbiEncoded
```

### Decode
Expand All @@ -354,7 +364,7 @@ comptime know and you dont want to provided the return type.
### Signature

```zig
pub fn decode(self: @This(), comptime T: type, allocator: Allocator, encoded: []const u8, options: DecodeOptions) !AbiDecoded(T)
pub fn decode(self: @This(), comptime T: type, allocator: Allocator, encoded: []const u8, options: DecodeOptions) DecodeErrors!AbiDecoded(T)
```

## Fallback
Expand Down
16 changes: 12 additions & 4 deletions docs/pages/api/abi/abi_parameter.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## PrepareErrors

Set of possible errors when running `allocPrepare`

```zig
Allocator.Error || error{NoSpaceLeft}
```

## AbiParameter

Struct to represent solidity Abi Paramters
Expand Down Expand Up @@ -33,7 +41,7 @@ comptime know and you want better typesafety from the compiler
### Signature

```zig
pub fn encode(self: @This(), allocator: Allocator, values: anytype) ![]u8
pub fn encode(self: @This(), allocator: Allocator, values: anytype) EncodeErrors![]u8
```

### Decode
Expand All @@ -49,7 +57,7 @@ comptime know and you want better typesafety from the compiler
### Signature

```zig
pub fn decode(self: @This(), comptime T: type, allocator: Allocator, encoded: []const u8, options: DecodeOptions) !AbiDecoded(T)
pub fn decode(self: @This(), comptime T: type, allocator: Allocator, encoded: []const u8, options: DecodeOptions) DecoderErrors!AbiDecoded(T)
```

### Prepare
Expand All @@ -59,7 +67,7 @@ Intended to use for hashing purposes.
### Signature

```zig
pub fn prepare(self: @This(), writer: anytype) !void
pub fn prepare(self: @This(), writer: anytype) PrepareErrors!void
```

## AbiEventParameter
Expand Down Expand Up @@ -92,6 +100,6 @@ Intended to use for hashing purposes.
### Signature

```zig
pub fn prepare(self: @This(), writer: anytype) !void
pub fn prepare(self: @This(), writer: anytype) PrepareErrors!void
```

Loading

0 comments on commit 6ca5af9

Please sign in to comment.