Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve error codes and remove duplicities #182

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,44 +142,6 @@ constructor(
cause: Throwable? = null
) : KnownPrismError(message, cause) {

/**
* An implementation of the [ApolloError] class that represents an error caused by invalid mnemonic words.
* This error occurs when one or more mnemonic words are invalid in a PRISM API response.
*
* @param invalidWords The array of invalid mnemonic words.
* @property message The error message for this error, which is determined based on the presence of invalid words.
* If `invalidWords` is not null, the message will be "The following mnemonic words are invalid: [invalidWords]".
* If `invalidWords` is null, the message will be "The seed cannot be null".
*
* @see ApolloError
*/
class InvalidMnemonicWord
@JvmOverloads
constructor(
invalidWords: Array<String>? = null
) : ApolloError(
if (invalidWords.isNullOrEmpty()) {
"The following mnemonic words are invalid: $invalidWords"
} else {
"The seed cannot be null"
}
) {
override val code: Int
get() = 11
}

/**
* Class representing an error when the message string cannot be parsed to UTF8 data.
*
* @property code The error code for CouldNotParseMessageString, which is 12.
*
* @see ApolloError
*/
class CouldNotParseMessageString : ApolloError("Could not get UTF8 Data from message string") {
override val code: Int
get() = 12
}

/**
* A class representing an invalid JSON Web Key (JWK) error in the PRISM SDK.
*
Expand Down Expand Up @@ -212,24 +174,6 @@ constructor(
get() = 14
}

/**
* Represents an error indicating that a specific key curve is invalid.
*
* @param invalidCurve The invalid key curve.
* @param validCurves An array of valid key curves.
*
* @see ApolloError
*/
class InvalidSpecificKeyCurve(
invalidCurve: String,
validCurves: Array<String>
) : ApolloError(
"Invalid key curve $invalidCurve. Valid options are: ${validCurves.joinToString(", ")}"
) {
override val code: Int
get() = 14
}

/**
* Represents an error that occurs when an invalid key type is used.
*
Expand Down Expand Up @@ -272,18 +216,6 @@ constructor(
get() = 17
}

/**
* A class representing an error that occurs when an invalid seed is used.
*
* @param message The error message.
*
* @see ApolloError
*/
class InvalidSeed(message: String) : ApolloError(message) {
override val code: Int
get() = 18
}

/**
* Represents an error that occurs due to invalid raw data.
*
Expand All @@ -303,7 +235,7 @@ constructor(
*/
class RestorationFailedNoIdentifierOrInvalid : ApolloError("Restoration failed: no identifier or invalid") {
override val code: Int
get() = 20
get() = 110
}
}

Expand Down Expand Up @@ -432,28 +364,20 @@ constructor(
*
* @see CastorError
*/
class InvalidKeyError @JvmOverloads constructor(message: String? = null) : CastorError(message)
class InvalidKeyError @JvmOverloads constructor(message: String? = null) : CastorError(message) {
override val code: Int
get() = 29
}

/**
* An error that occurs when the provided PeerDID is invalid.
*
* @see CastorError
*/
class InvalidPeerDIDError @JvmOverloads constructor(message: String? = null, cause: Throwable? = null) :
CastorError(message, cause)

/**
* Class representing an error thrown when no resolvers are available to resolve a given DID method.
*
* @param method The method that couldn't be resolved.
*
* @see CastorError
*/
class NoResolversAvailableForDIDMethod(method: String) : CastorError(
"No resolvers in castor are able to resolve the method $method, please provide a resolver"
) {
CastorError(message, cause) {
override val code: Int
get() = 29
get() = 210
}

/**
Expand All @@ -467,7 +391,7 @@ constructor(
"Provided json cannot be parsed into DIDDocument. Missing field $field"
) {
override val code: Int
get() = 30
get() = 211
}

/**
Expand All @@ -481,7 +405,7 @@ constructor(
"$field is missing or null from $parent when it must be provided and not null."
) {
override val code: Int
get() = 30
get() = 212
}
}

Expand Down Expand Up @@ -561,42 +485,6 @@ constructor(
override val code: Int
get() = 35
}

/**
* A class representing an error that occurs when decoding a message with an invalid body.
*
* @see MercuryError
*/
class MessageInvalidBodyDataError : MercuryError(
"While decoding a message, a body was found to be invalid while decoding"
) {
override val code: Int
get() = 36
}

/**
* A class representing a DIDComm error in the PRISM SDK.
*
* @param customMessage The custom message associated with the error. Defaults to null.
* @param customUnderlyingErrors The array of underlying errors associated with the error.
*
* @see MercuryError
*/
class DidCommError
@JvmOverloads
constructor(
customMessage: String? = null,
customUnderlyingErrors: Array<Error>
) : MercuryError(
message = "DIDComm error has occurred with message: $customMessage\nErrors: ${
customUnderlyingErrors.joinToString(
separator = "\n"
) { it.errorDescription ?: "" }
}"
) {
override val code: Int
get() = 37
}
}

/**
Expand All @@ -611,67 +499,6 @@ constructor(
cause: Throwable? = null
) : KnownPrismError(message, cause) {

/**
* Represents an error that occurs when data is not persisted for a specific type while adding or making changes to another object.
*
* @param type The type of data that is not persisted.
* @param affecting The object to which the data is being added or modified.
*
* @see PlutoError
*/
class MissingDataPersistence(type: String, affecting: String) :
PlutoError("$type is not persisted while trying to add or make changes to $affecting") {
override val code: Int
get() = 41
}

/**
* Represents a specific error that occurs when required fields are missing.
*
* @param type The type that requires the fields.
* @param fields The array of missing fields.
*
* @see PlutoError
*/
class MissingRequiredFields(type: String, fields: Array<String>) :
PlutoError("$type requires the following fields: ${fields.joinToString(", ")}") {

override val code: Int
get() = 42
}

/**
* Represents a duplication error when trying to save an object with an existing ID.
*
* @param type The type of object that is being duplicated.
*
* @see PlutoError
*/
class Duplication(type: String) : PlutoError("Trying to save $type with an ID that already exists") {
override val code: Int
get() = 43
}

/**
* A class representing an unknown credential type error in the Pluto SDK.
*
* @see PlutoError
*/
class UnknownCredentialTypeError : PlutoError("The credential type needs to be JWT or W3C") {
override val code: Int
get() = 44
}

/**
* Represents an error that occurs when the credential JSON cannot be decoded.
*
* @see PlutoError
*/
class InvalidCredentialJsonError : PlutoError("Could not decode the credential JSON") {
override val code: Int
get() = 45
}

/**
* An error class representing a database connection error.
*
Expand Down Expand Up @@ -823,7 +650,7 @@ constructor(
*/
class VerificationUnsuccessful(reason: String) : PolluxError(reason) {
override val code: Int
get() = 60
get() = 510
}

/**
Expand All @@ -834,67 +661,47 @@ constructor(
class WrongKeyProvided(expected: String?, actual: String?) :
PolluxError("Provided key is: $actual but should be $expected") {
override val code: Int
get() = 61
}

/**
* A class representing an error when a field is null when it should not.
*
* @see PolluxError
*/
class NullField(field: String) : PolluxError("Field $field must not be null") {
override val code: Int
get() = 62
}

/**
* A class representing an error when a request presentation has wrong attachments.
*
* @see PolluxError
*/
class RequestPresentationHasWrongAttachments(reason: String) : PolluxError(reason) {
override val code: Int
get() = 63
get() = 511
}

/*
* Represents an error that occurs when the status list index is out of bounds compared to the decoded and decompressed value of encodedList.
*/
class StatusListOutOfBoundIndex : PolluxError("Status list index is out of bound") {
override val code: Int
get() = 64
get() = 513
}

/**
* Represents an error that occurs when a revocation registry json is missing a field.
*/
class RevocationRegistryJsonMissingFieldError(val field: String) : PolluxError("Revocation registry json missing: $field") {
override val code: Int
get() = 65
get() = 514
}

/**
* Represents an error that occurs when a revocation registry json is missing a field.
*/
class UnsupportedTypeError(val type: String) : PolluxError("Unsupported type: $type") {
override val code: Int
get() = 66
get() = 515
}

/**
* Represents an error that occurs when a field is null but should not be.
*/
class NonNullableError(val field: String) : PolluxError("Field $field are non nullable.") {
override val code: Int
get() = 67
get() = 516
}

/**
* Represents an error that occurs when a proof cannot be verified.
*/
class VerifyProofError() : PolluxError("The verification failed.") {
override val code: Int
get() = 68
get() = 517
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,8 @@ open class EdgeAgent {
}

else -> {
throw ApolloError.InvalidSpecificKeyCurve(
privateKey.getCurve(),
arrayOf(Curve.SECP256K1.value, Curve.ED25519.value)
throw ApolloError.InvalidKeyCurve(
privateKey.getCurve()
)
}
}
Expand Down
Loading
Loading