mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Improved error handling in card-assets
refs bb47b9e327
- EACCESS error was previously caught to stop the boot process from failing with perms errors
- For clearFiless, we do not care if these files cannot be removed. Refactored to use allSettled which means we don't do them in sequence + can ignore the outcome
- For minifiy, this is now a legit error, however we don't need the activate method to fail for an EACCES error, we just need an error to be shown (I think)
This commit is contained in:
parent
aee949bbf4
commit
4c7330125f
1 changed files with 17 additions and 21 deletions
|
@ -53,35 +53,31 @@ class CardAssetService {
|
|||
async minify(globs) {
|
||||
try {
|
||||
return await this.minifier.minify(globs);
|
||||
} catch (err) {
|
||||
// @TODO: Convert this back to a proper error once the underlying bug is fixed
|
||||
if (err.code === 'EACCES') {
|
||||
logging.warn('Ghost was not able to write card asset files due to permissions.');
|
||||
} catch (error) {
|
||||
if (error.code === 'EACCES') {
|
||||
logging.error('Ghost was not able to write card asset files due to permissions.');
|
||||
return;
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async clearFiles() {
|
||||
this.files = [];
|
||||
|
||||
// @deprecated switch this to use fs.rm when we drop support for Node v12
|
||||
try {
|
||||
await fs.unlink(path.join(this.dest, 'cards.min.css'));
|
||||
} catch (error) {
|
||||
// Don't worry if the file didn't exist or we don't have perms here
|
||||
if (error.code !== 'ENOENT' && error.code !== 'EACCES') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
const rmFile = async (name) => {
|
||||
await fs.unlink(path.join(this.dest, name));
|
||||
};
|
||||
|
||||
try {
|
||||
await fs.unlink(path.join(this.dest, 'cards.min.js'));
|
||||
} catch (error) {
|
||||
// Don't worry if the file didn't exist or we don't have perms here
|
||||
if (error.code !== 'ENOENT' && error.code !== 'EACCES') {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
let promises = [
|
||||
// @deprecated switch this to use fs.rm when we drop support for Node v12
|
||||
rmFile('cards.min.css'),
|
||||
rmFile('cards.min.js')
|
||||
];
|
||||
|
||||
// We don't care if removing these files fails as it's valid for them to not exist
|
||||
return Promise.allSettled(promises);
|
||||
}
|
||||
|
||||
hasFile(type) {
|
||||
|
|
Loading…
Reference in a new issue