Created
October 6, 2025 06:44
-
-
Save RB-Lab/fe32223fd69a0c0cfb922b69457f20e5 to your computer and use it in GitHub Desktop.
Function to debug paths in AWS lambda (but not only)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require('fs'); | |
| const path = require('path'); | |
| function debugPath(targetPath) { | |
| console.log(`Debugging path: ${targetPath}`); | |
| console.log('='.repeat(50)); | |
| const segments = targetPath.split('/').filter(segment => segment !== ''); | |
| let currentPath = ''; | |
| // Start from root if path is absolute | |
| if (targetPath.startsWith('/')) { | |
| currentPath = '/'; | |
| console.log(`Root directory (/): exists`); | |
| } | |
| for (let i = 0; i < segments.length; i++) { | |
| currentPath = path.join(currentPath, segments[i]); | |
| try { | |
| const stats = fs.statSync(currentPath); | |
| console.log(`✓ ${currentPath}: ${stats.isDirectory() ? 'directory' : 'file'}`); | |
| if (stats.isDirectory()) { | |
| try { | |
| const contents = fs.readdirSync(currentPath); | |
| console.log(` Contents: [${contents.join(', ')}]`); | |
| } catch (err) { | |
| console.log(` Cannot read directory: ${err.message}`); | |
| } | |
| } | |
| } catch (err) { | |
| console.log(`✗ ${currentPath}: ${err.code} - ${err.message}`); | |
| break; | |
| } | |
| console.log('-'.repeat(30)); | |
| } | |
| } | |
| // Debug the specific path from your error | |
| debugPath('/opt/nodejs/your/path'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment