Skip to content

Commit 00d1e43

Browse files
committed
change to try catch instead
1 parent 60ab16f commit 00d1e43

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

patch-nx-debug.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,24 @@ const replacement = `function getTargetConfigurationForTask(task, projectGraph)
4444
// SPRING_BOOT_DEBUG: Log task details before potential error
4545
console.log('🎯 SPRING_BOOT_DEBUG: Processing target:', task.target.target, 'for project:', task.target.project);
4646
47-
if (!projectGraph?.nodes?.[task.target.project]) {
48-
console.log('❌ SPRING_BOOT_DEBUG: Project not found in projectGraph.nodes:', task.target.project);
49-
console.log('❌ SPRING_BOOT_DEBUG: Available projects:', Object.keys(projectGraph?.nodes || {}));
50-
throw new Error(\`Project \${task.target.project} not found in projectGraph.nodes\`);
51-
}
52-
53-
const project = projectGraph.nodes[task.target.project].data;`;
47+
try {
48+
const project = projectGraph.nodes[task.target.project].data;`;
5449

5550
if (originalPattern.test(content)) {
56-
// Patch the function
51+
// Patch the function start
5752
content = content.replace(originalPattern, replacement);
5853

54+
// Add the closing try-catch block around the return statement
55+
const returnPattern = /(\s+return project\.targets\[task\.target\.target\];)\s*}/;
56+
content = content.replace(returnPattern, `$1
57+
} catch (error) {
58+
console.log('❌ SPRING_BOOT_DEBUG: Error accessing project data for:', task.target.project);
59+
// console.log('❌ SPRING_BOOT_DEBUG: Available projects:', Object.keys(projectGraph?.nodes || {}));
60+
console.log('❌ SPRING_BOOT_DEBUG: Error details:', error.message);
61+
throw error;
62+
}
63+
}`);
64+
5965
fs.writeFileSync(utilsPath, content);
6066
console.log('✅ Successfully patched NX utils.js with debug logging');
6167
} else {
@@ -70,13 +76,15 @@ if (originalPattern.test(content)) {
7076
replacement: `// SPRING_BOOT_DEBUG: Log task details before potential error
7177
console.log('🎯 SPRING_BOOT_DEBUG: Processing target:', task.target.target, 'for project:', task.target.project);
7278
73-
if (!projectGraph?.nodes?.[task.target.project]) {
74-
console.log('❌ SPRING_BOOT_DEBUG: Project not found in projectGraph.nodes:', task.target.project);
75-
console.log('❌ SPRING_BOOT_DEBUG: Available projects:', Object.keys(projectGraph?.nodes || {}));
76-
throw new Error(\`Project \${task.target.project} not found in projectGraph.nodes\`);
77-
}
78-
79-
const project = projectGraph.nodes[task.target.project].data;`,
79+
let project;
80+
try {
81+
project = projectGraph.nodes[task.target.project].data;
82+
} catch (error) {
83+
console.log('❌ SPRING_BOOT_DEBUG: Error accessing project data for:', task.target.project);
84+
// console.log('❌ SPRING_BOOT_DEBUG: Available projects:', Object.keys(projectGraph?.nodes || {}));
85+
console.log('❌ SPRING_BOOT_DEBUG: Error details:', error.message);
86+
throw error;
87+
}`,
8088
name: 'simple pattern'
8189
},
8290
// Even simpler - just add logging before the line

0 commit comments

Comments
 (0)