Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad YAML error in the presence of parse error #9496

Closed
cscheid opened this issue Apr 26, 2024 · 9 comments · Fixed by #9566
Closed

Bad YAML error in the presence of parse error #9496

cscheid opened this issue Apr 26, 2024 · 9 comments · Fixed by #9566
Assignees
Labels
bug Something isn't working yaml-validation Issues with YAML validation and autocompletion in quarto
Milestone

Comments

@cscheid
Copy link
Collaborator

cscheid commented Apr 26, 2024

---
title: Hello, world
format: html
---

```{r}
#| label: fig-foo
#| message: FALSE
#| echo:false
cat("HIIII")
```

@cscheid cscheid added bug Something isn't working yaml-validation Issues with YAML validation and autocompletion in quarto labels Apr 26, 2024
@cscheid cscheid added this to the v1.5 milestone Apr 26, 2024
@cscheid cscheid self-assigned this Apr 26, 2024
@cscheid
Copy link
Collaborator Author

cscheid commented May 2, 2024

We don't print a stack trace here, not even when QUARTO_PRINT_STACK=true:

$ QUARTO_PRINT_STACK=true quarto render issue-9496.qmd
ERROR: YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key (issue-9496.qmd, 9:14)
 8: #| message: FALSE
 9: #| echo:false
                ~
10: cat("HIIII")

@cscheid

This comment was marked as outdated.

@gordonwoodhull
Copy link
Contributor

gordonwoodhull commented May 2, 2024

I'm not able to repro. I added

 diff --git a/src/project/project-shared.ts b/src/project/project-shared.ts
index e45739f77..5d17abe6c 100644
--- a/src/project/project-shared.ts
+++ b/src/project/project-shared.ts
@@ -457,10 +457,14 @@ export async function projectResolveFullMarkdownForFile(
     flags: {} as RenderFlags,
   };
   try {
+    console.log('FOOO')
     const result = await expandIncludes(markdown, options, file);
     cache.fullMarkdown = result;
     cache.includeMap = options.state?.include.includes as FileInclusion[];
     return result;
+  } catch(xep) {
+    console.log(xep);
+    throw xep;
   } finally {
     temp.cleanup();
   }

I see 3

FOOO
[YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key (invalid-yaml.qmd, 9:14)
 8: #| message: FALSE
 9: #| echo:false
                ~
10: cat("HIIII")] {
  name: "YAMLException",
  reason: "can not read a block mapping entry; a multiline key may not be an implicit key",
  mark: {
    name: null,
    buffer: "label: fig-foo\nmessage: FALSE\necho:false\n",
    position: 41,
    line: 3,
    column: 0,
    snippet: " 1 | label: fig-foo\n 2 | message: FALSE\n 3 | echo:false\n 4 | \n-----^"
  },
  message: "can not read a block mapping entry; a multiline key may not be an implicit key (invalid-yaml.qmd, 9:"... 108 more characters
}

@cscheid
Copy link
Collaborator Author

cscheid commented May 2, 2024

I'm debugging that part of project-shared.ts with

  try {
    const result = await expandIncludes(markdown, options, file);
    cache.fullMarkdown = result;
    cache.includeMap = options.state?.include.includes as FileInclusion[];
    temp.cleanup();
    return result;
  } catch (e) {
    console.log("Exception:");
    temp.cleanup();
    console.log("\n");
    console.log(getStack());
    throw e;
  }

  // try {
  //   const result = await expandIncludes(markdown, options, file);
  //   cache.fullMarkdown = result;
  //   cache.includeMap = options.state?.include.includes as FileInclusion[];
  //   return result;
  // } finally {
  //   temp.cleanup();
  // }

(Specifically, I was disentangling await from try..finally to ensure I didn't have some other await bug lurking)

@cscheid
Copy link
Collaborator Author

cscheid commented May 2, 2024

A-ha! The first two stack traces are not the same, there were two different locations in render-files.ts.

@cscheid
Copy link
Collaborator Author

cscheid commented May 2, 2024

Ok, this is better:

$ quarto render issue-9496.qmd
ERROR: YAML Parse Error: block has incorrect key formatting (issue-9496.qmd, 9:4)
 8: #| message: FALSE
 9: #| echo:false
       ~~~~~~~~~~
10: cat("HIIII")
ℹ Is it possible you missed a space after a colon in the key-value mapping?

(cc @mine-cetinkaya-rundel, I think this error message should be more actionable now!)

@mcanouil
Copy link
Collaborator

mcanouil commented May 2, 2024

What is "block"? 😅

@cscheid
Copy link
Collaborator Author

cscheid commented May 2, 2024

We use the term block at least once here: https://quarto.org/docs/reference/cells/cells-knitr.html#overview

@mcanouil
Copy link
Collaborator

mcanouil commented May 3, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working yaml-validation Issues with YAML validation and autocompletion in quarto
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants