createTriggerParseError creates a detailed error for trigger parsing issues with source location
(filePath, content, triggerStr string, err error)
| 338 | |
| 339 | // createTriggerParseError creates a detailed error for trigger parsing issues with source location |
| 340 | func (c *Compiler) createTriggerParseError(filePath, content, triggerStr string, err error) error { |
| 341 | schedulePreprocessingLog.Printf("Creating trigger parse error for: %s", triggerStr) |
| 342 | |
| 343 | lines := strings.Split(content, "\n") |
| 344 | |
| 345 | // Find the line where "on:" appears in the frontmatter |
| 346 | var onLine int |
| 347 | var onColumn int |
| 348 | inFrontmatter := false |
| 349 | |
| 350 | for i, line := range lines { |
| 351 | lineNum := i + 1 |
| 352 | |
| 353 | // Check for frontmatter delimiter |
| 354 | if strings.TrimSpace(line) == "---" { |
| 355 | if !inFrontmatter { |
| 356 | inFrontmatter = true |
| 357 | } else { |
| 358 | // End of frontmatter |
| 359 | break |
| 360 | } |
| 361 | continue |
| 362 | } |
| 363 | |
| 364 | if inFrontmatter { |
| 365 | // Look for "on:" field |
| 366 | trimmed := strings.TrimSpace(line) |
| 367 | if strings.HasPrefix(trimmed, "on:") { |
| 368 | onLine = lineNum |
| 369 | // Find the column where "on:" starts |
| 370 | onColumn = strings.Index(line, "on:") + 1 |
| 371 | break |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | // If we found the line, create a formatted error |
| 377 | if onLine > 0 { |
| 378 | // Create context lines around the error |
| 379 | var context []string |
| 380 | startLine := max(1, onLine-2) |
| 381 | endLine := min(len(lines), onLine+2) |
| 382 | |
| 383 | for i := startLine; i <= endLine; i++ { |
| 384 | if i-1 < len(lines) { |
| 385 | context = append(context, lines[i-1]) |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | compilerErr := console.CompilerError{ |
| 390 | Position: console.ErrorPosition{ |
| 391 | File: filePath, |
| 392 | Line: onLine, |
| 393 | Column: onColumn, |
| 394 | }, |
| 395 | Type: "error", |
| 396 | Message: "trigger syntax error: " + err.Error(), |
| 397 | Context: context, |
no test coverage detected