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

fix: add dependency error handling #394

Merged
merged 2 commits into from
Oct 3, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Table:
| Simple Ts Esm | ✅ |
| Simple Js Esm | ✅ |

Last test run date: 10/02/24 03:35:49 AM
Last test run date: 10/03/24 03:35:41 AM
## Quick Installation

For those who just want to use Azion Bundler in their project without contributing to the development, you can install it directly from npm.
Expand Down
31 changes: 31 additions & 0 deletions lib/env/vulcan.env.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,33 @@ async function readVulcanEnv(scope = 'local') {
throw error;
}
}

/**
* Handles dependency-related errors and provides user feedback.
* @param {Error} error - The error object caught during module loading.
* @param {string} configPath - The path to the configuration file.
* @throws {Error} Rethrows the original error if it's not a dependency issue.
*/
function handleDependencyError(error, configPath) {
if (error.code === 'ERR_MODULE_NOT_FOUND') {
const missingPackage = error.message.match(/'([^']+)'/)?.[1];
if (missingPackage) {
feedback.error(
`Missing dependency: ${missingPackage}. Please install it using 'npm install ${missingPackage}' or 'yarn add ${missingPackage}'.`,
);
} else {
feedback.error(
`A required dependency is missing. Please ensure all dependencies are installed.`,
);
}
debug.error(
`Failed to load configuration from ${configPath}. ${error.message}`,
);
} else {
throw error;
}
}

/**
* Loads the azion.config file and returns the entire configuration object.
* @async
Expand Down Expand Up @@ -205,6 +232,10 @@ async function loadAzionConfig(configPath) {

return configModule.default || configModule;
} catch (error) {
if (error.code === 'ERR_MODULE_NOT_FOUND') {
handleDependencyError(error, configPath);
return null;
}
debug.error(error);
feedback.error(Messages.errors.file_doesnt_exist(configPath));
throw error;
Expand Down