api_errors.py revision 2219
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
import errno
import os
import urlparse
# EmptyI for argument defaults; can't import from misc due to circular
# dependency.
class ApiException(Exception):
self.__verbose_info = []
def __unicode__(self):
# To workaround python issues 6108 and 2517, this provides a
# a standard wrapper for this class' exceptions so that they
# have a chance of being stringified correctly.
def verbose_info(self):
return self.__verbose_info
class ImageLockedError(ApiException):
"""Used to indicate that the image is currently locked by another thread
or process and cannot be modified."""
return _("The image cannot be modified as it is "
"currently in use by another package client: "
"%(pid_name)s on %(host)s, pid %(pid)s.") % {
return _("The image cannot be modified as it is "
"currently in use by another package client: "
"%(pid_name)s on an unknown host, pid %(pid)s.") % {
return _("The image cannot be modified as it is "
"currently in use by another package client: "
"pid %(pid)s on %(host)s.") % {
return _("The image cannot be modified as it is currently "
"in use by another package client.")
class ImageNotFoundException(ApiException):
"""Used when an image was not found"""
class ImageLocationAmbiguous(ApiException):
"""Used to indicate that an image was found at a location other than
'/' on the Solaris platform when requesting automatic image location
discovery. Clients should trap this exception and add their own
messaging telling the user how to specify an image root explicitly
for the location."""
return _("pkg(5) image found at '%(found)s' instead of "
class ImageFormatUpdateNeeded(ApiException):
"""Used to indicate that an image cannot be used until its format is
updated."""
return _("The image rooted at %s is written in an older format "
"and must be updated before the requested operation can be "
class VersionException(ApiException):
class PlanExistsException(ApiException):
class PlanPrepareException(ApiException):
"""Base exception class for plan preparation errors."""
pass
class InvalidPackageErrors(ApiException):
"""Used to indicate that the requested operation could not be completed
as one or more packages contained invalid metadata."""
"""'errors' should be a list of exceptions or strings
indicating what packages had errors and why."""
return _("The requested operation cannot be completed due "
"to invalid package metadata. Details follow:\n\n"
class LicenseAcceptanceError(ApiException):
"""Used to indicate that license-related errors occurred during
plan evaluation or execution."""
displayed=None):
class PkgLicenseErrors(PlanPrepareException):
"""Used to indicate that plan evaluation or execution failed due
to license-related errors for a package."""
"""'errors' should be a list of LicenseAcceptanceError
exceptions."""
"""A list of LicenseAcceptanceError exceptions."""
"""Used to indicate that image plan evaluation or execution failed due
to license-related errors."""
"""'errors' should be a list of PkgLicenseErrors exceptions."""
"""Returns a dictionary indexed by package FMRI string of
lists of LicenseAcceptanceError exceptions."""
"""Returns a string representation of the license errors."""
output = ""
output += _(" License requires "
"acceptance.")
output += _(" License must be viewed.")
output += "\n"
return output
class ActuatorException(ApiException):
pass
pass
class AlreadyExecutedException(ApiException):
pass
class ImageplanStateException(ApiException):
class InvalidPlanError(ApiException):
"""Used to indicate that the image plan is no longer valid, likely as a
result of an image state change since the plan was created."""
return _("The plan for the current operation is no longer "
"valid. The image has likely been modified by another "
"process or client. Please try the operation again.")
class ImagePkgStateError(ApiException):
return _("Invalid package state change attempted '%(states)s' "
class IpkgOutOfDateException(ApiException):
pass
pass
pass
class CanceledException(ApiException):
pass
class PlanMissingException(ApiException):
pass
pass
class PermissionsException(ApiException):
return _("Could not operate on %s\nbecause of "
"insufficient permissions. Please try the "
"command again as a privileged user.") % \
else:
return _("""
Could not complete the operation because of insufficient permissions.
Please try the command again as a privileged user.
""")
assert path
return _("Could not operate on %s\nbecause the file is "
"in use. Please stop using the file and try the\n"
"""Used to indicate that the operation was attempted on a
read-only filesystem"""
return _("Could not complete the operation on %s: "
return _("Could not complete the operation: read-only "
"filesystem.")
class PlanCreationException(ApiException):
res = []
if self.unmatched_fmris:
s = _("""\
The following pattern(s) did not match any packages in the current catalog.
res += [s]
if self.wrong_variants:
s = _("""\
The following pattern(s) only matched packages that are not available
res += [s]
if self.wrong_publishers:
s = _("The following patterns only matched packages "
"that are from publishers other than that which "
"supplied the already installed version of this package")
res += [s]
if self.multiple_matches:
s = _("'%s' matches multiple packages")
if self.missing_matches:
s = _("'%s' matches no installed packages")
s = _("'%s' is an illegal fmri")
s = _("'%s' supports the following architectures: %s")
a = _("Image architecture is defined as: %s")
s = _("'%(p)s' depends on obsolete package '%(op)s'")
s = _("The proposed operation can not be performed for "
"the following package(s) as they are already "
"installed: ")
res += [s]
s = _("The following different patterns specify the"
"same package(s):")
res += [s]
res += [
", ".join(
+ ": %s" % t[0]
]
if self.no_solution:
res += [_("No solution was found to satisfy constraints")]
if self.no_version:
res += [_("Package %(pkg)s is missing a dependency: "
"%(dep)s") %
res += [_("The following files are not packaged in this image:")]
if self.solver_errors:
res += ["\n"]
res += [_("Solver dependency errors:")]
class ConflictingActionError(ApiException):
"""Used to indicate that the imageplan would result in one or more sets
of conflicting actions, meaning that more than one action would exist on
the system with the same key attribute value in the same namespace.
There are three categories, each with its own subclass:
- multiple files delivered to the same path or drivers, users, groups,
etc, delivered with the same key attribute;
- multiple objects delivered to the same path which aren't the same
type;
- multiple directories, links, or hardlinks delivered to the same path
but with conflicting attributes.
"""
class ConflictingActionErrors(ApiException):
"""A container for multiple ConflictingActionError exception objects
that can be raised as a single exception."""
"""Multiple actions of the same type have been delivered with the same
key attribute (when not allowed)."""
s = _("The following packages all deliver %(action)s "
"actions to %(kv)s:\n") % locals()
s += "\n %s" % p
s += _("\n\nThese packages may not be installed together. "
"Any non-conflicting set may\nbe, or the packages "
"must be corrected before they can be installed.")
else:
s = _("The package %(pfmri)s delivers multiple copies "
"of %(action)s %(kv)s") % locals()
s += _("\nThis package must be corrected before it "
"can be installed.")
return s
"""Multiple actions of different types have been delivered with the same
'path' attribute. While this exception could represent other action
groups which share a single namespace, none such exist."""
ad = {}
s = _("The following packages deliver conflicting "
"action types to %s:\n") % kv
s += "\n %s:" % name
s += _("\n\nThese packages may not be installed together. "
"Any non-conflicting set may\nbe, or the packages "
"must be corrected before they can be installed.")
else:
s = _("The package %(pfmri)s delivers conflicting "
"action types (%(types)s) to %(kv)s") % locals()
s += _("\nThis package must be corrected before it "
"can be installed.")
return s
"""Multiple actions of the same type representing the same object have
have been delivered, but with conflicting attributes, such as two
directories at /usr with groups 'root' and 'sys', or two 'root' users
with uids '0' and '7'."""
# Trim the action's attributes to only those required to be
# unique.
(k, v)
if k in action.unique_attrs
)
return action
d = {}
for a in actions:
l = sorted([
])
s = _("The requested change to the system attempts to install "
"multiple actions\nfor %(a)s '%(k)s' with conflicting "
if num <= 5:
if num == 1:
t = _(" %(n)d package delivers '%(a)s':\n")
else:
t = _(" %(n)d packages deliver '%(a)s':\n")
s += _(" %s\n") % pkg
else:
t = _(" %d packages deliver '%s', including:\n")
s += _(" %s\n") % pkg
s += _("\n\nThis package must be corrected before it "
"can be installed.")
else:
s += _("\n\nThese packages may not be installed together."
" Any non-conflicting set may\nbe, or the packages "
"must be corrected before they can be installed.")
return s
def list_to_lang(l):
"""Takes a list of items and puts them into a string, with commas in
between items, and an "and" between the last two items. Special cases
for lists of two or fewer items, and uses the Oxford comma."""
if not l:
return ""
if len(l) == 1:
return l[0]
if len(l) == 2:
# Used for a two-element list
return _("%(penultimate)s and %(ultimate)s") % {
"penultimate": l[0],
"ultimate": l[1]
}
# In order to properly i18n this construct, we create two templates:
# one for each element save the last, and one that tacks on the last
# element.
# 'elementtemplate' is for each element through the penultimate
elementtemplate = _("%s, ")
# 'listtemplate' concatenates the concatenation of non-ultimate elements
# and the ultimate element.
listtemplate = _("%(list)sand %(tail)s")
return listtemplate % {
"tail": l[-1]
}
class ActionExecutionError(ApiException):
"""Used to indicate that action execution (such as install, remove,
etc.) failed even though the action is valid.
In particular, this exception indicates that something went wrong in the
application (or unapplication) of the action to the system, and is most
likely not an error in the pkg(5) code."""
use_errno=None):
"""'action' is the object for the action that failed during the
requested operation.
'details' is an optional message explaining what operation
failed, why it failed, and why it cannot continue. It should
also include a suggestion as to how to resolve the situation
if possible.
'error' is an optional exception object that may have been
raised when the operation failed.
'fmri' is an optional package FMRI indicating what package
was being operated on at the time the error occurred.
'use_errno' is an optional boolean value indicating whether
the strerror() text of the exception should be used. If
'details' is provided, the default value is False, otherwise
True."""
if use_errno == None:
# If details were provided, don't use errno unless
# explicitly requested.
errno = ""
# Fall back on the wrapped exception if we don't have anything
# useful.
details = _("Requested operation failed for action "
"%(action)s:\n%(details)s") % {
"details": details }
elif details:
details = _("Requested operation failed for package "
"details": details }
# If we only have one of the two, no need for the colon.
class CatalogRefreshException(ApiException):
class CatalogError(ApiException):
"""Base exception class for all catalog exceptions."""
if args:
else:
class AnarchicalCatalogFMRI(CatalogError):
"""Used to indicate that the specified FMRI is not valid for catalog
operations because it is missing publisher information."""
return _("The FMRI '%s' does not contain publisher information "
class BadCatalogMetaRoot(CatalogError):
"""Used to indicate an operation on the catalog's meta_root failed
because the meta_root is invalid."""
return _("Catalog meta_root '%(root)s' is invalid; unable "
class BadCatalogPermissions(CatalogError):
"""Used to indicate the server catalog files do not have the expected
permissions."""
"""files should contain a list object with each entry consisting
of a tuple of filename, expected_mode, received_mode."""
if not files:
files = []
msg = _("The following catalog files have incorrect "
"permissions:\n")
msg += _("\t%(fname)s: expected mode: %(emode)s, found "
return msg
class BadCatalogSignatures(CatalogError):
"""Used to indicate that the Catalog signatures are not valid."""
return _("The signature data for the '%s' catalog file is not "
class BadCatalogUpdateIdentity(CatalogError):
"""Used to indicate that the requested catalog updates could not be
applied as the new catalog data is significantly different such that
the old catalog cannot be updated to match it."""
return _("Unable to determine the updates needed for "
"the current catalog using the provided catalog "
class DuplicateCatalogEntry(CatalogError):
"""Used to indicate that the specified catalog operation could not be
performed since it would result in a duplicate catalog entry."""
return _("Unable to perform '%(op)s' operation for catalog "
"%(name)s; completion would result in a duplicate entry "
"""Used to indicate that an update request for the catalog could not
be performed because update requirements were not satisfied."""
return _("Catalog updates can only be applied to an on-disk "
"catalog.")
class InvalidCatalogFile(CatalogError):
"""Used to indicate a Catalog file could not be loaded."""
class MismatchedCatalog(CatalogError):
"""Used to indicate that a Catalog's attributes and parts do not
match. This is likely the result of an attributes file being
retrieved which doesn't match the parts that were retrieved such
as in a misconfigured or stale cache case."""
return _("The content of the catalog for publisher '%s' "
"doesn't match the catalog's attributes. This is "
"likely the result of a mix of older and newer "
"catalog files being provided for the publisher.") % \
class ObsoleteCatalogUpdate(CatalogError):
"""Used to indicate that the specified catalog updates are for an older
version of the catalog and cannot be applied."""
return _("Unable to determine the updates needed for the "
"catalog using the provided catalog update data in '%s'. "
"The specified catalog updates are for an older version "
class UnknownCatalogEntry(CatalogError):
"""Used to indicate that an entry for the specified package FMRI or
pattern could not be found in the catalog."""
class UnknownUpdateType(CatalogError):
"""Used to indicate that the specified CatalogUpdate operation is
unknown."""
class UnrecognizedCatalogPart(CatalogError):
"""Raised when the catalog finds a CatalogPart that is unrecognized
or invalid."""
return _("Unrecognized, unknown, or invalid CatalogPart '%s'") \
class InventoryException(ApiException):
"""Used to indicate that some of the specified patterns to a catalog
matching function did not match any catalog entries, or were invalid
patterns."""
outstr = ""
# Illegal FMRIs have their own __str__ method
outstr += "%s\n" % x
outstr += _("No matching package could be found for "
"the following FMRIs in any of the catalogs for "
"the current publishers:\n")
outstr += _("%s (pattern did not match)\n") % x
outstr += _("%s (publisher did not "
"match)\n") % x
outstr += _("%s (version did not match)\n") % x
return outstr
# SearchExceptions
class SearchException(ApiException):
"""Based class used for all search-related api exceptions."""
pass
"""Raised when the server cannot understand the format of the
search request."""
class NegativeSearchResult(SearchException):
"""Returned when the search cannot find any matches."""
"""This class wraps exceptions which could appear while trying to
do a search request."""
s = _("Some repositories failed to respond appropriately:\n")
s += _("%(o)s:\n%(msg)s\n") % \
s += _("%s did not return a valid response.\n" \
% pub)
s += _("Some repositories don't support requested "
"search operation:\n")
s += _("%(o)s:\n%(msg)s\n") % \
return s
class SlowSearchUsed(SearchException):
"""This exception is thrown when a local search is performed without
an index. It's raised after all results have been yielded."""
return _("Search performance is degraded.\n"
"Run 'pkg rebuild-index' to improve search speed.")
"""Returned when a search protocol is not supported by the
remote server."""
s = _("Search repository does not support the requested "
"protocol:")
return s
return -1
if r != 0:
return r
# IndexingExceptions.
class IndexingException(SearchException):
""" The base class for all exceptions that can occur while indexing. """
"""This is used when the index is not in a correct state."""
pass
"""This is used when the existing index is found to have inconsistent
versions."""
"""This is used when an attempt to modify an index locked by another
process or thread is made."""
""" This is used when the indexer is unable to create, move, or remove
files or directories it should be able to. """
return "Could not remove or create " \
"%s because of incorrect " \
"permissions. Please correct this issue then " \
class WrapIndexingException(ApiException):
"""This exception is used to wrap an indexing exception during install,
uninstall, or update so that a more appropriate error message can be
displayed to the user."""
"""This exception is used to wrap an indexing exception during install,
uninstall, or update which was recovered from by performing a full
reindex."""
pass
# Query Parsing Exceptions
class BooleanQueryException(ApiException):
"""This exception is used when the children of a boolean operation
have different return types. The command 'pkg search foo AND <bar>'
is the simplest example of this."""
self.e = e
class ParseError(ApiException):
self.e = e
class NonLeafPackageException(ApiException):
"""Removal of a package which satisfies dependencies has been attempted.
The first argument to the constructor is the FMRI which we tried to
remove, and is available as the "fmri" member of the exception. The
second argument is the list of dependent packages that prevent the
removal of the package, and is available as the "dependents" member.
"""
def _str_autofix(self):
s = _("\nThis is happening because the following "
"packages needed to be repaired as\npart of this "
"operation:\n\n ")
s += _("\n\nYou will need to reestablish your access to the "
"repository or remove the\npackages in the list above.")
return s
return ""
"""Raised when the depot doesn't have versions of operations
that the client needs to operate successfully."""
s = _("Unable to contact valid package repository")
s += ("\nEncountered the following error(s):\n%s") % \
s += _str_autofix(self)
return s
class DataError(ApiException):
"""Base exception class used for all data related errors."""
if args:
else:
class InvalidP5IFile(DataError):
"""Used to indicate that the specified location does not contain a
valid p5i-formatted file."""
return _("The provided p5i data is in an unrecognized "
"format or does not contain valid publisher "
return _("The provided p5i data is in an unrecognized format "
"or does not contain valid publisher information.")
class UnsupportedP5IFile(DataError):
"""Used to indicate that an attempt to read an unsupported version
of pkg(5) info file was attempted."""
return _("Unsupported pkg(5) publisher information data "
"format.")
class TransportError(ApiException):
"""Abstract exception class for all transport exceptions.
Specific transport exceptions should be implemented in the
transport code. Callers wishing to catch transport exceptions
should use this class. Subclasses must implement all methods
defined here that raise NotImplementedError."""
raise NotImplementedError()
def _str_autofix(self):
return _str_autofix(self)
class RetrievalError(ApiException):
"""Used to indicate that a a requested resource could not be
retrieved."""
return _("Error encountered while retrieving data from "
return _("Error encountered while retrieving data from: %s") % \
class InvalidResourceLocation(ApiException):
"""Used to indicate that an invalid transport location was provided."""
class BEException(ApiException):
class InvalidBENameException(BEException):
return _("'%s' is not a valid boot environment name.") % \
class DuplicateBEName(BEException):
"""Used to indicate that there is an existing boot environment
with this name"""
return _("The boot environment '%s' already exists.") % \
class BENamingNotSupported(BEException):
return _("""\
Boot environment naming during package install is not supported on this
version of OpenSolaris. Please update without the --be-name option.""")
class UnableToCopyBE(BEException):
return _("Unable to clone the current boot environment.")
class UnableToRenameBE(BEException):
d = {
}
return _("""\
A problem occurred while attempting to rename the boot environment
currently named %(orig)s to %(dest)s.""") % d
class UnableToMountBE(BEException):
return _("Unable to mount %(name)s at %(mt)s") % \
class BENameGivenOnDeadBE(BEException):
return _("""\
Naming a boot environment when operating on a non-live image is
not allowed.""")
s = _("Info does not recognize the following options:")
return s
class IncorrectIndexFileHash(ApiException):
"""This is used when the index hash value doesn't match the hash of the
packages installed in the image."""
pass
class PublisherError(ApiException):
"""Base exception class for all publisher exceptions."""
if args:
else:
class BadPublisherMetaRoot(PublisherError):
"""Used to indicate an operation on the publisher's meta_root failed
because the meta_root is invalid."""
return _("Publisher meta_root '%(root)s' is invalid; unable "
class BadPublisherAlias(PublisherError):
"""Used to indicate that a publisher alias is not valid."""
class BadPublisherPrefix(PublisherError):
"""Used to indicate that a publisher name is not valid."""
"""Used to indicate that the specified repository attribute value is
invalid."""
return _("'%(value)s' is not a valid value for repository "
"attribute '%(attribute)s'.") % {
"""Used to indicate that the specified repository collection type is
invalid."""
return _("'%s' is not a valid repository collection type.") % \
class BadRepositoryURI(PublisherError):
"""Used to indicate that a repository URI is not syntactically valid."""
"""Used to indicate that the priority specified for a repository URI is
not valid."""
return _("'%s' is not a valid URI priority; integer value "
"""Used to indicate that the specified repository URI sort policy is
invalid."""
return _("'%s' is not a valid repository URI sort policy.") % \
class DisabledPublisher(PublisherError):
"""Used to indicate that an attempt to use a disabled publisher occurred
during an operation."""
return _("Publisher '%s' is disabled and cannot be used for "
class DuplicatePublisher(PublisherError):
"""Used to indicate that a publisher with the same name or alias already
exists for an image."""
return _("A publisher with the same name or alias as '%s' "
class DuplicateRepository(PublisherError):
"""Used to indicate that a repository with the same origin uris
already exists for a publisher."""
return _("A repository with the same name or origin URIs "
"""Used to indicate that a repository URI is already in use by another
repository mirror."""
return _("Mirror '%s' already exists for the specified "
"""Used to indicate that a repository URI is already in use by another
repository origin."""
return _("Origin '%s' already exists for the specified "
"""Used to indicate that a Publisher has no repository information
configured and so transport operations cannot be performed."""
return _("Unable to retrieve requested package data for "
"publisher %s; no repositories are currently configured "
"""Used to indicate an attempt to remove the preferred publisher was
made."""
return _("The preferred publisher cannot be removed.")
class MoveRelativeToSelf(PublisherError):
"""Used to indicate an attempt to search a repo before or after itself"""
return _("Cannot search a repository before or after itself")
"""Used to indicate that an attempt to remove the selected repository
for a publisher was made."""
return _("Cannot remove the selected repository for a "
"publisher.")
"""Used to indicate an attempt to set a disabled publisher as the
preferred publisher was made."""
return _("Publisher '%s' is disabled and cannot be set as the "
"""Used to indicate that an attempt was made to set the preferred
publisher as disabled."""
return _("The preferred publisher may not be disabled."
" Another publisher must be set as the preferred "
"publisher before this publisher can be disabled.")
class UnknownLegalURI(PublisherError):
"""Used to indicate that no matching legal URI could be found using the
provided criteria."""
class UnknownPublisher(PublisherError):
"""Used to indicate that no matching publisher could be found using the
provided criteria."""
"""Used to indicate that one or more publisher prefixes are unknown by
the specified repository."""
return _("The repository at %(location)s does not "
"contain package data for %(unknown)s; only "
"%(known)s.\n\nThis is either because the "
"repository location is not valid, or because the "
"provided publisher does not match those known by "
"the repository.") % {
return _("One or more of the repository origin(s) "
"listed below contains package data for "
"%(known)s; not %(unknown)s:\n\n%(origins)s\n\n"
"This is either because one of the repository "
"origins is not valid for this publisher, or "
"because the list of known publishers retrieved "
"from the repository origin does not match the "
return _("The specified publisher repository does not "
"contain any package data for %(unknown)s; only "
class UnknownRelatedURI(PublisherError):
"""Used to indicate that no matching related URI could be found using
the provided criteria."""
class UnknownRepository(PublisherError):
"""Used to indicate that no matching repository could be found using the
provided criteria."""
"""Used to indicate that a repository URI could not be found in the
list of repository mirrors."""
"""The publisher has no active repositories that support the
requested operation."""
return _("Publisher '%s' has no repositories that support the"
"""Used to indicate that the specified repository does not provide
publisher configuration information."""
return _("The specified package repository does not "
"provide publisher configuration information.")
return _("The package repository at %s does not "
"provide publisher configuration information or "
"the information provided is incomplete.") % \
return _("One of the package repository origins for %s does "
"not provide publisher configuration information or the "
"""Used to indicate that a repository URI could not be found in the
list of repository origins."""
"""Used to indicate that the specified repository URI uses an
unsupported scheme."""
return _("The URI '%(uri)s' uses the unsupported "
"scheme '%(scheme)s'. Supported schemes are "
"file://, http://, and https://.") % {
return _("The specified URI uses an unsupported scheme."
" Supported schemes are: file://, http://, and https://.")
"""Used to indicate that the specified repository URI attribute is not
supported for the URI's scheme."""
return _("'%(attr)s' is not supported for '%(scheme)s'.") % {
class SigningException(ApiException):
"""The base class for exceptions related to manifest signing."""
# This string method is used by subclasses to fill in the details
# about the package and signature involved.
return _("The relevant signature action is "
"found in %(pfmri)s and has a hash of "
"%(hsh)s") % \
return _("The relevant signature action's value "
return ""
class BadFileFormat(SigningException):
"""Exception used when a key, certificate or CRL file is not in a
recognized format."""
"""Exception used when a signature reports a version which this version
of pkg(5) doesn't support."""
return _("The signature action %(act)s was made using a "
"version (%(ver)s) this version of pkg(5) doesn't "
class CertificateException(SigningException):
"""Base class for exceptions encountered while establishing the chain
of trust."""
"""Exception used when a certificate does not match its expected hash
value."""
return _("Certificate %s has been modified on disk. Its hash "
"""Exception used when a chain of trust is rooted in an untrusted
self-signed certificate."""
return _("Chain was rooted in an untrusted self-signed "
class BrokenChain(CertificateException):
"""Exception used when a chain of trust can not be established between
the leaf certificate and a trust anchor."""
s = ""
s = _("The following problems were encountered:\n") + \
return _("The certificate which issued this "
"certificate:%(subj)s could not be found. The issuer "
"""Exception used when a chain of trust contains a revoked certificate.
"""
return _("This certificate was revoked:%(cert)s for this "
class UnverifiedSignature(SigningException):
"""Exception used when a signature could not be verified by the
expected certificate."""
return _("A signature in %(pfmri)s could not be "
"verified for "
"this reason:\n%(reason)s\nThe signature's hash is "
return _("The signature with this signature value:\n"
"%(sigval)s\n could not be verified for this reason:\n"
"""Exception used when signatures were required but none were found."""
return _("The policy for %(pub_str)s requires "
"signatures to be present but no signature was "
"found in %(fmri_str)s.") % \
return _("The policy for %(pub_str)s requires signatures to be "
"present but no signature was found.") % {
"pub_str": pub_str}
"""Exception used when a signature policy required names to be seen
which weren't seen."""
return _("The policy for %(pub_str)s requires certain "
"CNs to be seen in a chain of trust. The following "
"required names couldn't be found for this "
"package:%(fmri_str)s.\n%(missing)s") % \
return _("The policy for %(pub_str)s requires certain CNs to "
"be seen in a chain of trust. The following required names "
"""Exception used when a certificate in the chain of trust uses a
critical extension pkg5 doesn't understand."""
return _("The certificate whose subject is %(cert)s could not "
"be verified "
"because it uses a critical extension that pkg5 cannot "
"handle yet.\nExtension name:%(name)s\nExtension "
"""Exception used when a certificate in the chain of trust has an
extension with a value pkg5 doesn't understand."""
s = _("The certificate whose subject is %(cert)s could not be "
"verified because it has an extension with a value that "
"pkg(5) does not understand."
"\nExtension name:%(name)s\nExtension value:%(val)s") % \
return s
"""Exception used when a certificate in the chain of trust has been used
inappropriately. An example would be a certificate which was only
supposed to be used to sign code being used to sign other certificates.
"""
return _("The certificate whose subject is %(cert)s could not "
"be verified because it has been used inappropriately. "
"The way it is used means that the value for extension "
"%(name)s must include '%(use)s' but the value was "
class InvalidPropertyValue(ApiException):
"""Exception used when a property was set to an invalid value."""
class CertificateError(ApiException):
"""Base exception class for all certificate exceptions."""
if args:
else:
class ExpiredCertificate(CertificateError):
"""Used to indicate that a certificate has expired."""
if publisher:
if uri:
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s' needed to access '%(uri)s', "
"has expired. Please install a valid "
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s', has expired. Please install a valid "
"pub": publisher }
if uri:
return _("Certificate '%(cert)s', needed to access "
"'%(uri)s', has expired. Please install a valid "
return _("Certificate '%s' has expired. Please install a "
class ExpiringCertificate(CertificateError):
"""Used to indicate that a certificate has expired."""
if publisher:
if uri:
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s', needed to access '%(uri)s', "
"will expire in '%(days)s' days.") % {
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s' will expire in '%(days)s' days.") % {
if uri:
return _("Certificate '%(cert)s', needed to access "
"'%(uri)s', will expire in '%(days)s' days.") % {
return _("Certificate '%(cert)s' will expire in "
class InvalidCertificate(CertificateError):
"""Used to indicate that a certificate is invalid."""
if publisher:
if uri:
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s', needed to access '%(uri)s', is "
return _("Certificate '%(cert)s' for publisher "
"pub": publisher }
if uri:
return _("Certificate '%(cert)s' needed to access "
"uri": uri }
class NoSuchKey(CertificateError):
"""Used to indicate that a key could not be found."""
if publisher:
if uri:
return _("Unable to locate key '%(key)s' for "
"publisher '%(pub)s' needed to access "
return _("Unable to locate key '%(key)s' for publisher "
}
if uri:
return _("Unable to locate key '%(key)s' needed to "
"uri": uri }
class NoSuchCertificate(CertificateError):
"""Used to indicate that a certificate could not be found."""
if publisher:
if uri:
return _("Unable to locate certificate "
"'%(cert)s' for publisher '%(pub)s' needed "
"to access '%(uri)s'.") % {
"uri": uri }
return _("Unable to locate certificate '%(cert)s' for "
"pub": publisher }
if uri:
return _("Unable to locate certificate '%(cert)s' "
"needed to access '%(uri)s'.") % {
"""Used to indicate that a certificate is not yet valid (future
effective date)."""
if publisher:
if uri:
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s', needed to access '%(uri)s', "
"has a future effective date.") % {
"uri": uri }
return _("Certificate '%(cert)s' for publisher "
"'%(pub)s' has a future effective date.") % {
if uri:
return _("Certificate '%(cert)s' needed to access "
"'%(uri)s' has a future effective date.") % {
return _("Certificate '%s' has a future effective date.") % \
class ServerReturnError(ApiException):
"""This exception is used when the server returns a line which the
client cannot parse correctly."""
"""This exception is used when a file was given as an argument but
no such file could be found."""
class ManifestError(ApiException):
"""Base exception class for all manifest exceptions."""
if args:
else:
class BadManifestSignatures(ManifestError):
"""Used to indicate that the Manifest signatures are not valid."""
return _("The signature data for the manifest of the "
return _("The signature data for the manifest is not valid.")
class UnknownErrors(ApiException):
"""Used to indicate that one or more exceptions were encountered.
This is intended for use with where multiple exceptions for multiple
files are encountered and the errors have been condensed into a
single exception and re-raised. One example case would be rmtree()
with shutil.Error."""
# Image creation exceptions
class ImageCreationException(ApiException):
raise NotImplementedError()
return _("there is already an image at: %s.\nTo override, use "
class ImageCfgEmptyError(ApiException):
"""Used to indicate that the image configuration is invalid."""
return _("The configuration data for the image rooted at "
class UnsupportedImageError(ApiException):
"""Used to indicate that the image at a specific location is in a format
not supported by this version of the pkg(5) API."""
return _("The image rooted at %s is invalid or is not "
"supported by this version of the packaging system.") % \
return _("the specified image path is not empty: %s.\nTo "
"""Converts the provided exception into an ApiException equivalent if
possible. Returns a new exception object if converted or the original
if not.
'ignored_errors' is an optional list of errno values for which None
should be returned.
"""
if not hasattr(e, "errno"):
return e
if e.errno in ignored_errors:
return None
return PermissionsException(e.filename)
return ReadOnlyFileSystemException(e.filename)
return e