| 1 | // error names preserve the public API; messages follow pacman lib/libalpm/error.c. |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | module engine |
| 4 | |
| 5 | pub enum Errno { |
| 6 | ok = 0 |
| 7 | memory |
| 8 | system |
| 9 | badperms |
| 10 | not_a_file |
| 11 | not_a_dir |
| 12 | wrong_args |
| 13 | disk_space |
| 14 | handle_null |
| 15 | handle_not_null |
| 16 | handle_lock |
| 17 | db_open |
| 18 | db_create |
| 19 | db_null |
| 20 | db_not_null |
| 21 | db_not_found |
| 22 | db_invalid |
| 23 | db_invalid_sig |
| 24 | db_version |
| 25 | db_write |
| 26 | db_remove |
| 27 | server_bad_url |
| 28 | server_none |
| 29 | trans_not_null |
| 30 | trans_null |
| 31 | trans_dup_target |
| 32 | trans_dup_filename |
| 33 | trans_not_initialized |
| 34 | trans_not_prepared |
| 35 | trans_abort |
| 36 | trans_type |
| 37 | trans_not_locked |
| 38 | trans_hook_failed |
| 39 | pkg_not_found |
| 40 | pkg_ignored |
| 41 | pkg_invalid |
| 42 | pkg_invalid_checksum |
| 43 | pkg_invalid_sig |
| 44 | pkg_missing_sig |
| 45 | pkg_open |
| 46 | pkg_cant_remove |
| 47 | pkg_invalid_name |
| 48 | pkg_invalid_arch |
| 49 | sig_missing |
| 50 | sig_invalid |
| 51 | unsatisfied_deps |
| 52 | conflicting_deps |
| 53 | file_conflicts |
| 54 | retrieve_prepare |
| 55 | retrieve |
| 56 | invalid_regex |
| 57 | libarchive |
| 58 | libcurl |
| 59 | external_download |
| 60 | gpgme |
| 61 | missing_capability_signatures |
| 62 | } |
| 63 | |
| 64 | pub fn (kind Errno) strerror() string { |
| 65 | message := match kind { |
| 66 | .ok { 'unexpected error' } |
| 67 | .memory { 'out of memory!' } |
| 68 | .system { 'unexpected system error' } |
| 69 | .badperms { 'permission denied' } |
| 70 | .not_a_file { 'could not find or read file' } |
| 71 | .not_a_dir { 'could not find or read directory' } |
| 72 | .wrong_args { 'wrong or NULL argument passed' } |
| 73 | .disk_space { 'not enough free disk space' } |
| 74 | .handle_null { 'library not initialized' } |
| 75 | .handle_not_null { 'library already initialized' } |
| 76 | .handle_lock { 'unable to lock database' } |
| 77 | .db_open { 'could not open database' } |
| 78 | .db_create { 'could not create database' } |
| 79 | .db_null { 'database not initialized' } |
| 80 | .db_not_null { 'database already registered' } |
| 81 | .db_not_found { 'could not find database' } |
| 82 | .db_invalid { 'invalid or corrupted database' } |
| 83 | .db_invalid_sig { 'invalid or corrupted database (PGP signature)' } |
| 84 | .db_version { 'database is incorrect version' } |
| 85 | .db_write { 'could not update database' } |
| 86 | .db_remove { 'could not remove database entry' } |
| 87 | .server_bad_url { 'invalid url for server' } |
| 88 | .server_none { 'no servers configured for repository' } |
| 89 | .trans_not_null { 'transaction already initialized' } |
| 90 | .trans_null { 'transaction not initialized' } |
| 91 | .trans_dup_target { 'duplicate target' } |
| 92 | .trans_dup_filename { 'duplicate filename' } |
| 93 | .trans_not_initialized { 'transaction not initialized' } |
| 94 | .trans_not_prepared { 'transaction not prepared' } |
| 95 | .trans_abort { 'transaction aborted' } |
| 96 | .trans_type { 'operation not compatible with the transaction type' } |
| 97 | .trans_not_locked { 'transaction commit attempt when database is not locked' } |
| 98 | .trans_hook_failed { 'failed to run transaction hooks' } |
| 99 | .pkg_not_found { 'could not find or read package' } |
| 100 | .pkg_ignored { 'operation cancelled due to ignorepkg' } |
| 101 | .pkg_invalid { 'invalid or corrupted package' } |
| 102 | .pkg_invalid_checksum { 'invalid or corrupted package (checksum)' } |
| 103 | .pkg_invalid_sig { 'invalid or corrupted package (PGP signature)' } |
| 104 | .pkg_missing_sig { 'package missing required signature' } |
| 105 | .pkg_open { 'cannot open package file' } |
| 106 | .pkg_cant_remove { 'cannot remove all files for package' } |
| 107 | .pkg_invalid_name { 'package filename is not valid' } |
| 108 | .pkg_invalid_arch { 'package architecture is not valid' } |
| 109 | .sig_missing { 'missing PGP signature' } |
| 110 | .sig_invalid { 'invalid PGP signature' } |
| 111 | .unsatisfied_deps { 'could not satisfy dependencies' } |
| 112 | .conflicting_deps { 'conflicting dependencies' } |
| 113 | .file_conflicts { 'conflicting files' } |
| 114 | .retrieve_prepare { 'failed to initialize download' } |
| 115 | .retrieve { 'failed to retrieve some files' } |
| 116 | .invalid_regex { 'invalid regular expression' } |
| 117 | .libarchive { 'libarchive error' } |
| 118 | .libcurl { 'download library error' } |
| 119 | .external_download { 'error invoking external downloader' } |
| 120 | .gpgme { 'gpgme error' } |
| 121 | .missing_capability_signatures { 'compiled without signature support' } |
| 122 | else { 'unexpected error' } |
| 123 | } |
| 124 | return translated_message(message) |
| 125 | } |
| 126 | |
| 127 | pub struct AlpmError { |
| 128 | pub: |
| 129 | kind Errno |
| 130 | detail string |
| 131 | } |
| 132 | |
| 133 | pub fn (problem AlpmError) msg() string { |
| 134 | return if problem.detail == '' { |
| 135 | problem.kind.strerror() |
| 136 | } else { |
| 137 | problem.kind.strerror() + ': ' + problem.detail |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | pub fn (problem AlpmError) code() int { |
| 142 | return int(problem.kind) |
| 143 | } |
| 144 | |