Skip to content

Commit 273754b

Browse files
committed
fix: improve ABL and DF parser error handling
- Add try-catch blocks for ABL and DF parser loading - Improve error messages when parsers fail to load - Add warning messages to build script when WASM files are not found - Ensure parsers gracefully skip when unavailable instead of throwing errors This fixes the "No parser available for file extension" errors for .p, .w, .i, and .cls files
1 parent 1498a07 commit 273754b

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

packages/build/src/esbuild.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,15 @@ export function copyWasms(srcDir: string, distDir: string): void {
166166
if (fs.existsSync(ablWasmPath)) {
167167
fs.copyFileSync(ablWasmPath, path.join(distDir, "tree-sitter-abl.wasm"))
168168
console.log(`[copyWasms] Copied tree-sitter-abl.wasm to ${distDir}`)
169+
} else {
170+
console.warn(`[copyWasms] ABL WASM file not found at ${ablWasmPath}`)
169171
}
170172

171173
if (fs.existsSync(dfWasmPath)) {
172174
fs.copyFileSync(dfWasmPath, path.join(distDir, "tree-sitter-df.wasm"))
173175
console.log(`[copyWasms] Copied tree-sitter-df.wasm to ${distDir}`)
176+
} else {
177+
console.warn(`[copyWasms] DF WASM file not found at ${dfWasmPath}`)
174178
}
175179
}
176180

src/services/tree-sitter/languageParser.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ async function loadLanguage(langName: string, sourceDirectory?: string) {
6363
console.log(`Successfully loaded ${langName} from npm package`)
6464
return language
6565
} catch (error) {
66-
console.warn(
67-
`Warning: ${langName} language parser has version incompatibility. ${error instanceof Error ? error.message : error}`,
68-
)
69-
// Don't throw here, we'll handle this gracefully
70-
console.warn(`Skipping ${langName} parser due to version incompatibility`)
66+
const errorMessage = error instanceof Error ? error.message : String(error)
67+
console.error(`Error: Failed to load ${langName} parser from npm package. ${errorMessage}`)
68+
// Return null to indicate parser is not available
69+
// The calling code will handle this gracefully
7170
return null
7271
}
7372
}
@@ -256,20 +255,34 @@ export async function loadRequiredLanguageParsers(filesToParse: string[], source
256255
case "w":
257256
case "cls":
258257
parserKey = "abl" // Use same key for all ABL extensions
259-
language = await loadLanguage("abl", sourceDirectory)
260-
if (!language) {
261-
console.warn(`Skipping ABL parser for .${ext} files due to compatibility issues`)
258+
try {
259+
language = await loadLanguage("abl", sourceDirectory)
260+
if (!language) {
261+
console.warn(`ABL parser not available for .${ext} files - skipping`)
262+
continue // Skip this extension
263+
}
264+
query = new Query(language, ablQuery)
265+
} catch (error) {
266+
console.warn(
267+
`Failed to load ABL parser for .${ext} files: ${error instanceof Error ? error.message : error}`,
268+
)
262269
continue // Skip this extension
263270
}
264-
query = new Query(language, ablQuery)
265271
break
266272
case "df":
267-
language = await loadLanguage("df", sourceDirectory)
268-
if (!language) {
269-
console.warn(`Skipping DF parser for .${ext} files due to compatibility issues`)
273+
try {
274+
language = await loadLanguage("df", sourceDirectory)
275+
if (!language) {
276+
console.warn(`DF parser not available for .${ext} files - skipping`)
277+
continue // Skip this extension
278+
}
279+
query = new Query(language, dfQuery)
280+
} catch (error) {
281+
console.warn(
282+
`Failed to load DF parser for .${ext} files: ${error instanceof Error ? error.message : error}`,
283+
)
270284
continue // Skip this extension
271285
}
272-
query = new Query(language, dfQuery)
273286
break
274287
default:
275288
throw new Error(`Unsupported language: ${ext}`)

0 commit comments

Comments
 (0)