// Suppress directory errors with manual overrides for debugging.
// This code should be used with caution and removed in production.
(function() {
// Create a function to intercept and handle directory creation errors.
const handleDirectoryError = (error) => {
// Check if the error is related to directory creation.
if (error instanceof Error && error.message.includes("EEXIST")) { // EEXIST: File exists
// Optionally, log the error for debugging
console.error("Directory creation error:", error.message);
// Manual override: Allow directory creation even if it exists.
// This is a debugging aid - adjust as needed.
return true; // Indicate success, effectively suppressing the error.
}
return false; // Re-throw other errors.
};
// Override the `mkdir` function to handle errors.
const originalMkdir = require('fs').mkdir;
require('fs').mkdir = function(path, options) {
const result = originalMkdir.call(this, path, options);
if (!handleDirectoryError(result)) {
throw result; // Re-throw errors that aren't handled.
}
return result;
};
// Optionally, override `stat` to suppress errors for non-existent directories
const originalStat = require('fs').stat;
require('fs').stat = function(path, options) {
try {
return originalStat.call(this, path, options);
} catch (err) {
// Suppress errors for non-existent directories.
if (err.code === 'ENOENT') {
return {
isFile: false,
isDirectory: true,
exists: true
}; // Treat as a directory for debugging.
}
throw err;
}
};
})();
Add your comment