1from typing import Optional
2
3from arango.request import Request
4from arango.response import Response
5
6
7class ArangoError(Exception):
8    """Base class for all exceptions in python-arango."""
9
10
11class ArangoClientError(ArangoError):
12    """Base class for errors originating from python-arango client.
13
14    :param msg: Error message.
15    :type msg: str
16
17    :cvar source: Source of the error (always set to "client").
18    :vartype source: str
19    :ivar message: Error message.
20    :vartype message: str
21    """
22
23    source = "client"
24
25    def __init__(self, msg: str) -> None:
26        super().__init__(msg)
27        self.message = msg
28        self.error_message = None
29        self.error_code = None
30        self.url = None
31        self.response = None
32        self.request = None
33        self.http_method = None
34        self.http_code = None
35        self.http_headers = None
36
37
38class ArangoServerError(ArangoError):
39    """Base class for errors originating from ArangoDB server.
40
41    :param resp: HTTP response.
42    :type resp: arango.response.Response
43    :param msg: Error message override.
44    :type msg: str
45
46    :cvar source: Source of the error (always set to "server").
47    :vartype source: str
48    :ivar message: Exception message.
49    :vartype message: str
50    :ivar url: API URL.
51    :vartype url: str
52    :ivar response: HTTP response object.
53    :vartype response: arango.response.Response
54    :ivar request: HTTP request object.
55    :vartype request: arango.request.Request
56    :ivar http_method: HTTP method in lowercase (e.g. "post").
57    :vartype http_method: str
58    :ivar http_code: HTTP status code.
59    :vartype http_code: int
60    :ivar http_headers: Response headers.
61    :vartype http_headers: dict
62    :ivar error_code: Error code from ArangoDB server.
63    :vartype error_code: int
64    :ivar error_message: Raw error message from ArangoDB server.
65    :vartype error_message: str
66    """
67
68    source = "server"
69
70    def __init__(
71        self, resp: Response, request: Request, msg: Optional[str] = None
72    ) -> None:
73        msg = msg or resp.error_message or resp.status_text
74        self.error_message = resp.error_message
75        self.error_code = resp.error_code
76        if self.error_code is not None:
77            msg = f"[HTTP {resp.status_code}][ERR {self.error_code}] {msg}"
78        else:
79            msg = f"[HTTP {resp.status_code}] {msg}"
80            self.error_code = resp.status_code
81        super().__init__(msg)
82        self.message = msg
83        self.url = resp.url
84        self.response = resp
85        self.request = request
86        self.http_method = resp.method
87        self.http_code = resp.status_code
88        self.http_headers = resp.headers
89
90
91##################
92# AQL Exceptions #
93##################
94
95
96class AQLQueryListError(ArangoServerError):
97    """Failed to retrieve running AQL queries."""
98
99
100class AQLQueryExplainError(ArangoServerError):
101    """Failed to parse and explain query."""
102
103
104class AQLQueryValidateError(ArangoServerError):
105    """Failed to parse and validate query."""
106
107
108class AQLQueryExecuteError(ArangoServerError):
109    """Failed to execute query."""
110
111
112class AQLQueryKillError(ArangoServerError):
113    """Failed to kill the query."""
114
115
116class AQLQueryClearError(ArangoServerError):
117    """Failed to clear slow AQL queries."""
118
119
120class AQLQueryTrackingGetError(ArangoServerError):
121    """Failed to retrieve AQL tracking properties."""
122
123
124class AQLQueryTrackingSetError(ArangoServerError):
125    """Failed to configure AQL tracking properties."""
126
127
128class AQLCachePropertiesError(ArangoServerError):
129    """Failed to retrieve query cache properties."""
130
131
132class AQLCacheConfigureError(ArangoServerError):
133    """Failed to configure query cache properties."""
134
135
136class AQLCacheEntriesError(ArangoServerError):
137    """Failed to retrieve AQL cache entries."""
138
139
140class AQLCacheClearError(ArangoServerError):
141    """Failed to clear the query cache."""
142
143
144class AQLFunctionListError(ArangoServerError):
145    """Failed to retrieve AQL user functions."""
146
147
148class AQLFunctionCreateError(ArangoServerError):
149    """Failed to create AQL user function."""
150
151
152class AQLFunctionDeleteError(ArangoServerError):
153    """Failed to delete AQL user function."""
154
155
156##############################
157# Async Execution Exceptions #
158##############################
159
160
161class AsyncExecuteError(ArangoServerError):
162    """Failed to execute async API request."""
163
164
165class AsyncJobListError(ArangoServerError):
166    """Failed to retrieve async jobs."""
167
168
169class AsyncJobCancelError(ArangoServerError):
170    """Failed to cancel async job."""
171
172
173class AsyncJobStatusError(ArangoServerError):
174    """Failed to retrieve async job status."""
175
176
177class AsyncJobResultError(ArangoServerError):
178    """Failed to retrieve async job result."""
179
180
181class AsyncJobClearError(ArangoServerError):
182    """Failed to clear async job results."""
183
184
185##############################
186# Backup Exceptions #
187##############################
188
189
190class BackupCreateError(ArangoServerError):
191    """Failed to create a backup."""
192
193
194class BackupDeleteError(ArangoServerError):
195    """Failed to delete a backup."""
196
197
198class BackupDownloadError(ArangoServerError):
199    """Failed to download a backup from remote repository."""
200
201
202class BackupGetError(ArangoServerError):
203    """Failed to retrieve backup details."""
204
205
206class BackupRestoreError(ArangoServerError):
207    """Failed to restore from backup."""
208
209
210class BackupUploadError(ArangoServerError):
211    """Failed to upload a backup to remote repository."""
212
213
214##############################
215# Batch Execution Exceptions #
216##############################
217
218
219class BatchStateError(ArangoClientError):
220    """The batch object was in a bad state."""
221
222
223class BatchJobResultError(ArangoClientError):
224    """Failed to retrieve batch job result."""
225
226
227class BatchExecuteError(ArangoServerError):
228    """Failed to execute batch API request."""
229
230
231#########################
232# Collection Exceptions #
233#########################
234
235
236class CollectionListError(ArangoServerError):
237    """Failed to retrieve collections."""
238
239
240class CollectionPropertiesError(ArangoServerError):
241    """Failed to retrieve collection properties."""
242
243
244class CollectionConfigureError(ArangoServerError):
245    """Failed to configure collection properties."""
246
247
248class CollectionStatisticsError(ArangoServerError):
249    """Failed to retrieve collection statistics."""
250
251
252class CollectionRevisionError(ArangoServerError):
253    """Failed to retrieve collection revision."""
254
255
256class CollectionChecksumError(ArangoServerError):
257    """Failed to retrieve collection checksum."""
258
259
260class CollectionCreateError(ArangoServerError):
261    """Failed to create collection."""
262
263
264class CollectionDeleteError(ArangoServerError):
265    """Failed to delete collection."""
266
267
268class CollectionRenameError(ArangoServerError):
269    """Failed to rename collection."""
270
271
272class CollectionTruncateError(ArangoServerError):
273    """Failed to truncate collection."""
274
275
276class CollectionLoadError(ArangoServerError):
277    """Failed to load collection."""
278
279
280class CollectionUnloadError(ArangoServerError):
281    """Failed to unload collection."""
282
283
284class CollectionRecalculateCountError(ArangoServerError):
285    """Failed to recalculate document count."""
286
287
288class CollectionResponsibleShardError(ArangoServerError):
289    """Failed to retrieve responsible shard."""
290
291
292#####################
293# Cursor Exceptions #
294#####################
295
296
297class CursorStateError(ArangoClientError):
298    """The cursor object was in a bad state."""
299
300
301class CursorCountError(ArangoClientError, TypeError):
302    """The cursor count was not enabled."""
303
304
305class CursorEmptyError(ArangoClientError):
306    """The current batch in cursor was empty."""
307
308
309class CursorNextError(ArangoServerError):
310    """Failed to retrieve the next result batch from server."""
311
312
313class CursorCloseError(ArangoServerError):
314    """Failed to delete the cursor result from server."""
315
316
317#######################
318# Database Exceptions #
319#######################
320
321
322class DatabaseListError(ArangoServerError):
323    """Failed to retrieve databases."""
324
325
326class DatabasePropertiesError(ArangoServerError):
327    """Failed to retrieve database properties."""
328
329
330class DatabaseCreateError(ArangoServerError):
331    """Failed to create database."""
332
333
334class DatabaseDeleteError(ArangoServerError):
335    """Failed to delete database."""
336
337
338#######################
339# Document Exceptions #
340#######################
341
342
343class DocumentParseError(ArangoClientError):
344    """Failed to parse document input."""
345
346
347class DocumentCountError(ArangoServerError):
348    """Failed to retrieve document count."""
349
350
351class DocumentInError(ArangoServerError):
352    """Failed to check whether document exists."""
353
354
355class DocumentGetError(ArangoServerError):
356    """Failed to retrieve document."""
357
358
359class DocumentKeysError(ArangoServerError):
360    """Failed to retrieve document keys."""
361
362
363class DocumentIDsError(ArangoServerError):
364    """Failed to retrieve document IDs."""
365
366
367class DocumentInsertError(ArangoServerError):
368    """Failed to insert document."""
369
370
371class DocumentReplaceError(ArangoServerError):
372    """Failed to replace document."""
373
374
375class DocumentUpdateError(ArangoServerError):
376    """Failed to update document."""
377
378
379class DocumentDeleteError(ArangoServerError):
380    """Failed to delete document."""
381
382
383class DocumentRevisionError(ArangoServerError):
384    """The expected and actual document revisions mismatched."""
385
386
387###################
388# Foxx Exceptions #
389###################
390
391
392class FoxxServiceListError(ArangoServerError):
393    """Failed to retrieve Foxx services."""
394
395
396class FoxxServiceGetError(ArangoServerError):
397    """Failed to retrieve Foxx service metadata."""
398
399
400class FoxxServiceCreateError(ArangoServerError):
401    """Failed to create Foxx service."""
402
403
404class FoxxServiceUpdateError(ArangoServerError):
405    """Failed to update Foxx service."""
406
407
408class FoxxServiceReplaceError(ArangoServerError):
409    """Failed to replace Foxx service."""
410
411
412class FoxxServiceDeleteError(ArangoServerError):
413    """Failed to delete Foxx services."""
414
415
416class FoxxConfigGetError(ArangoServerError):
417    """Failed to retrieve Foxx service configuration."""
418
419
420class FoxxConfigUpdateError(ArangoServerError):
421    """Failed to update Foxx service configuration."""
422
423
424class FoxxConfigReplaceError(ArangoServerError):
425    """Failed to replace Foxx service configuration."""
426
427
428class FoxxDependencyGetError(ArangoServerError):
429    """Failed to retrieve Foxx service dependencies."""
430
431
432class FoxxDependencyUpdateError(ArangoServerError):
433    """Failed to update Foxx service dependencies."""
434
435
436class FoxxDependencyReplaceError(ArangoServerError):
437    """Failed to replace Foxx service dependencies."""
438
439
440class FoxxScriptListError(ArangoServerError):
441    """Failed to retrieve Foxx service scripts."""
442
443
444class FoxxScriptRunError(ArangoServerError):
445    """Failed to run Foxx service script."""
446
447
448class FoxxTestRunError(ArangoServerError):
449    """Failed to run Foxx service tests."""
450
451
452class FoxxDevModeEnableError(ArangoServerError):
453    """Failed to enable development mode for Foxx service."""
454
455
456class FoxxDevModeDisableError(ArangoServerError):
457    """Failed to disable development mode for Foxx service."""
458
459
460class FoxxReadmeGetError(ArangoServerError):
461    """Failed to retrieve Foxx service readme."""
462
463
464class FoxxSwaggerGetError(ArangoServerError):
465    """Failed to retrieve Foxx service swagger."""
466
467
468class FoxxDownloadError(ArangoServerError):
469    """Failed to download Foxx service bundle."""
470
471
472class FoxxCommitError(ArangoServerError):
473    """Failed to commit local Foxx service state."""
474
475
476####################
477# Graph Exceptions #
478####################
479
480
481class GraphListError(ArangoServerError):
482    """Failed to retrieve graphs."""
483
484
485class GraphCreateError(ArangoServerError):
486    """Failed to create the graph."""
487
488
489class GraphDeleteError(ArangoServerError):
490    """Failed to delete the graph."""
491
492
493class GraphPropertiesError(ArangoServerError):
494    """Failed to retrieve graph properties."""
495
496
497class GraphTraverseError(ArangoServerError):
498    """Failed to execute graph traversal."""
499
500
501class VertexCollectionListError(ArangoServerError):
502    """Failed to retrieve vertex collections."""
503
504
505class VertexCollectionCreateError(ArangoServerError):
506    """Failed to create vertex collection."""
507
508
509class VertexCollectionDeleteError(ArangoServerError):
510    """Failed to delete vertex collection."""
511
512
513class EdgeDefinitionListError(ArangoServerError):
514    """Failed to retrieve edge definitions."""
515
516
517class EdgeDefinitionCreateError(ArangoServerError):
518    """Failed to create edge definition."""
519
520
521class EdgeDefinitionReplaceError(ArangoServerError):
522    """Failed to replace edge definition."""
523
524
525class EdgeDefinitionDeleteError(ArangoServerError):
526    """Failed to delete edge definition."""
527
528
529class EdgeListError(ArangoServerError):
530    """Failed to retrieve edges coming in and out of a vertex."""
531
532
533####################
534# Index Exceptions #
535####################
536
537
538class IndexListError(ArangoServerError):
539    """Failed to retrieve collection indexes."""
540
541
542class IndexCreateError(ArangoServerError):
543    """Failed to create collection index."""
544
545
546class IndexDeleteError(ArangoServerError):
547    """Failed to delete collection index."""
548
549
550class IndexLoadError(ArangoServerError):
551    """Failed to load indexes into memory."""
552
553
554#####################
555# Pregel Exceptions #
556#####################
557
558
559class PregelJobCreateError(ArangoServerError):
560    """Failed to create Pregel job."""
561
562
563class PregelJobGetError(ArangoServerError):
564    """Failed to retrieve Pregel job details."""
565
566
567class PregelJobDeleteError(ArangoServerError):
568    """Failed to delete Pregel job."""
569
570
571#####################
572# Server Exceptions #
573#####################
574
575
576class ServerConnectionError(ArangoClientError):
577    """Failed to connect to ArangoDB server."""
578
579
580class ServerEngineError(ArangoServerError):
581    """Failed to retrieve database engine."""
582
583
584class ServerVersionError(ArangoServerError):
585    """Failed to retrieve server version."""
586
587
588class ServerDetailsError(ArangoServerError):
589    """Failed to retrieve server details."""
590
591
592class ServerStatusError(ArangoServerError):
593    """Failed to retrieve server status."""
594
595
596class ServerTimeError(ArangoServerError):
597    """Failed to retrieve server system time."""
598
599
600class ServerEchoError(ArangoServerError):
601    """Failed to retrieve details on last request."""
602
603
604class ServerShutdownError(ArangoServerError):
605    """Failed to initiate shutdown sequence."""
606
607
608class ServerRunTestsError(ArangoServerError):
609    """Failed to execute server tests."""
610
611
612class ServerRequiredDBVersionError(ArangoServerError):
613    """Failed to retrieve server target version."""
614
615
616class ServerReadLogError(ArangoServerError):
617    """Failed to retrieve global log."""
618
619
620class ServerLogLevelError(ArangoServerError):
621    """Failed to retrieve server log levels."""
622
623
624class ServerLogLevelSetError(ArangoServerError):
625    """Failed to set server log levels."""
626
627
628class ServerReloadRoutingError(ArangoServerError):
629    """Failed to reload routing details."""
630
631
632class ServerStatisticsError(ArangoServerError):
633    """Failed to retrieve server statistics."""
634
635
636class ServerMetricsError(ArangoServerError):
637    """Failed to retrieve server metrics."""
638
639
640class ServerRoleError(ArangoServerError):
641    """Failed to retrieve server role in a cluster."""
642
643
644class ServerTLSError(ArangoServerError):
645    """Failed to retrieve TLS data."""
646
647
648class ServerTLSReloadError(ArangoServerError):
649    """Failed to reload TLS."""
650
651
652class ServerEncryptionError(ArangoServerError):
653    """Failed to reload user-defined encryption keys."""
654
655
656#####################
657# Task Exceptions   #
658#####################
659
660
661class TaskListError(ArangoServerError):
662    """Failed to retrieve server tasks."""
663
664
665class TaskGetError(ArangoServerError):
666    """Failed to retrieve server task details."""
667
668
669class TaskCreateError(ArangoServerError):
670    """Failed to create server task."""
671
672
673class TaskDeleteError(ArangoServerError):
674    """Failed to delete server task."""
675
676
677##########################
678# Transaction Exceptions #
679##########################
680
681
682class TransactionExecuteError(ArangoServerError):
683    """Failed to execute raw transaction."""
684
685
686class TransactionInitError(ArangoServerError):
687    """Failed to initialize transaction."""
688
689
690class TransactionStatusError(ArangoServerError):
691    """Failed to retrieve transaction status."""
692
693
694class TransactionCommitError(ArangoServerError):
695    """Failed to commit transaction."""
696
697
698class TransactionAbortError(ArangoServerError):
699    """Failed to abort transaction."""
700
701
702###################
703# User Exceptions #
704###################
705
706
707class UserListError(ArangoServerError):
708    """Failed to retrieve users."""
709
710
711class UserGetError(ArangoServerError):
712    """Failed to retrieve user details."""
713
714
715class UserCreateError(ArangoServerError):
716    """Failed to create user."""
717
718
719class UserUpdateError(ArangoServerError):
720    """Failed to update user."""
721
722
723class UserReplaceError(ArangoServerError):
724    """Failed to replace user."""
725
726
727class UserDeleteError(ArangoServerError):
728    """Failed to delete user."""
729
730
731###################
732# View Exceptions #
733###################
734
735
736class ViewListError(ArangoServerError):
737    """Failed to retrieve views."""
738
739
740class ViewGetError(ArangoServerError):
741    """Failed to retrieve view details."""
742
743
744class ViewCreateError(ArangoServerError):
745    """Failed to create view."""
746
747
748class ViewUpdateError(ArangoServerError):
749    """Failed to update view."""
750
751
752class ViewReplaceError(ArangoServerError):
753    """Failed to replace view."""
754
755
756class ViewDeleteError(ArangoServerError):
757    """Failed to delete view."""
758
759
760class ViewRenameError(ArangoServerError):
761    """Failed to rename view."""
762
763
764#######################
765# Analyzer Exceptions #
766#######################
767
768
769class AnalyzerListError(ArangoServerError):
770    """Failed to retrieve analyzers."""
771
772
773class AnalyzerGetError(ArangoServerError):
774    """Failed to retrieve analyzer details."""
775
776
777class AnalyzerCreateError(ArangoServerError):
778    """Failed to create analyzer."""
779
780
781class AnalyzerDeleteError(ArangoServerError):
782    """Failed to delete analyzer."""
783
784
785#########################
786# Permission Exceptions #
787#########################
788
789
790class PermissionListError(ArangoServerError):
791    """Failed to list user permissions."""
792
793
794class PermissionGetError(ArangoServerError):
795    """Failed to retrieve user permission."""
796
797
798class PermissionUpdateError(ArangoServerError):
799    """Failed to update user permission."""
800
801
802class PermissionResetError(ArangoServerError):
803    """Failed to reset user permission."""
804
805
806##################
807# WAL Exceptions #
808##################
809
810
811class WALPropertiesError(ArangoServerError):
812    """Failed to retrieve WAL properties."""
813
814
815class WALConfigureError(ArangoServerError):
816    """Failed to configure WAL properties."""
817
818
819class WALTransactionListError(ArangoServerError):
820    """Failed to retrieve running WAL transactions."""
821
822
823class WALFlushError(ArangoServerError):
824    """Failed to flush WAL."""
825
826
827class WALTickRangesError(ArangoServerError):
828    """Failed to return WAL tick ranges."""
829
830
831class WALLastTickError(ArangoServerError):
832    """Failed to return WAL tick ranges."""
833
834
835class WALTailError(ArangoServerError):
836    """Failed to return WAL tick ranges."""
837
838
839##########################
840# Replication Exceptions #
841##########################
842
843
844class ReplicationInventoryError(ArangoServerError):
845    """Failed to retrieve inventory of collection and indexes."""
846
847
848class ReplicationDumpBatchCreateError(ArangoServerError):
849    """Failed to create dump batch."""
850
851
852class ReplicationDumpBatchDeleteError(ArangoServerError):
853    """Failed to delete a dump batch."""
854
855
856class ReplicationDumpBatchExtendError(ArangoServerError):
857    """Failed to extend a dump batch."""
858
859
860class ReplicationDumpError(ArangoServerError):
861    """Failed to retrieve collection content."""
862
863
864class ReplicationSyncError(ArangoServerError):
865    """Failed to synchronize data from remote."""
866
867
868class ReplicationClusterInventoryError(ArangoServerError):
869    """Failed to retrieve overview of collection and indexes in a cluster."""
870
871
872class ReplicationLoggerStateError(ArangoServerError):
873    """Failed to retrieve logger state."""
874
875
876class ReplicationLoggerFirstTickError(ArangoServerError):
877    """Failed to retrieve logger first tick."""
878
879
880class ReplicationApplierConfigError(ArangoServerError):
881    """Failed to retrieve replication applier configuration."""
882
883
884class ReplicationApplierConfigSetError(ArangoServerError):
885    """Failed to update replication applier configuration."""
886
887
888class ReplicationApplierStartError(ArangoServerError):
889    """Failed to start replication applier."""
890
891
892class ReplicationApplierStopError(ArangoServerError):
893    """Failed to stop replication applier."""
894
895
896class ReplicationApplierStateError(ArangoServerError):
897    """Failed to retrieve replication applier state."""
898
899
900class ReplicationMakeSlaveError(ArangoServerError):
901    """Failed to change role to slave."""
902
903
904class ReplicationServerIDError(ArangoServerError):
905    """Failed to retrieve server ID."""
906
907
908######################
909# Cluster Exceptions #
910######################
911
912
913class ClusterHealthError(ArangoServerError):
914    """Failed to retrieve DBServer health."""
915
916
917class ClusterServerIDError(ArangoServerError):
918    """Failed to retrieve server ID."""
919
920
921class ClusterServerRoleError(ArangoServerError):
922    """Failed to retrieve server role."""
923
924
925class ClusterServerStatisticsError(ArangoServerError):
926    """Failed to retrieve DBServer statistics."""
927
928
929class ClusterServerVersionError(ArangoServerError):
930    """Failed to retrieve server node version."""
931
932
933class ClusterServerEngineError(ArangoServerError):
934    """Failed to retrieve server node engine."""
935
936
937class ClusterMaintenanceModeError(ArangoServerError):
938    """Failed to enable/disable cluster supervision maintenance mode."""
939
940
941class ClusterEndpointsError(ArangoServerError):
942    """Failed to retrieve cluster endpoints."""
943
944
945class ClusterServerCountError(ArangoServerError):
946    """Failed to retrieve cluster server count."""
947
948
949##################
950# JWT Exceptions #
951##################
952
953
954class JWTAuthError(ArangoServerError):
955    """Failed to get a new JWT token from ArangoDB."""
956
957
958class JWTSecretListError(ArangoServerError):
959    """Failed to retrieve information on currently loaded JWT secrets."""
960
961
962class JWTSecretReloadError(ArangoServerError):
963    """Failed to reload JWT secrets."""
964