Skip to content

Commit bd6f0d1

Browse files
authored
Merge pull request #236 from ardriveapp/PE-6152-catch-gql-errors-in-response
chore: release 2.0.3
2 parents 0958c8f + b67ced3 commit bd6f0d1

File tree

8 files changed

+91
-292
lines changed

8 files changed

+91
-292
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ardrive-core-js",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"description": "ArDrive Core contains the essential back end application features to support the ArDrive CLI and Desktop apps, such as file management, Permaweb upload/download, wallet management and other common functions.",
55
"main": "./lib/exports.js",
66
"types": "./lib/exports.d.ts",

src/ardrive.ts

Lines changed: 25 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ export class ArDrive extends ArDriveAnonymous {
179179
public async movePublicFile({ fileId, newParentFolderId }: MovePublicFileParams): Promise<ArFSResult> {
180180
const destFolderDriveId = await this.arFsDao.getDriveIdForFolderId(newParentFolderId);
181181

182-
const owner = await this.getOwnerForDriveId(destFolderDriveId);
183-
await this.assertOwnerAddress(owner);
184-
182+
const owner = await this.wallet.getAddress();
185183
const originalFileMetaData = await this.getPublicFile({ fileId });
186184

187185
if (!destFolderDriveId.equals(originalFileMetaData.driveId)) {
@@ -256,9 +254,7 @@ export class ArDrive extends ArDriveAnonymous {
256254
public async movePrivateFile({ fileId, newParentFolderId, driveKey }: MovePrivateFileParams): Promise<ArFSResult> {
257255
const destFolderDriveId = await this.arFsDao.getDriveIdForFolderId(newParentFolderId);
258256

259-
const owner = await this.getOwnerForDriveId(destFolderDriveId);
260-
await this.assertOwnerAddress(owner);
261-
257+
const owner = await this.wallet.getAddress();
262258
const originalFileMetaData = await this.getPrivateFile({ fileId, driveKey });
263259

264260
if (!destFolderDriveId.equals(originalFileMetaData.driveId)) {
@@ -345,9 +341,7 @@ export class ArDrive extends ArDriveAnonymous {
345341

346342
const destFolderDriveId = await this.arFsDao.getDriveIdForFolderId(newParentFolderId);
347343

348-
const owner = await this.getOwnerForDriveId(destFolderDriveId);
349-
await this.assertOwnerAddress(owner);
350-
344+
const owner = await this.wallet.getAddress();
351345
const originalFolderMetaData = await this.getPublicFolder({ folderId });
352346

353347
if (!destFolderDriveId.equals(originalFolderMetaData.driveId)) {
@@ -430,9 +424,7 @@ export class ArDrive extends ArDriveAnonymous {
430424

431425
const destFolderDriveId = await this.arFsDao.getDriveIdForFolderId(newParentFolderId);
432426

433-
const owner = await this.getOwnerForDriveId(destFolderDriveId);
434-
await this.assertOwnerAddress(owner);
435-
427+
const owner = await this.wallet.getAddress();
436428
const originalFolderMetaData = await this.getPrivateFolder({ folderId, driveKey });
437429

438430
if (!destFolderDriveId.equals(originalFolderMetaData.driveId)) {
@@ -594,13 +586,10 @@ export class ArDrive extends ArDriveAnonymous {
594586
const preparedEntities: UploadStats[] = [];
595587

596588
for (const entity of entitiesToUpload) {
597-
const { destFolderId, driveKey } = entity;
589+
const { destFolderId } = entity;
598590
const destDriveId = await this.arFsDao.getDriveIdForFolderId(destFolderId);
599591

600-
// Assert drive privacy and owner of the drive
601-
const owner = await this.arFsDao.getOwnerAndAssertDrive(destDriveId, driveKey);
602-
await this.assertOwnerAddress(owner);
603-
592+
const owner = await this.wallet.getAddress();
604593
preparedEntities.push({ ...entity, destDriveId, owner });
605594
}
606595

@@ -822,7 +811,7 @@ export class ArDrive extends ArDriveAnonymous {
822811
}
823812

824813
private async deriveMetaDataTxIdForFileId(fileId: FileID, dataTxId: TransactionID): Promise<TransactionID> {
825-
const owner = await this.arFsDao.getDriveOwnerForFileId(fileId);
814+
const owner = await this.wallet.getAddress();
826815
const fileMetaData = await this.arFsDao.getPublicFile(fileId, owner);
827816

828817
if (fileMetaData.dataTxId.equals(dataTxId)) {
@@ -837,7 +826,7 @@ export class ArDrive extends ArDriveAnonymous {
837826
destinationFolderId: FolderID,
838827
dataTxId: TransactionID
839828
): Promise<ArFSPublicFile | undefined> {
840-
const owner = await this.arFsDao.getDriveOwnerForFolderId(destinationFolderId);
829+
const owner = await this.wallet.getAddress();
841830
await this.assertFolderExists(destinationFolderId, owner);
842831

843832
const allFileMetaDataTxInFolder = await this.arFsDao.getPublicFilesWithParentFolderIds(
@@ -870,10 +859,7 @@ export class ArDrive extends ArDriveAnonymous {
870859
destinationFolderId: FolderID;
871860
conflictResolution: FileNameConflictResolution;
872861
}): Promise<boolean> {
873-
const destDriveId = await this.arFsDao.getDriveIdForFolderId(destinationFolderId);
874-
const owner = await this.arFsDao.getOwnerAndAssertDrive(destDriveId);
875-
await this.assertOwnerAddress(owner);
876-
862+
const owner = await this.wallet.getAddress();
877863
await resolveFileNameConflicts({
878864
wrappedFile,
879865
conflictResolution,
@@ -989,12 +975,8 @@ export class ArDrive extends ArDriveAnonymous {
989975
conflictResolution = upsertOnConflicts,
990976
prompts
991977
}: UploadPublicManifestParams): Promise<ArFSManifestResult> {
992-
const driveId = await this.arFsDao.getDriveIdForFolderId(folderId);
993-
994978
// Assert that the owner of this drive is consistent with the provided wallet
995-
const owner = await this.getOwnerForDriveId(driveId);
996-
await this.assertOwnerAddress(owner);
997-
979+
const owner = await this.wallet.getAddress();
998980
const children = await this.listPublicFolder({
999981
folderId,
1000982
maxDepth,
@@ -1034,8 +1016,7 @@ export class ArDrive extends ArDriveAnonymous {
10341016
assertValidArFSFolderName(folderName);
10351017

10361018
const driveId = await this.arFsDao.getDriveIdForFolderId(parentFolderId);
1037-
const owner = await this.arFsDao.getOwnerAndAssertDrive(driveId);
1038-
await this.assertOwnerAddress(owner);
1019+
const owner = await this.wallet.getAddress();
10391020

10401021
// Assert that there are no duplicate names in the destination folder
10411022
const entityNamesInParentFolder = await this.arFsDao.getPublicEntityNamesInFolder(parentFolderId, owner);
@@ -1096,8 +1077,7 @@ export class ArDrive extends ArDriveAnonymous {
10961077
assertValidArFSFolderName(folderName);
10971078

10981079
const driveId = await this.arFsDao.getDriveIdForFolderId(parentFolderId);
1099-
const owner = await this.arFsDao.getOwnerAndAssertDrive(driveId, driveKey);
1100-
await this.assertOwnerAddress(owner);
1080+
const owner = await this.wallet.getAddress();
11011081

11021082
// Assert that there are no duplicate names in the destination folder
11031083
const entityNamesInParentFolder = await this.arFsDao.getPrivateEntityNamesInFolder(
@@ -1286,10 +1266,8 @@ export class ArDrive extends ArDriveAnonymous {
12861266
withKeys
12871267
}: GetPrivateDriveParams): Promise<ArFSPrivateDrive> {
12881268
if (!owner) {
1289-
owner = await this.getOwnerForDriveId(driveId);
1269+
owner = await this.wallet.getAddress();
12901270
}
1291-
await this.assertOwnerAddress(owner);
1292-
12931271
const drive = await this.arFsDao.getPrivateDrive(driveId, driveKey, owner);
12941272
return withKeys
12951273
? drive
@@ -1318,9 +1296,8 @@ export class ArDrive extends ArDriveAnonymous {
13181296
withKeys
13191297
}: GetPrivateFolderParams): Promise<ArFSPrivateFolder> {
13201298
if (!owner) {
1321-
owner = await this.arFsDao.getDriveOwnerForFolderId(folderId);
1299+
owner = await this.wallet.getAddress();
13221300
}
1323-
await this.assertOwnerAddress(owner);
13241301

13251302
const folder = await this.arFsDao.getPrivateFolder(folderId, driveKey, owner);
13261303
return withKeys ? folder : new ArFSPrivateFolderKeyless(folder);
@@ -1343,7 +1320,7 @@ export class ArDrive extends ArDriveAnonymous {
13431320
withKeys = false
13441321
}: GetPrivateFileParams): Promise<ArFSPrivateFile> {
13451322
if (!owner) {
1346-
owner = await this.arFsDao.getDriveOwnerForFileId(fileId);
1323+
owner = await this.wallet.getAddress();
13471324
}
13481325

13491326
const file = await this.arFsDao.getPrivateFile(fileId, driveKey, owner);
@@ -1364,9 +1341,8 @@ export class ArDrive extends ArDriveAnonymous {
13641341
withKeys = false
13651342
}: ListPrivateFolderParams): Promise<(ArFSPrivateFolderWithPaths | ArFSPrivateFileWithPaths)[]> {
13661343
if (!owner) {
1367-
owner = await this.arFsDao.getDriveOwnerForFolderId(folderId);
1344+
owner = await this.wallet.getAddress();
13681345
}
1369-
await this.assertOwnerAddress(owner);
13701346

13711347
const withPathsFactory = withKeys ? privateEntityWithPathsFactory : privateEntityWithPathsKeylessFactory;
13721348

@@ -1490,8 +1466,8 @@ export class ArDrive extends ArDriveAnonymous {
14901466
}
14911467

14921468
async renamePublicFile({ fileId, newName }: RenamePublicFileParams): Promise<ArFSResult> {
1493-
const owner = await this.arFsDao.getDriveOwnerForFileId(fileId);
1494-
await this.assertOwnerAddress(owner);
1469+
const owner = await this.wallet.getAddress();
1470+
14951471
const file = await this.getPublicFile({ fileId, owner });
14961472
if (file.name === newName) {
14971473
throw new Error(`To rename a file, the new name must be different`);
@@ -1549,8 +1525,7 @@ export class ArDrive extends ArDriveAnonymous {
15491525
}
15501526

15511527
async renamePrivateFile({ fileId, newName, driveKey }: RenamePrivateFileParams): Promise<ArFSResult> {
1552-
const owner = await this.arFsDao.getDriveOwnerForFileId(fileId);
1553-
await this.assertOwnerAddress(owner);
1528+
const owner = await this.wallet.getAddress();
15541529
const file = await this.getPrivateFile({ fileId, driveKey, owner });
15551530
if (file.name === newName) {
15561531
throw new Error(`To rename a file, the new name must be different`);
@@ -1613,8 +1588,7 @@ export class ArDrive extends ArDriveAnonymous {
16131588
}
16141589

16151590
async renamePublicFolder({ folderId, newName }: RenamePublicFolderParams): Promise<ArFSResult> {
1616-
const owner = await this.arFsDao.getDriveOwnerForFolderId(folderId);
1617-
await this.assertOwnerAddress(owner);
1591+
const owner = await this.wallet.getAddress();
16181592
const folder = await this.getPublicFolder({ folderId, owner });
16191593
if (`${folder.parentFolderId}` === ROOT_FOLDER_ID_PLACEHOLDER) {
16201594
throw new Error(
@@ -1671,8 +1645,7 @@ export class ArDrive extends ArDriveAnonymous {
16711645
}
16721646

16731647
async renamePrivateFolder({ folderId, newName, driveKey }: RenamePrivateFolderParams): Promise<ArFSResult> {
1674-
const owner = await this.arFsDao.getDriveOwnerForFolderId(folderId);
1675-
await this.assertOwnerAddress(owner);
1648+
const owner = await this.wallet.getAddress();
16761649
const folder = await this.getPrivateFolder({ folderId, driveKey, owner });
16771650
if (`${folder.parentFolderId}` === ROOT_FOLDER_ID_PLACEHOLDER) {
16781651
throw new Error(
@@ -1735,8 +1708,7 @@ export class ArDrive extends ArDriveAnonymous {
17351708
}
17361709

17371710
async renamePublicDrive({ driveId, newName }: RenamePublicDriveParams): Promise<ArFSResult> {
1738-
const owner = await this.arFsDao.getOwnerForDriveId(driveId);
1739-
await this.assertOwnerAddress(owner);
1711+
const owner = await this.wallet.getAddress();
17401712
const drive = await this.getPublicDrive({ driveId, owner });
17411713
if (drive.name === newName) {
17421714
throw new Error(`New drive name '${newName}' must be different from the current drive name!`);
@@ -1791,8 +1763,7 @@ export class ArDrive extends ArDriveAnonymous {
17911763
}
17921764

17931765
async renamePrivateDrive({ driveId, newName, driveKey }: RenamePrivateDriveParams): Promise<ArFSResult> {
1794-
const owner = await this.arFsDao.getOwnerForDriveId(driveId);
1795-
await this.assertOwnerAddress(owner);
1766+
const owner = await this.wallet.getAddress();
17961767
const drive = await this.getPrivateDrive({ driveId, owner, driveKey });
17971768
if (drive.name === newName) {
17981769
throw new Error(`New drive name '${newName}' must be different from the current drive name!`);
@@ -1858,7 +1829,7 @@ export class ArDrive extends ArDriveAnonymous {
18581829
owner
18591830
}: DownloadPrivateFolderParameters): Promise<void> {
18601831
if (!owner) {
1861-
owner = await this.arFsDao.getDriveOwnerForFolderId(folderId);
1832+
owner = await this.wallet.getAddress();
18621833
}
18631834

18641835
return this.arFsDao.downloadPrivateFolder({
@@ -1880,7 +1851,7 @@ export class ArDrive extends ArDriveAnonymous {
18801851
owner
18811852
}: DownloadPrivateDriveParameters): Promise<void> {
18821853
if (!owner) {
1883-
owner = await this.arFsDao.getOwnerForDriveId(driveId);
1854+
owner = await this.wallet.getAddress();
18841855
}
18851856

18861857
const drive = await this.arFsDao.getPrivateDrive(driveId, driveKey, owner);

src/arfs/arfsdao.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ import {
8787
W,
8888
GQLEdgeInterface,
8989
GQLNodeInterface,
90-
DrivePrivacy,
9190
DriveID,
9291
DriveKey,
9392
FolderID,
@@ -176,7 +175,7 @@ import {
176175
} from './tx/arfs_tx_data_types';
177176
import { ArFSTagAssembler } from './tags/tag_assembler';
178177
import { assertDataRootsMatch, rePrepareV2Tx } from '../utils/arfsdao_utils';
179-
import { ArFSDataToUpload, ArFSFolderToUpload } from '../exports';
178+
import { ArFSDataToUpload, ArFSFolderToUpload, DrivePrivacy } from '../exports';
180179
import { Turbo, TurboCachesResponse } from './turbo';
181180
import { ArweaveSigner } from 'arbundles/src/signing';
182181

src/types/entity_key.test.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,47 @@ describe('EntityKey class', () => {
1111

1212
it('throws if a non-buffer is given', () => {
1313
// eslint-disable-next-line prettier/prettier
14-
const nonBuffer: Buffer = 'non buffer type' as unknown as Buffer;
14+
const nonBuffer: Buffer = ('non buffer type' as unknown) as Buffer;
1515
expect(() => new EntityKey(nonBuffer)).to.throw('The argument must be of type Buffer, got string');
1616
});
1717

1818
it('the original buffer contains the correct data', async () => {
1919
expect(key.keyData).to.deep.equal(
2020
Buffer.from([
2121
// eslint-disable-next-line prettier/prettier
22-
159, 20, 229, 218, 72, 185, 133, 104, 242, 96, 77, 18, 140, 232, 54, 21, 93, 207, 19, 177, 1, 40, 199,
22+
159,
23+
20,
24+
229,
25+
218,
26+
72,
27+
185,
28+
133,
29+
104,
30+
242,
31+
96,
32+
77,
33+
18,
34+
140,
35+
232,
36+
54,
37+
21,
38+
93,
39+
207,
40+
19,
41+
177,
42+
1,
43+
40,
44+
199,
2345
// eslint-disable-next-line prettier/prettier
24-
189, 19, 169, 3, 242, 227, 175, 155, 172
46+
189,
47+
19,
48+
169,
49+
3,
50+
242,
51+
227,
52+
175,
53+
155,
54+
172
2555
])
2656
);
2757
});

src/types/gql_Types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,13 @@ export interface GQLTransactionsResultInterface {
7979
export default interface GQLResultInterface {
8080
data: {
8181
transactions: GQLTransactionsResultInterface;
82-
};
82+
} | null;
83+
errors:
84+
| {
85+
message: string;
86+
path: string[];
87+
locations: { line: number; column: number }[];
88+
extensions: { code: string };
89+
}[]
90+
| undefined;
8391
}

src/utils/gateway_api.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@ export class GatewayAPI {
8282
try {
8383
const { data } = await this.postToEndpoint<GQLResultInterface>('graphql', query);
8484

85+
if (data.errors) {
86+
data.errors.forEach((error) => {
87+
console.error(`GQL Error: ${error.message}`);
88+
});
89+
}
90+
91+
if (!data.data) {
92+
const isTimeoutError = data.errors?.some((error) =>
93+
error.message.includes('canceling statement due to statement timeout')
94+
);
95+
96+
if (isTimeoutError) {
97+
throw new Error('GQL Query has been timed out.');
98+
}
99+
100+
throw new Error('No data was returned from the GQL request.');
101+
}
102+
85103
return data.data.transactions;
86104
} catch (error) {
87105
throw Error(`GQL Error: ${(error as Error).message}`);

0 commit comments

Comments
 (0)