Skip to content

Commit

Permalink
fix(modules): Fix miss leading provider resolution error (#10900)
Browse files Browse the repository at this point in the history
FIXES SUP-560

**What**
Currently, no matter the error when looking for a provider to exists in the container we are throwing a normalized error stating that the provider does not exists in the container. The issue is that the first initialization of the provider occurs the first time we resolve it, and the error can be that the provider failed to be instanciated for any reason. 

In this pr, we are explicitly checking for the error to be an awilix resolution error to throw the classic error and otherwise we provide the issue why the provider failed to be resolved.
  • Loading branch information
adrien2p authored Jan 10, 2025
1 parent 44706ef commit c490e08
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ moduleIntegrationTestRunner({

expect(err).toEqual({
success: false,
error:
"\n Unable to retrieve the auth provider with id: facebook\n Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.\n ",
error: `
Unable to retrieve the auth provider with id: facebook
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.`,
})
})

Expand Down
13 changes: 9 additions & 4 deletions packages/modules/auth/src/services/auth-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ export default class AuthProviderService {
try {
return this.dependencies[`${AuthProviderRegistrationPrefix}${providerId}`]
} catch (err) {
const errMessage = `
Unable to retrieve the auth provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.
`
if (err.name === "AwilixResolutionError") {
const errMessage = `
Unable to retrieve the auth provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.`
throw new Error(errMessage)
}

const errMessage = `Unable to retrieve the auth provider with id: ${providerId}, the following error occurred: ${err.message}`
this.#logger.error(errMessage)

throw new Error(errMessage)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ export default class FulfillmentProviderService extends ModulesSdkUtils.MedusaIn
try {
return this.__container__[`fp_${providerId}`]
} catch (err) {
const errMessage = `
Unable to retrieve the fulfillment provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.
`
if (err.name === "AwilixResolutionError") {
const errMessage = `
Unable to retrieve the fulfillment provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.`
throw new Error(errMessage)
}

const errMessage = `Unable to retrieve the fulfillment provider with id: ${providerId}, the following error occurred: ${err.message}`
this.#logger.error(errMessage)

throw new Error(errMessage)
}
}
Expand Down
13 changes: 9 additions & 4 deletions packages/modules/locking/src/services/locking-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ export default class LockingProviderService {
`${LockingProviderRegistrationPrefix}${providerId}`
]
} catch (err) {
const errMessage = `
Unable to retrieve the locking provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.
`
if (err.name === "AwilixResolutionError") {
const errMessage = `
Unable to retrieve the locking provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.`
throw new Error(errMessage)
}

const errMessage = `Unable to retrieve the locking provider with id: ${providerId}, the following error occurred: ${err.message}`
this.#logger.error(errMessage)

throw new Error(errMessage)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ export default class NotificationProviderService extends ModulesSdkUtils.MedusaI
`${NotificationProviderRegistrationPrefix}${providerId}`
]
} catch (err) {
const errMessage = `
Unable to retrieve the notification provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.
`
if (err.name === "AwilixResolutionError") {
const errMessage = `
Unable to retrieve the notification provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.`
throw new Error(errMessage)
}

const errMessage = `Unable to retrieve the notification provider with id: ${providerId}, the following error occurred: ${err.message}`
this.#logger.error(errMessage)

throw new Error(errMessage)
}
}
Expand Down
18 changes: 10 additions & 8 deletions packages/modules/payment/src/services/payment-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ export default class PaymentProviderService extends ModulesSdkUtils.MedusaIntern
retrieveProvider(providerId: string): IPaymentProvider {
try {
return this.__container__[providerId] as IPaymentProvider
} catch (e) {
const errMessage = `
Unable to retrieve the payment provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.
`

// Ensure that the logger captures the actual error
this.#logger.error(e)
} catch (err) {
if (err.name === "AwilixResolutionError") {
const errMessage = `
Unable to retrieve the payment provider with id: ${providerId}
Please make sure that the provider is registered in the container and it is configured correctly in your project configuration file.`
throw new Error(errMessage)
}

const errMessage = `Unable to retrieve the payment provider with id: ${providerId}, the following error occurred: ${err.message}`
this.#logger.error(errMessage)

throw new Error(errMessage)
}
Expand Down

0 comments on commit c490e08

Please sign in to comment.