Skip to content

Commit

Permalink
refactor(store): errors at file-level (#2311)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <[email protected]>
  • Loading branch information
yonadaaa and holic authored Feb 28, 2024
1 parent 8f49c27 commit ad0c5ad
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 193 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-pandas-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store": major
---

Moved Solidity custom errors (e.g. `Store_TableNotFound`) from `IStoreErrors` interface to file-level errors in `errors.sol`. If you were using these errors before, you may need to update your imports.
74 changes: 46 additions & 28 deletions docs/pages/store/reference/store.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/IStore.sol)

**Inherits:**
[IStoreData](/store/reference/store#istoredata), [IStoreRegistration](/store/reference/store#istoreregistration), [IStoreErrors](/store/reference/store#istoreerrors)
[IStoreData](/store/reference/store#istoredata), [IStoreRegistration](/store/reference/store#istoreregistration)

## IStoreEvents

Expand Down Expand Up @@ -96,82 +96,100 @@ event Store_DeleteRecord(ResourceId indexed tableId, bytes32[] keyTuple);
| `tableId` | `ResourceId` | The ID of the table where the record is deleted. |
| `keyTuple` | `bytes32[]` | An array representing the composite key for the record. |

## IStoreErrors
## Store_IndexOutOfBounds

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/IStoreErrors.sol)

### Errors

#### Store_TableAlreadyExists
[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol)

```solidity
error Store_TableAlreadyExists(ResourceId tableId, string tableIdString);
error Store_IndexOutOfBounds(uint256 length, uint256 accessedIndex);
```

#### Store_TableNotFound
## Store_InvalidBounds

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol)

```solidity
error Store_TableNotFound(ResourceId tableId, string tableIdString);
error Store_InvalidBounds(uint256 start, uint256 end);
```

#### Store_InvalidResourceType
## Store_InvalidFieldNamesLength

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol)

```solidity
error Store_InvalidResourceType(bytes2 expected, ResourceId resourceId, string resourceIdString);
error Store_InvalidFieldNamesLength(uint256 expected, uint256 received);
```

#### Store_InvalidStaticDataLength
## Store_InvalidKeyNamesLength

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol)

```solidity
error Store_InvalidStaticDataLength(uint256 expected, uint256 received);
error Store_InvalidKeyNamesLength(uint256 expected, uint256 received);
```

#### Store_InvalidBounds
## Store_InvalidResourceType

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol)

```solidity
error Store_InvalidBounds(uint256 start, uint256 end);
error Store_InvalidResourceType(bytes2 expected, ResourceId resourceId, string resourceIdString);
```

#### Store_IndexOutOfBounds
## Store_InvalidSplice

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol)

```solidity
error Store_IndexOutOfBounds(uint256 length, uint256 accessedIndex);
error Store_InvalidSplice(uint40 startWithinField, uint40 deleteCount, uint40 fieldLength);
```

#### Store_InvalidKeyNamesLength
## Store_InvalidStaticDataLength

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol)

```solidity
error Store_InvalidKeyNamesLength(uint256 expected, uint256 received);
error Store_InvalidStaticDataLength(uint256 expected, uint256 received);
```

#### Store_InvalidFieldNamesLength
## Store_InvalidValueSchemaDynamicLength

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol)

```solidity
error Store_InvalidFieldNamesLength(uint256 expected, uint256 received);
error Store_InvalidValueSchemaDynamicLength(uint256 expected, uint256 received);
```

#### Store_InvalidValueSchemaLength
## Store_InvalidValueSchemaLength

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol)

```solidity
error Store_InvalidValueSchemaLength(uint256 expected, uint256 received);
```

#### Store_InvalidValueSchemaStaticLength
## Store_InvalidValueSchemaStaticLength

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol)

```solidity
error Store_InvalidValueSchemaStaticLength(uint256 expected, uint256 received);
```

#### Store_InvalidValueSchemaDynamicLength
## Store_TableAlreadyExists

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol)

```solidity
error Store_InvalidValueSchemaDynamicLength(uint256 expected, uint256 received);
error Store_TableAlreadyExists(ResourceId tableId, string tableIdString);
```

#### Store_InvalidSplice
## Store_TableNotFound

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol)

```solidity
error Store_InvalidSplice(uint40 startWithinField, uint40 deleteCount, uint40 fieldLength);
error Store_TableNotFound(ResourceId tableId, string tableIdString);
```

## IStoreData
Expand Down
74 changes: 0 additions & 74 deletions docs/pages/world/reference/world-external.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -451,80 +451,6 @@ function unregisterNamespaceDelegation(ResourceId namespaceId) public onlyDelega
| ------------- | ------------ | ----------------------- |
| `namespaceId` | `ResourceId` | The ID of the namespace |

### Errors

#### Store_TableAlreadyExists

```solidity
error Store_TableAlreadyExists(ResourceId tableId, string tableIdString);
```

#### Store_TableNotFound

```solidity
error Store_TableNotFound(ResourceId tableId, string tableIdString);
```

#### Store_InvalidResourceType

```solidity
error Store_InvalidResourceType(bytes2 expected, ResourceId resourceId, string resourceIdString);
```

#### Store_InvalidStaticDataLength

```solidity
error Store_InvalidStaticDataLength(uint256 expected, uint256 received);
```

#### Store_InvalidBounds

```solidity
error Store_InvalidBounds(uint256 start, uint256 end);
```

#### Store_IndexOutOfBounds

```solidity
error Store_IndexOutOfBounds(uint256 length, uint256 accessedIndex);
```

#### Store_InvalidKeyNamesLength

```solidity
error Store_InvalidKeyNamesLength(uint256 expected, uint256 received);
```

#### Store_InvalidFieldNamesLength

```solidity
error Store_InvalidFieldNamesLength(uint256 expected, uint256 received);
```

#### Store_InvalidValueSchemaLength

```solidity
error Store_InvalidValueSchemaLength(uint256 expected, uint256 received);
```

#### Store_InvalidValueSchemaStaticLength

```solidity
error Store_InvalidValueSchemaStaticLength(uint256 expected, uint256 received);
```

#### Store_InvalidValueSchemaDynamicLength

```solidity
error Store_InvalidValueSchemaDynamicLength(uint256 expected, uint256 received);
```

#### Store_InvalidSplice

```solidity
error Store_InvalidSplice(uint40 startWithinField, uint40 deleteCount, uint40 fieldLength);
```

## IWorldCall

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/world/src/IWorldKernel.sol)
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/contracts/test/Tablegen.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.8.24;

import "forge-std/Test.sol";
import { StoreMock } from "@latticexyz/store/test/StoreMock.sol";
import { IStoreErrors } from "@latticexyz/store/src/IStoreErrors.sol";
import { Store_IndexOutOfBounds } from "@latticexyz/store/src/errors.sol";

import { Statics, StaticsData, Dynamics1, Dynamics1Data, Dynamics2, Dynamics2Data, Singleton, Offchain, UserTyped, UserTypedData } from "../src/codegen/index.sol";
import { TestTypeAddress, TestTypeInt64, TestTypeLibrary } from "../src/types.sol";
Expand Down Expand Up @@ -143,7 +143,7 @@ contract TablegenTest is Test, StoreMock {
assertEq(abi.encode(Singleton.getV4()), abi.encode([uint32(5)]));
assertEq(Singleton.lengthV4(), 1);
assertEq(Singleton.getItemV4(0), 5);
vm.expectRevert(abi.encodeWithSelector(IStoreErrors.Store_IndexOutOfBounds.selector, 4, 4));
vm.expectRevert(abi.encodeWithSelector(Store_IndexOutOfBounds.selector, 4, 4));
assertEq(Singleton.getItemV4(1), 0);
}

Expand Down
3 changes: 1 addition & 2 deletions packages/store/src/IStore.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import { IStoreErrors } from "./IStoreErrors.sol";
import { IStoreData } from "./IStoreData.sol";
import { IStoreRegistration } from "./IStoreRegistration.sol";

interface IStore is IStoreData, IStoreRegistration, IStoreErrors {}
interface IStore is IStoreData, IStoreRegistration {}
21 changes: 0 additions & 21 deletions packages/store/src/IStoreErrors.sol

This file was deleted.

Loading

0 comments on commit ad0c5ad

Please sign in to comment.