This repository has been archived by the owner on Jan 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
/
error.go
656 lines (457 loc) · 18.3 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
/*
* This file is part of the libvirt-go project
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Copyright (c) 2013 Alex Zorin
* Copyright (C) 2016 Red Hat, Inc.
*
*/
package libvirt
/*
#cgo pkg-config: libvirt
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
#include "error_compat.h"
void ignoreErrorFunc(void *userData, virErrorPtr error) {
// no-op
}
*/
import "C"
import (
"fmt"
)
func init() {
C.virSetErrorFunc(nil, (C.virErrorFunc)(C.ignoreErrorFunc))
C.virInitialize()
}
type ErrorLevel int
const (
ERR_NONE = ErrorLevel(C.VIR_ERR_NONE)
ERR_WARNING = ErrorLevel(C.VIR_ERR_WARNING)
ERR_ERROR = ErrorLevel(C.VIR_ERR_ERROR)
)
type ErrorNumber int
func (err ErrorNumber) Error() string {
return fmt.Sprintf("virErrCode(%d)", err)
}
const (
ERR_OK = ErrorNumber(C.VIR_ERR_OK)
// internal error
ERR_INTERNAL_ERROR = ErrorNumber(C.VIR_ERR_INTERNAL_ERROR)
// memory allocation failure
ERR_NO_MEMORY = ErrorNumber(C.VIR_ERR_NO_MEMORY)
// no support for this function
ERR_NO_SUPPORT = ErrorNumber(C.VIR_ERR_NO_SUPPORT)
// could not resolve hostname
ERR_UNKNOWN_HOST = ErrorNumber(C.VIR_ERR_UNKNOWN_HOST)
// can't connect to hypervisor
ERR_NO_CONNECT = ErrorNumber(C.VIR_ERR_NO_CONNECT)
// invalid connection object
ERR_INVALID_CONN = ErrorNumber(C.VIR_ERR_INVALID_CONN)
// invalid domain object
ERR_INVALID_DOMAIN = ErrorNumber(C.VIR_ERR_INVALID_DOMAIN)
// invalid function argument
ERR_INVALID_ARG = ErrorNumber(C.VIR_ERR_INVALID_ARG)
// a command to hypervisor failed
ERR_OPERATION_FAILED = ErrorNumber(C.VIR_ERR_OPERATION_FAILED)
// a HTTP GET command to failed
ERR_GET_FAILED = ErrorNumber(C.VIR_ERR_GET_FAILED)
// a HTTP POST command to failed
ERR_POST_FAILED = ErrorNumber(C.VIR_ERR_POST_FAILED)
// unexpected HTTP error code
ERR_HTTP_ERROR = ErrorNumber(C.VIR_ERR_HTTP_ERROR)
// failure to serialize an S-Expr
ERR_SEXPR_SERIAL = ErrorNumber(C.VIR_ERR_SEXPR_SERIAL)
// could not open Xen hypervisor control
ERR_NO_XEN = ErrorNumber(C.VIR_ERR_NO_XEN)
// failure doing an hypervisor call
ERR_XEN_CALL = ErrorNumber(C.VIR_ERR_XEN_CALL)
// unknown OS type
ERR_OS_TYPE = ErrorNumber(C.VIR_ERR_OS_TYPE)
// missing kernel information
ERR_NO_KERNEL = ErrorNumber(C.VIR_ERR_NO_KERNEL)
// missing root device information
ERR_NO_ROOT = ErrorNumber(C.VIR_ERR_NO_ROOT)
// missing source device information
ERR_NO_SOURCE = ErrorNumber(C.VIR_ERR_NO_SOURCE)
// missing target device information
ERR_NO_TARGET = ErrorNumber(C.VIR_ERR_NO_TARGET)
// missing domain name information
ERR_NO_NAME = ErrorNumber(C.VIR_ERR_NO_NAME)
// missing domain OS information
ERR_NO_OS = ErrorNumber(C.VIR_ERR_NO_OS)
// missing domain devices information
ERR_NO_DEVICE = ErrorNumber(C.VIR_ERR_NO_DEVICE)
// could not open Xen Store control
ERR_NO_XENSTORE = ErrorNumber(C.VIR_ERR_NO_XENSTORE)
// too many drivers registered
ERR_DRIVER_FULL = ErrorNumber(C.VIR_ERR_DRIVER_FULL)
// not supported by the drivers (DEPRECATED)
ERR_CALL_FAILED = ErrorNumber(C.VIR_ERR_CALL_FAILED)
// an XML description is not well formed or broken
ERR_XML_ERROR = ErrorNumber(C.VIR_ERR_XML_ERROR)
// the domain already exist
ERR_DOM_EXIST = ErrorNumber(C.VIR_ERR_DOM_EXIST)
// operation forbidden on read-only connections
ERR_OPERATION_DENIED = ErrorNumber(C.VIR_ERR_OPERATION_DENIED)
// failed to open a conf file
ERR_OPEN_FAILED = ErrorNumber(C.VIR_ERR_OPEN_FAILED)
// failed to read a conf file
ERR_READ_FAILED = ErrorNumber(C.VIR_ERR_READ_FAILED)
// failed to parse a conf file
ERR_PARSE_FAILED = ErrorNumber(C.VIR_ERR_PARSE_FAILED)
// failed to parse the syntax of a conf file
ERR_CONF_SYNTAX = ErrorNumber(C.VIR_ERR_CONF_SYNTAX)
// failed to write a conf file
ERR_WRITE_FAILED = ErrorNumber(C.VIR_ERR_WRITE_FAILED)
// detail of an XML error
ERR_XML_DETAIL = ErrorNumber(C.VIR_ERR_XML_DETAIL)
// invalid network object
ERR_INVALID_NETWORK = ErrorNumber(C.VIR_ERR_INVALID_NETWORK)
// the network already exist
ERR_NETWORK_EXIST = ErrorNumber(C.VIR_ERR_NETWORK_EXIST)
// general system call failure
ERR_SYSTEM_ERROR = ErrorNumber(C.VIR_ERR_SYSTEM_ERROR)
// some sort of RPC error
ERR_RPC = ErrorNumber(C.VIR_ERR_RPC)
// error from a GNUTLS call
ERR_GNUTLS_ERROR = ErrorNumber(C.VIR_ERR_GNUTLS_ERROR)
// failed to start network
WAR_NO_NETWORK = ErrorNumber(C.VIR_WAR_NO_NETWORK)
// domain not found or unexpectedly disappeared
ERR_NO_DOMAIN = ErrorNumber(C.VIR_ERR_NO_DOMAIN)
// network not found
ERR_NO_NETWORK = ErrorNumber(C.VIR_ERR_NO_NETWORK)
// invalid MAC address
ERR_INVALID_MAC = ErrorNumber(C.VIR_ERR_INVALID_MAC)
// authentication failed
ERR_AUTH_FAILED = ErrorNumber(C.VIR_ERR_AUTH_FAILED)
// invalid storage pool object
ERR_INVALID_STORAGE_POOL = ErrorNumber(C.VIR_ERR_INVALID_STORAGE_POOL)
// invalid storage vol object
ERR_INVALID_STORAGE_VOL = ErrorNumber(C.VIR_ERR_INVALID_STORAGE_VOL)
// failed to start storage
WAR_NO_STORAGE = ErrorNumber(C.VIR_WAR_NO_STORAGE)
// storage pool not found
ERR_NO_STORAGE_POOL = ErrorNumber(C.VIR_ERR_NO_STORAGE_POOL)
// storage volume not found
ERR_NO_STORAGE_VOL = ErrorNumber(C.VIR_ERR_NO_STORAGE_VOL)
// failed to start node driver
WAR_NO_NODE = ErrorNumber(C.VIR_WAR_NO_NODE)
// invalid node device object
ERR_INVALID_NODE_DEVICE = ErrorNumber(C.VIR_ERR_INVALID_NODE_DEVICE)
// node device not found
ERR_NO_NODE_DEVICE = ErrorNumber(C.VIR_ERR_NO_NODE_DEVICE)
// security model not found
ERR_NO_SECURITY_MODEL = ErrorNumber(C.VIR_ERR_NO_SECURITY_MODEL)
// operation is not applicable at this time
ERR_OPERATION_INVALID = ErrorNumber(C.VIR_ERR_OPERATION_INVALID)
// failed to start interface driver
WAR_NO_INTERFACE = ErrorNumber(C.VIR_WAR_NO_INTERFACE)
// interface driver not running
ERR_NO_INTERFACE = ErrorNumber(C.VIR_ERR_NO_INTERFACE)
// invalid interface object
ERR_INVALID_INTERFACE = ErrorNumber(C.VIR_ERR_INVALID_INTERFACE)
// more than one matching interface found
ERR_MULTIPLE_INTERFACES = ErrorNumber(C.VIR_ERR_MULTIPLE_INTERFACES)
// failed to start nwfilter driver
WAR_NO_NWFILTER = ErrorNumber(C.VIR_WAR_NO_NWFILTER)
// invalid nwfilter object
ERR_INVALID_NWFILTER = ErrorNumber(C.VIR_ERR_INVALID_NWFILTER)
// nw filter pool not found
ERR_NO_NWFILTER = ErrorNumber(C.VIR_ERR_NO_NWFILTER)
// nw filter pool not found
ERR_BUILD_FIREWALL = ErrorNumber(C.VIR_ERR_BUILD_FIREWALL)
// failed to start secret storage
WAR_NO_SECRET = ErrorNumber(C.VIR_WAR_NO_SECRET)
// invalid secret
ERR_INVALID_SECRET = ErrorNumber(C.VIR_ERR_INVALID_SECRET)
// secret not found
ERR_NO_SECRET = ErrorNumber(C.VIR_ERR_NO_SECRET)
// unsupported configuration construct
ERR_CONFIG_UNSUPPORTED = ErrorNumber(C.VIR_ERR_CONFIG_UNSUPPORTED)
// timeout occurred during operation
ERR_OPERATION_TIMEOUT = ErrorNumber(C.VIR_ERR_OPERATION_TIMEOUT)
// a migration worked, but making the VM persist on the dest host failed
ERR_MIGRATE_PERSIST_FAILED = ErrorNumber(C.VIR_ERR_MIGRATE_PERSIST_FAILED)
// a synchronous hook script failed
ERR_HOOK_SCRIPT_FAILED = ErrorNumber(C.VIR_ERR_HOOK_SCRIPT_FAILED)
// invalid domain snapshot
ERR_INVALID_DOMAIN_SNAPSHOT = ErrorNumber(C.VIR_ERR_INVALID_DOMAIN_SNAPSHOT)
// domain snapshot not found
ERR_NO_DOMAIN_SNAPSHOT = ErrorNumber(C.VIR_ERR_NO_DOMAIN_SNAPSHOT)
// stream pointer not valid
ERR_INVALID_STREAM = ErrorNumber(C.VIR_ERR_INVALID_STREAM)
// valid API use but unsupported by the given driver
ERR_ARGUMENT_UNSUPPORTED = ErrorNumber(C.VIR_ERR_ARGUMENT_UNSUPPORTED)
// storage pool probe failed
ERR_STORAGE_PROBE_FAILED = ErrorNumber(C.VIR_ERR_STORAGE_PROBE_FAILED)
// storage pool already built
ERR_STORAGE_POOL_BUILT = ErrorNumber(C.VIR_ERR_STORAGE_POOL_BUILT)
// force was not requested for a risky domain snapshot revert
ERR_SNAPSHOT_REVERT_RISKY = ErrorNumber(C.VIR_ERR_SNAPSHOT_REVERT_RISKY)
// operation on a domain was canceled/aborted by user
ERR_OPERATION_ABORTED = ErrorNumber(C.VIR_ERR_OPERATION_ABORTED)
// authentication cancelled
ERR_AUTH_CANCELLED = ErrorNumber(C.VIR_ERR_AUTH_CANCELLED)
// The metadata is not present
ERR_NO_DOMAIN_METADATA = ErrorNumber(C.VIR_ERR_NO_DOMAIN_METADATA)
// Migration is not safe
ERR_MIGRATE_UNSAFE = ErrorNumber(C.VIR_ERR_MIGRATE_UNSAFE)
// integer overflow
ERR_OVERFLOW = ErrorNumber(C.VIR_ERR_OVERFLOW)
// action prevented by block copy job
ERR_BLOCK_COPY_ACTIVE = ErrorNumber(C.VIR_ERR_BLOCK_COPY_ACTIVE)
// The requested operation is not supported
ERR_OPERATION_UNSUPPORTED = ErrorNumber(C.VIR_ERR_OPERATION_UNSUPPORTED)
// error in ssh transport driver
ERR_SSH = ErrorNumber(C.VIR_ERR_SSH)
// guest agent is unresponsive, not running or not usable
ERR_AGENT_UNRESPONSIVE = ErrorNumber(C.VIR_ERR_AGENT_UNRESPONSIVE)
// resource is already in use
ERR_RESOURCE_BUSY = ErrorNumber(C.VIR_ERR_RESOURCE_BUSY)
// operation on the object/resource was denied
ERR_ACCESS_DENIED = ErrorNumber(C.VIR_ERR_ACCESS_DENIED)
// error from a dbus service
ERR_DBUS_SERVICE = ErrorNumber(C.VIR_ERR_DBUS_SERVICE)
// the storage vol already exists
ERR_STORAGE_VOL_EXIST = ErrorNumber(C.VIR_ERR_STORAGE_VOL_EXIST)
// given CPU is incompatible with host CPU
ERR_CPU_INCOMPATIBLE = ErrorNumber(C.VIR_ERR_CPU_INCOMPATIBLE)
// XML document doesn't validate against schema
ERR_XML_INVALID_SCHEMA = ErrorNumber(C.VIR_ERR_XML_INVALID_SCHEMA)
// Finish API succeeded but it is expected to return NULL */
ERR_MIGRATE_FINISH_OK = ErrorNumber(C.VIR_ERR_MIGRATE_FINISH_OK)
// authentication unavailable
ERR_AUTH_UNAVAILABLE = ErrorNumber(C.VIR_ERR_AUTH_UNAVAILABLE)
// Server was not found
ERR_NO_SERVER = ErrorNumber(C.VIR_ERR_NO_SERVER)
// Client was not found
ERR_NO_CLIENT = ErrorNumber(C.VIR_ERR_NO_CLIENT)
// guest agent replies with wrong id to guest sync command
ERR_AGENT_UNSYNCED = ErrorNumber(C.VIR_ERR_AGENT_UNSYNCED)
// error in libssh transport driver
ERR_LIBSSH = ErrorNumber(C.VIR_ERR_LIBSSH)
// libvirt fail to find the desired device
ERR_DEVICE_MISSING = ErrorNumber(C.VIR_ERR_DEVICE_MISSING)
// Invalid nwfilter binding object
ERR_INVALID_NWFILTER_BINDING = ErrorNumber(C.VIR_ERR_INVALID_NWFILTER_BINDING)
// Requested nwfilter binding does not exist
ERR_NO_NWFILTER_BINDING = ErrorNumber(C.VIR_ERR_NO_NWFILTER_BINDING)
// invalid domain checkpoint
ERR_INVALID_DOMAIN_CHECKPOINT = ErrorNumber(C.VIR_ERR_INVALID_DOMAIN_CHECKPOINT)
// domain checkpoint not found
ERR_NO_DOMAIN_CHECKPOINT = ErrorNumber(C.VIR_ERR_NO_DOMAIN_CHECKPOINT)
// domain backup job id not found *
ERR_NO_DOMAIN_BACKUP = ErrorNumber(C.VIR_ERR_NO_DOMAIN_BACKUP)
// invalid network port object
ERR_INVALID_NETWORK_PORT = ErrorNumber(C.VIR_ERR_INVALID_NETWORK_PORT)
// network port already exists
ERR_NETWORK_PORT_EXIST = ErrorNumber(C.VIR_ERR_NETWORK_PORT_EXIST)
// network port not found
ERR_NO_NETWORK_PORT = ErrorNumber(C.VIR_ERR_NO_NETWORK_PORT)
// no domain's hostname found
ERR_NO_HOSTNAME = ErrorNumber(C.VIR_ERR_NO_HOSTNAME)
// checkpoint is inconsistent
ERR_CHECKPOINT_INCONSISTENT = ErrorNumber(C.VIR_ERR_CHECKPOINT_INCONSISTENT)
// more than one matching domain found
ERR_MULTIPLE_DOMAINS = ErrorNumber(C.VIR_ERR_MULTIPLE_DOMAINS)
)
type ErrorDomain int
const (
FROM_NONE = ErrorDomain(C.VIR_FROM_NONE)
// Error at Xen hypervisor layer
FROM_XEN = ErrorDomain(C.VIR_FROM_XEN)
// Error at connection with xend daemon
FROM_XEND = ErrorDomain(C.VIR_FROM_XEND)
// Error at connection with xen store
FROM_XENSTORE = ErrorDomain(C.VIR_FROM_XENSTORE)
// Error in the S-Expression code
FROM_SEXPR = ErrorDomain(C.VIR_FROM_SEXPR)
// Error in the XML code
FROM_XML = ErrorDomain(C.VIR_FROM_XML)
// Error when operating on a domain
FROM_DOM = ErrorDomain(C.VIR_FROM_DOM)
// Error in the XML-RPC code
FROM_RPC = ErrorDomain(C.VIR_FROM_RPC)
// Error in the proxy code; unused since 0.8.6
FROM_PROXY = ErrorDomain(C.VIR_FROM_PROXY)
// Error in the configuration file handling
FROM_CONF = ErrorDomain(C.VIR_FROM_CONF)
// Error at the QEMU daemon
FROM_QEMU = ErrorDomain(C.VIR_FROM_QEMU)
// Error when operating on a network
FROM_NET = ErrorDomain(C.VIR_FROM_NET)
// Error from test driver
FROM_TEST = ErrorDomain(C.VIR_FROM_TEST)
// Error from remote driver
FROM_REMOTE = ErrorDomain(C.VIR_FROM_REMOTE)
// Error from OpenVZ driver
FROM_OPENVZ = ErrorDomain(C.VIR_FROM_OPENVZ)
// Error at Xen XM layer
FROM_XENXM = ErrorDomain(C.VIR_FROM_XENXM)
// Error in the Linux Stats code
FROM_STATS_LINUX = ErrorDomain(C.VIR_FROM_STATS_LINUX)
// Error from Linux Container driver
FROM_LXC = ErrorDomain(C.VIR_FROM_LXC)
// Error from storage driver
FROM_STORAGE = ErrorDomain(C.VIR_FROM_STORAGE)
// Error from network config
FROM_NETWORK = ErrorDomain(C.VIR_FROM_NETWORK)
// Error from domain config
FROM_DOMAIN = ErrorDomain(C.VIR_FROM_DOMAIN)
// Error at the UML driver
FROM_UML = ErrorDomain(C.VIR_FROM_UML)
// Error from node device monitor
FROM_NODEDEV = ErrorDomain(C.VIR_FROM_NODEDEV)
// Error from xen inotify layer
FROM_XEN_INOTIFY = ErrorDomain(C.VIR_FROM_XEN_INOTIFY)
// Error from security framework
FROM_SECURITY = ErrorDomain(C.VIR_FROM_SECURITY)
// Error from VirtualBox driver
FROM_VBOX = ErrorDomain(C.VIR_FROM_VBOX)
// Error when operating on an interface
FROM_INTERFACE = ErrorDomain(C.VIR_FROM_INTERFACE)
// The OpenNebula driver no longer exists. Retained for ABI/API compat only
FROM_ONE = ErrorDomain(C.VIR_FROM_ONE)
// Error from ESX driver
FROM_ESX = ErrorDomain(C.VIR_FROM_ESX)
// Error from IBM power hypervisor
FROM_PHYP = ErrorDomain(C.VIR_FROM_PHYP)
// Error from secret storage
FROM_SECRET = ErrorDomain(C.VIR_FROM_SECRET)
// Error from CPU driver
FROM_CPU = ErrorDomain(C.VIR_FROM_CPU)
// Error from XenAPI
FROM_XENAPI = ErrorDomain(C.VIR_FROM_XENAPI)
// Error from network filter driver
FROM_NWFILTER = ErrorDomain(C.VIR_FROM_NWFILTER)
// Error from Synchronous hooks
FROM_HOOK = ErrorDomain(C.VIR_FROM_HOOK)
// Error from domain snapshot
FROM_DOMAIN_SNAPSHOT = ErrorDomain(C.VIR_FROM_DOMAIN_SNAPSHOT)
// Error from auditing subsystem
FROM_AUDIT = ErrorDomain(C.VIR_FROM_AUDIT)
// Error from sysinfo/SMBIOS
FROM_SYSINFO = ErrorDomain(C.VIR_FROM_SYSINFO)
// Error from I/O streams
FROM_STREAMS = ErrorDomain(C.VIR_FROM_STREAMS)
// Error from VMware driver
FROM_VMWARE = ErrorDomain(C.VIR_FROM_VMWARE)
// Error from event loop impl
FROM_EVENT = ErrorDomain(C.VIR_FROM_EVENT)
// Error from libxenlight driver
FROM_LIBXL = ErrorDomain(C.VIR_FROM_LIBXL)
// Error from lock manager
FROM_LOCKING = ErrorDomain(C.VIR_FROM_LOCKING)
// Error from Hyper-V driver
FROM_HYPERV = ErrorDomain(C.VIR_FROM_HYPERV)
// Error from capabilities
FROM_CAPABILITIES = ErrorDomain(C.VIR_FROM_CAPABILITIES)
// Error from URI handling
FROM_URI = ErrorDomain(C.VIR_FROM_URI)
// Error from auth handling
FROM_AUTH = ErrorDomain(C.VIR_FROM_AUTH)
// Error from DBus
FROM_DBUS = ErrorDomain(C.VIR_FROM_DBUS)
// Error from Parallels
FROM_PARALLELS = ErrorDomain(C.VIR_FROM_PARALLELS)
// Error from Device
FROM_DEVICE = ErrorDomain(C.VIR_FROM_DEVICE)
// Error from libssh2 connection transport
FROM_SSH = ErrorDomain(C.VIR_FROM_SSH)
// Error from lockspace
FROM_LOCKSPACE = ErrorDomain(C.VIR_FROM_LOCKSPACE)
// Error from initctl device communication
FROM_INITCTL = ErrorDomain(C.VIR_FROM_INITCTL)
// Error from identity code
FROM_IDENTITY = ErrorDomain(C.VIR_FROM_IDENTITY)
// Error from cgroups
FROM_CGROUP = ErrorDomain(C.VIR_FROM_CGROUP)
// Error from access control manager
FROM_ACCESS = ErrorDomain(C.VIR_FROM_ACCESS)
// Error from systemd code
FROM_SYSTEMD = ErrorDomain(C.VIR_FROM_SYSTEMD)
// Error from bhyve driver
FROM_BHYVE = ErrorDomain(C.VIR_FROM_BHYVE)
// Error from crypto code
FROM_CRYPTO = ErrorDomain(C.VIR_FROM_CRYPTO)
// Error from firewall
FROM_FIREWALL = ErrorDomain(C.VIR_FROM_FIREWALL)
// Erorr from polkit code
FROM_POLKIT = ErrorDomain(C.VIR_FROM_POLKIT)
// Error from thread utils
FROM_THREAD = ErrorDomain(C.VIR_FROM_THREAD)
// Error from admin backend
FROM_ADMIN = ErrorDomain(C.VIR_FROM_ADMIN)
// Error from log manager
FROM_LOGGING = ErrorDomain(C.VIR_FROM_LOGGING)
// Error from Xen xl config code
FROM_XENXL = ErrorDomain(C.VIR_FROM_XENXL)
// Error from perf
FROM_PERF = ErrorDomain(C.VIR_FROM_PERF)
// Error from libssh
FROM_LIBSSH = ErrorDomain(C.VIR_FROM_LIBSSH)
// Error from resoruce control
FROM_RESCTRL = ErrorDomain(C.VIR_FROM_RESCTRL)
// Error from firewalld
FROM_FIREWALLD = ErrorDomain(C.VIR_FROM_FIREWALLD)
// Error from domain checkpoint
FROM_DOMAIN_CHECKPOINT = ErrorDomain(C.VIR_FROM_DOMAIN_CHECKPOINT)
// Error from TPM
FROM_TPM = ErrorDomain(C.VIR_FROM_TPM)
// Error from BPF
FROM_BPF = ErrorDomain(C.VIR_FROM_BPF)
)
type Error struct {
Code ErrorNumber
Domain ErrorDomain
Message string
Level ErrorLevel
}
func (err Error) Error() string {
return fmt.Sprintf("virError(Code=%d, Domain=%d, Message='%s')",
err.Code, err.Domain, err.Message)
}
func (err Error) Is(target error) bool {
n, ok := target.(ErrorNumber)
if !ok {
return false
}
return err.Code == n
}
func makeError(err *C.virError) Error {
ret := Error{
Code: ErrorNumber(err.code),
Domain: ErrorDomain(err.domain),
Message: C.GoString(err.message),
Level: ErrorLevel(err.level),
}
C.virResetError(err)
return ret
}
func makeNotImplementedError(apiname string) Error {
return Error{
Code: ERR_NO_SUPPORT,
Domain: FROM_NONE,
Message: fmt.Sprintf("Function '%s' not available in the libvirt library used during Go build", apiname),
Level: ERR_ERROR,
}
}