Skip to content

Commit

Permalink
Revert "refactor(store): errors at file-level (#2311)" (#2338)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Feb 28, 2024
1 parent 2e288aa commit 771fa4a
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 117 deletions.
5 changes: 0 additions & 5 deletions .changeset/pink-pandas-fetch.md

This file was deleted.

74 changes: 28 additions & 46 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)
[IStoreData](/store/reference/store#istoredata), [IStoreRegistration](/store/reference/store#istoreregistration), [IStoreErrors](/store/reference/store#istoreerrors)

## IStoreEvents

Expand Down Expand Up @@ -96,100 +96,82 @@ 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. |

## Store_IndexOutOfBounds
## IStoreErrors

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

### Errors

#### Store_TableAlreadyExists

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

## Store_InvalidBounds

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

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

## Store_InvalidFieldNamesLength

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

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

## Store_InvalidKeyNamesLength

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

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

## Store_InvalidResourceType

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

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

## Store_InvalidSplice

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

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

## Store_InvalidStaticDataLength

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

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

## Store_InvalidValueSchemaDynamicLength

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

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

## Store_InvalidValueSchemaLength

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

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

## Store_InvalidValueSchemaStaticLength

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

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

## Store_TableAlreadyExists

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

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

## Store_TableNotFound

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

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

## IStoreData
Expand Down
74 changes: 74 additions & 0 deletions docs/pages/world/reference/world-external.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,80 @@ 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 { Store_IndexOutOfBounds } from "@latticexyz/store/src/errors.sol";
import { IStoreErrors } from "@latticexyz/store/src/IStoreErrors.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(Store_IndexOutOfBounds.selector, 4, 4));
vm.expectRevert(abi.encodeWithSelector(IStoreErrors.Store_IndexOutOfBounds.selector, 4, 4));
assertEq(Singleton.getItemV4(1), 0);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/store/src/IStore.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// 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 {}
interface IStore is IStoreData, IStoreRegistration, IStoreErrors {}
21 changes: 21 additions & 0 deletions packages/store/src/IStoreErrors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import { ResourceId } from "./ResourceId.sol";

interface IStoreErrors {
// Errors include a stringified version of the tableId for easier debugging if cleartext tableIds are used
error Store_TableAlreadyExists(ResourceId tableId, string tableIdString);
error Store_TableNotFound(ResourceId tableId, string tableIdString);
error Store_InvalidResourceType(bytes2 expected, ResourceId resourceId, string resourceIdString);

error Store_InvalidStaticDataLength(uint256 expected, uint256 received);
error Store_InvalidBounds(uint256 start, uint256 end);
error Store_IndexOutOfBounds(uint256 length, uint256 accessedIndex);
error Store_InvalidKeyNamesLength(uint256 expected, uint256 received);
error Store_InvalidFieldNamesLength(uint256 expected, uint256 received);
error Store_InvalidValueSchemaLength(uint256 expected, uint256 received);
error Store_InvalidValueSchemaStaticLength(uint256 expected, uint256 received);
error Store_InvalidValueSchemaDynamicLength(uint256 expected, uint256 received);
error Store_InvalidSplice(uint40 startWithinField, uint40 deleteCount, uint40 fieldLength);
}
Loading

0 comments on commit 771fa4a

Please sign in to comment.