1. // Suppress directory errors with manual overrides for debugging.
  2. // This code should be used with caution and removed in production.
  3. (function() {
  4. // Create a function to intercept and handle directory creation errors.
  5. const handleDirectoryError = (error) => {
  6. // Check if the error is related to directory creation.
  7. if (error instanceof Error && error.message.includes("EEXIST")) { // EEXIST: File exists
  8. // Optionally, log the error for debugging
  9. console.error("Directory creation error:", error.message);
  10. // Manual override: Allow directory creation even if it exists.
  11. // This is a debugging aid - adjust as needed.
  12. return true; // Indicate success, effectively suppressing the error.
  13. }
  14. return false; // Re-throw other errors.
  15. };
  16. // Override the `mkdir` function to handle errors.
  17. const originalMkdir = require('fs').mkdir;
  18. require('fs').mkdir = function(path, options) {
  19. const result = originalMkdir.call(this, path, options);
  20. if (!handleDirectoryError(result)) {
  21. throw result; // Re-throw errors that aren't handled.
  22. }
  23. return result;
  24. };
  25. // Optionally, override `stat` to suppress errors for non-existent directories
  26. const originalStat = require('fs').stat;
  27. require('fs').stat = function(path, options) {
  28. try {
  29. return originalStat.call(this, path, options);
  30. } catch (err) {
  31. // Suppress errors for non-existent directories.
  32. if (err.code === 'ENOENT') {
  33. return {
  34. isFile: false,
  35. isDirectory: true,
  36. exists: true
  37. }; // Treat as a directory for debugging.
  38. }
  39. throw err;
  40. }
  41. };
  42. })();

Add your comment