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!: rename AriesFrameworkError to CredoError #1718

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
4 changes: 2 additions & 2 deletions packages/action-menu/src/ActionMenuApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {

import {
AgentContext,
AriesFrameworkError,
CredoError,
ConnectionService,
MessageSender,
injectable,
Expand Down Expand Up @@ -118,7 +118,7 @@ export class ActionMenuApi {
role: ActionMenuRole.Requester,
})
if (!actionMenuRecord) {
throw new AriesFrameworkError(`No active menu found for connection id ${options.connectionId}`)
throw new CredoError(`No active menu found for connection id ${options.connectionId}`)
}

const { message, record } = await this.actionMenuService.createPerform(this.agentContext, {
Expand Down
6 changes: 3 additions & 3 deletions packages/action-menu/src/repository/ActionMenuRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ActionMenuRole } from '../ActionMenuRole'
import type { ActionMenuState } from '../ActionMenuState'
import type { TagsBase } from '@credo-ts/core'

import { AriesFrameworkError, BaseRecord, utils } from '@credo-ts/core'
import { CredoError, BaseRecord, utils } from '@credo-ts/core'
import { Type } from 'class-transformer'

import { ActionMenuSelection, ActionMenu } from '../models'
Expand Down Expand Up @@ -88,15 +88,15 @@ export class ActionMenuRecord
}

if (!expectedStates.includes(this.state)) {
throw new AriesFrameworkError(
throw new CredoError(
`Action Menu record is in invalid state ${this.state}. Valid states are: ${expectedStates.join(', ')}.`
)
}
}

public assertRole(expectedRole: ActionMenuRole) {
if (this.role !== expectedRole) {
throw new AriesFrameworkError(`Action Menu record has invalid role ${this.role}. Expected role ${expectedRole}.`)
throw new CredoError(`Action Menu record has invalid role ${this.role}. Expected role ${expectedRole}.`)
}
}
}
14 changes: 6 additions & 8 deletions packages/action-menu/src/services/ActionMenuService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { ActionMenuStateChangedEvent } from '../ActionMenuEvents'
import type { ActionMenuProblemReportMessage } from '../messages'
import type { AgentContext, InboundMessageContext, Logger, Query } from '@credo-ts/core'

import { AgentConfig, EventEmitter, AriesFrameworkError, injectable } from '@credo-ts/core'
import { AgentConfig, EventEmitter, CredoError, injectable } from '@credo-ts/core'

import { ActionMenuEventTypes } from '../ActionMenuEvents'
import { ActionMenuRole } from '../ActionMenuRole'
Expand Down Expand Up @@ -118,7 +118,7 @@ export class ActionMenuService {

const uniqueNames = new Set(options.menu.options.map((v) => v.name))
if (uniqueNames.size < options.menu.options.length) {
throw new AriesFrameworkError('Action Menu contains duplicated options')
throw new CredoError('Action Menu contains duplicated options')
}

// Create message
Expand Down Expand Up @@ -226,7 +226,7 @@ export class ActionMenuService {

const validSelection = record.menu?.options.some((item) => item.name === performedSelection.name)
if (!validSelection) {
throw new AriesFrameworkError('Selection does not match valid actions')
throw new CredoError('Selection does not match valid actions')
}

const previousState = record.state
Expand Down Expand Up @@ -277,7 +277,7 @@ export class ActionMenuService {

const validSelection = record.menu?.options.some((item) => item.name === performMessage.name)
if (!validSelection) {
throw new AriesFrameworkError('Selection does not match valid actions')
throw new CredoError('Selection does not match valid actions')
}

const previousState = record.state
Expand All @@ -289,7 +289,7 @@ export class ActionMenuService {

this.emitStateChangedEvent(agentContext, record, previousState)
} else {
throw new AriesFrameworkError(`No Action Menu found with thread id ${messageContext.message.threadId}`)
throw new CredoError(`No Action Menu found with thread id ${messageContext.message.threadId}`)
}
}

Expand Down Expand Up @@ -325,9 +325,7 @@ export class ActionMenuService {
})

if (!actionMenuRecord) {
throw new AriesFrameworkError(
`Unable to process action menu problem: record not found for connection id ${connection.id}`
)
throw new CredoError(`Unable to process action menu problem: record not found for connection id ${connection.id}`)
}
// Clear menu to restart flow
return await this.clearMenu(agentContext, { actionMenuRecord })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
JsonObject,
} from '@hyperledger/anoncreds-shared'

import { AriesFrameworkError, JsonTransformer, TypedArrayEncoder, injectable, utils } from '@credo-ts/core'
import { CredoError, JsonTransformer, TypedArrayEncoder, injectable, utils } from '@credo-ts/core'
import {
Credential,
CredentialRequest,
Expand Down Expand Up @@ -110,7 +110,7 @@ export class AnonCredsRsHolderService implements AnonCredsHolderService {
// Extract revocation status list for the given timestamp
const revocationStatusList = revocationStatusLists[timestamp]
if (!revocationStatusList) {
throw new AriesFrameworkError(
throw new CredoError(
`Revocation status list for revocation registry ${revocationRegistryDefinitionId} and timestamp ${timestamp} not found in revocation status lists. All revocation status lists must be present.`
)
}
Expand Down Expand Up @@ -219,7 +219,7 @@ export class AnonCredsRsHolderService implements AnonCredsHolderService {

const isLegacyIdentifier = credentialOffer.cred_def_id.match(unqualifiedCredentialDefinitionIdRegex)
if (!isLegacyIdentifier && useLegacyProverDid) {
throw new AriesFrameworkError('Cannot use legacy prover_did with non-legacy identifiers')
throw new CredoError('Cannot use legacy prover_did with non-legacy identifiers')
}
createReturnObj = CredentialRequest.create({
entropy: !useLegacyProverDid || !isLegacyIdentifier ? anoncreds.generateNonce() : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type {
import type { AgentContext } from '@credo-ts/core'
import type { CredentialDefinitionPrivate, JsonObject, KeyCorrectnessProof } from '@hyperledger/anoncreds-shared'

import { injectable, AriesFrameworkError } from '@credo-ts/core'
import { injectable, CredoError } from '@credo-ts/core'
import {
RevocationStatusList,
RevocationRegistryDefinitionPrivate,
Expand Down Expand Up @@ -281,7 +281,7 @@ export class AnonCredsRsIssuerService implements AnonCredsIssuerService {
revocationRegistryIndex,
].filter((e) => e !== undefined)
if (definedRevocationOptions.length > 0 && definedRevocationOptions.length < 3) {
throw new AriesFrameworkError(
throw new CredoError(
'Revocation requires all of revocationRegistryDefinitionId, revocationRegistryIndex and revocationStatusList'
)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/anoncreds/src/error/AnonCredsError.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AriesFrameworkError } from '@credo-ts/core'
import { CredoError } from '@credo-ts/core'

export class AnonCredsError extends AriesFrameworkError {
export class AnonCredsError extends CredoError {
public constructor(message: string, { cause }: { cause?: Error } = {}) {
super(message, { cause })
}
Expand Down
48 changes: 21 additions & 27 deletions packages/anoncreds/src/formats/AnonCredsCredentialFormatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
ProblemReportError,
MessageValidator,
CredentialFormatSpec,
AriesFrameworkError,
CredoError,
Attachment,
JsonEncoder,
utils,
Expand Down Expand Up @@ -93,7 +93,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
const anoncredsFormat = credentialFormats.anoncreds

if (!anoncredsFormat) {
throw new AriesFrameworkError('Missing anoncreds payload in createProposal')
throw new CredoError('Missing anoncreds payload in createProposal')
}

// We want all properties except for `attributes` and `linkedAttachments` attributes.
Expand All @@ -105,9 +105,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
try {
MessageValidator.validateSync(proposal)
} catch (error) {
throw new AriesFrameworkError(
`Invalid proposal supplied: ${anoncredsCredentialProposal} in AnonCredsFormatService`
)
throw new CredoError(`Invalid proposal supplied: ${anoncredsCredentialProposal} in AnonCredsFormatService`)
}

const attachment = this.getFormatData(JsonTransformer.toJSON(proposal), format.attachmentId)
Expand Down Expand Up @@ -152,13 +150,11 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
const attributes = anoncredsFormat?.attributes ?? credentialRecord.credentialAttributes

if (!credentialDefinitionId) {
throw new AriesFrameworkError(
'No credential definition id in proposal or provided as input to accept proposal method.'
)
throw new CredoError('No credential definition id in proposal or provided as input to accept proposal method.')
}

if (!attributes) {
throw new AriesFrameworkError('No attributes in proposal or provided as input to accept proposal method.')
throw new CredoError('No attributes in proposal or provided as input to accept proposal method.')
}

const { format, attachment, previewAttributes } = await this.createAnonCredsOffer(agentContext, {
Expand Down Expand Up @@ -188,7 +184,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
const anoncredsFormat = credentialFormats.anoncreds

if (!anoncredsFormat) {
throw new AriesFrameworkError('Missing anoncreds credential format data')
throw new CredoError('Missing anoncreds credential format data')
}

const { format, attachment, previewAttributes } = await this.createAnonCredsOffer(agentContext, {
Expand Down Expand Up @@ -276,7 +272,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
* Starting from a request is not supported for anoncreds credentials, this method only throws an error.
*/
public async createRequest(): Promise<CredentialFormatCreateReturn> {
throw new AriesFrameworkError('Starting from a request is not supported for anoncreds credentials')
throw new CredoError('Starting from a request is not supported for anoncreds credentials')
}

/**
Expand All @@ -299,7 +295,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
// Assert credential attributes
const credentialAttributes = credentialRecord.credentialAttributes
if (!credentialAttributes) {
throw new AriesFrameworkError(
throw new CredoError(
`Missing required credential attribute values on credential record with id ${credentialRecord.id}`
)
}
Expand All @@ -308,10 +304,10 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
agentContext.dependencyManager.resolve<AnonCredsIssuerService>(AnonCredsIssuerServiceSymbol)

const credentialOffer = offerAttachment?.getDataAsJson<AnonCredsCredentialOffer>()
if (!credentialOffer) throw new AriesFrameworkError('Missing anoncreds credential offer in createCredential')
if (!credentialOffer) throw new CredoError('Missing anoncreds credential offer in createCredential')

const credentialRequest = requestAttachment.getDataAsJson<AnonCredsCredentialRequest>()
if (!credentialRequest) throw new AriesFrameworkError('Missing anoncreds credential request in createCredential')
if (!credentialRequest) throw new CredoError('Missing anoncreds credential request in createCredential')

// We check locally for credential definition info. If it supports revocation, we need to search locally for
// an active revocation registry
Expand All @@ -334,7 +330,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
}

if (!revocationRegistryDefinitionId || !revocationRegistryIndex) {
throw new AriesFrameworkError(
throw new CredoError(
'Revocation registry definition id and revocation index are mandatory to issue AnonCreds revocable credentials'
)
}
Expand All @@ -343,7 +339,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
.getByRevocationRegistryDefinitionId(agentContext, revocationRegistryDefinitionId)

if (revocationRegistryDefinitionPrivateRecord.state !== AnonCredsRevocationRegistryState.Active) {
throw new AriesFrameworkError(
throw new CredoError(
`Revocation registry ${revocationRegistryDefinitionId} is in ${revocationRegistryDefinitionPrivateRecord.state} state`
)
}
Expand All @@ -354,7 +350,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
.getRevocationStatusList(agentContext, revocationRegistryDefinitionId, dateToTimestamp(new Date()))

if (!revocationStatusListResult.revocationStatusList) {
throw new AriesFrameworkError(
throw new CredoError(
`Unable to resolve revocation status list for ${revocationRegistryDefinitionId}:
${revocationStatusListResult.resolutionMetadata.error} ${revocationStatusListResult.resolutionMetadata.message}`
)
Expand Down Expand Up @@ -399,15 +395,13 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
agentContext.dependencyManager.resolve<AnonCredsHolderService>(AnonCredsHolderServiceSymbol)

if (!credentialRequestMetadata) {
throw new AriesFrameworkError(
throw new CredoError(
`Missing required request metadata for credential exchange with thread id with id ${credentialRecord.id}`
)
}

if (!credentialRecord.credentialAttributes) {
throw new AriesFrameworkError(
'Missing credential attributes on credential record. Unable to check credential attributes'
)
throw new CredoError('Missing credential attributes on credential record. Unable to check credential attributes')
}

const anonCredsCredential = attachment.getDataAsJson<AnonCredsCredential>()
Expand All @@ -416,7 +410,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
.getRegistryForIdentifier(agentContext, anonCredsCredential.cred_def_id)
.getCredentialDefinition(agentContext, anonCredsCredential.cred_def_id)
if (!credentialDefinitionResult.credentialDefinition) {
throw new AriesFrameworkError(
throw new CredoError(
`Unable to resolve credential definition ${anonCredsCredential.cred_def_id}: ${credentialDefinitionResult.resolutionMetadata.error} ${credentialDefinitionResult.resolutionMetadata.message}`
)
}
Expand All @@ -425,7 +419,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
.getRegistryForIdentifier(agentContext, anonCredsCredential.cred_def_id)
.getSchema(agentContext, anonCredsCredential.schema_id)
if (!schemaResult.schema) {
throw new AriesFrameworkError(
throw new CredoError(
`Unable to resolve schema ${anonCredsCredential.schema_id}: ${schemaResult.resolutionMetadata.error} ${schemaResult.resolutionMetadata.message}`
)
}
Expand All @@ -438,7 +432,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
.getRevocationRegistryDefinition(agentContext, anonCredsCredential.rev_reg_id)

if (!revocationRegistryResult.revocationRegistryDefinition) {
throw new AriesFrameworkError(
throw new CredoError(
`Unable to resolve revocation registry definition ${anonCredsCredential.rev_reg_id}: ${revocationRegistryResult.resolutionMetadata.error} ${revocationRegistryResult.resolutionMetadata.message}`
)
}
Expand Down Expand Up @@ -605,7 +599,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService

const { previewAttributes } = this.getCredentialLinkedAttachments(attributes, linkedAttachments)
if (!previewAttributes) {
throw new AriesFrameworkError('Missing required preview attributes for anoncreds offer')
throw new CredoError('Missing required preview attributes for anoncreds offer')
}

await this.assertPreviewAttributesMatchSchemaAttributes(agentContext, offer, previewAttributes)
Expand All @@ -620,7 +614,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService

if (credentialDefinition.revocation) {
if (!revocationRegistryDefinitionId || !revocationRegistryIndex) {
throw new AriesFrameworkError(
throw new CredoError(
'AnonCreds revocable credentials require revocationRegistryDefinitionId and revocationRegistryIndex'
)
}
Expand Down Expand Up @@ -656,7 +650,7 @@ export class AnonCredsCredentialFormatService implements CredentialFormatService
const schemaResult = await registry.getSchema(agentContext, offer.schema_id)

if (!schemaResult.schema) {
throw new AriesFrameworkError(
throw new CredoError(
`Unable to resolve schema ${offer.schema_id} from registry: ${schemaResult.resolutionMetadata.error} ${schemaResult.resolutionMetadata.message}`
)
}
Expand Down
Loading
Loading